forked from makeitrealcamp/node-auth-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.test.js
31 lines (26 loc) · 947 Bytes
/
app.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
const request = require('supertest');
process.env.DATABASE_URL = "mongodb://localhost/auth-test-test";
const mongoose = require("mongoose");
const app = require('./app');
const User = require("./user");
beforeEach(async () => {
await User.remove({});
});
afterAll(async () => {
await mongoose.disconnect();
});
test('GET / responds with success code', async () => {
const response = await request(app).get('/');
expect(response.statusCode).toBe(302);
});
test('POST /register redirects to login', async () => {
const response = await request(app).post('/register')
.send("username=user1&password=test1234");
expect(response.statusCode).toBe(302);
});
test('POST /login redirects to home', async () => {
await User.create({ username: "user1", password: "test1234" });
const response = await request(app).post('/login')
.send("username=user1&password=test1234");
expect(response.statusCode).toBe(302);
});