Newer
Older
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
const dbClientInstance_ = require( './../db/mongo.js' );
const { model: Users } = require( './Users.js' );
describe( 'Model: Users', ()=>{
beforeAll( async ()=>{
await dbClientInstance_;
});
const userData = {
name: 'myname',
email: 'myname@example.com',
password: 'mypassword'
};
test( 'creating a user', async ()=>{
const userData = {
name: 'myname',
email: 'myname@example.com',
password: 'mypassword'
};
const userDoc = await Users( userData );
await userDoc.save();
const userRecord = await Users.findOne({ email: userData.email });
const { password, ...userInfo } = userData;
expect( userRecord ).toEqual( expect.objectContaining( userInfo ) );
});
afterAll( async ()=>{
const dbClient = await dbClientInstance_;
const { connection } = dbClient;
await connection.dropDatabase();
await dbClient.disconnect();
});
});