-
Notifications
You must be signed in to change notification settings - Fork 3
/
database_test.js
57 lines (47 loc) · 1.88 KB
/
database_test.js
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
const mongoose = require('mongoose');
require('dotenv').config();
describe('User CRUD',() => {
let connection;
let database;
const users = mongoose.model("test_"+process.env.COLLECTION,mongoose.Schema({
name: String,
email: String
}));
beforeAll(async () => {
connection = await mongoose.connect('postgres://localhost:5000/test_'+process.env.DATABASE,{useNewUrlParser: true, useUnifiedTopology: true });
db = mongoose.connection;
const collection = process.env.COLLECTION;
await db.createCollection(collection);
});
afterAll(async () => {
const collection = "test_"+process.env.COLLECTION;
await db.dropCollection(collection);
await db.dropDatabase();
await db.close();
await connection.close();
});
test("Add User POST /signup",async () => {
const response = await users.create({
name: process.env.USER_NAME,
email: process.env.USER_EMAIL
});
await response.save();
expect(response.name).toBe(process.env.USER_NAME);
});
test("All users GET /database", async () => {
const response = await users.find({});
expect(response.length).toBeGreaterThan(0);
});
// test("Update User PUT /users/:id", async () => {
// const response = await users.updateOne({name: process.env.USER_NAME},{email: process.env.USER_EMAIL_ALT});
// expect(response.ok).toBeTruthy();
// });
// test("User update is correct", async () => {
// const responseTwo = await users.findOne({name: process.env.USER_NAME});
// expect(responseTwo.email).toBe(process.env.USER_EMAIL_ALT);
// });
// test("Delete User DELETE /users/:id", async() => {
// const response = await users.deleteOne({name: process.env.USER_NAME});
// expect(response.ok).toBe(1);
// });
});