forked from feathersjs-ecosystem/authentication-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration.test.js
More file actions
61 lines (54 loc) · 1.57 KB
/
integration.test.js
File metadata and controls
61 lines (54 loc) · 1.57 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
50
51
52
53
54
55
56
57
58
59
60
61
import feathers from 'feathers';
import authentication from 'feathers-authentication';
import memory from 'feathers-memory';
import hooks from 'feathers-hooks';
import local from '../src';
import { expect } from 'chai';
describe('integration', () => {
it('verifies', () => {
const User = {
email: 'admin@feathersjs.com',
password: 'password'
};
const req = {
query: {},
body: Object.assign({}, User),
headers: {},
cookies: {},
params: {
query: {},
provider: 'socketio',
headers: {},
session: {},
cookies: {},
data: 'Hello, world'
}
};
const app = feathers();
let paramsReceived = false;
let dataReceived;
app.configure(hooks())
.configure(authentication({ secret: 'secret' }))
.configure(local())
.use('/users', memory());
app.service('users').hooks({
before: {
find: (hook) => {
paramsReceived = Object.keys(hook.params);
dataReceived = hook.params.data;
},
create: local.hooks.hashPassword({ passwordField: 'password' })
}
});
app.setup();
return app.service('users').create(User).then(() => {
return app.authenticate('local')(req).then(result => {
expect(result.success).to.equal(true);
expect(result.data.user.email).to.equal(User.email);
expect(result.data.user.password).to.not.equal(undefined);
expect(paramsReceived).to.have.members(['data', 'query']);
expect(dataReceived).to.equal('Hello, world');
});
});
});
});