-
-
Notifications
You must be signed in to change notification settings - Fork 795
Expand file tree
/
Copy pathexpress.test.ts
More file actions
49 lines (40 loc) · 1.38 KB
/
express.test.ts
File metadata and controls
49 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { strict as assert } from 'assert';
import { Server } from 'http';
import axios from 'axios';
import { app } from './fixture';
describe('@feathersjs/authentication-oauth/express', () => {
let server: Server;
before(async () => {
server = await app.listen(9876);
});
after(() => server.close());
it('oauth/test', async () => {
try {
await axios.get('http://localhost:9876/oauth/test?feathers_token=testing', { maxRedirects: 0 });
} catch (error) {
assert.equal(error.response.status, 302)
}
});
it('oauth/test with query', async () => {
try {
await axios.get('http://localhost:9876/oauth/test?other=test', { maxRedirects: 0 });
} catch (error) {
assert.equal(error.response.status, 302)
}
});
it('oauth/test/authenticate', async () => {
const { data } = await axios.get('http://localhost:9876/oauth/test/authenticate?profile[sub]=expressTest');
assert.ok(data.accessToken);
assert.equal(data.user.testId, 'expressTest');
assert.equal(data.fromMiddleware, 'testing');
});
it('oauth/test/authenticate with redirect', async () => {
app.get('authentication').oauth.redirect = '/';
try {
await axios.get('http://localhost:9876/oauth/test/authenticate');
} catch (error) {
assert.ok(/Cannot GET/.test(error.response.data));
delete app.get('authentication').oauth.redirect;
}
});
});