mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-29 08:07:48 +01:00
fix tests
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
const server = require('../../app.js');
|
||||
|
||||
const request = require('supertest');
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
require('../../models/Todo');
|
||||
require('../../models/TodoList');
|
||||
require('../../models/User');
|
||||
|
||||
const Todo = mongoose.model('Todo');
|
||||
const TodoList = mongoose.model('TodoList');
|
||||
const User = mongoose.model('User');
|
||||
|
||||
jest.setTimeout(60000);
|
||||
const MongoDBMemoryServer = require('mongodb-memory-server').default;
|
||||
const server = require('../../app.js');
|
||||
const { seed, clean, mongodbMemoryServerConfig } = require('./utils');
|
||||
|
||||
let user;
|
||||
@@ -34,13 +37,12 @@ afterEach(async () => {
|
||||
afterAll(async () => {
|
||||
await mongoose.disconnect();
|
||||
await mongoServer.stop();
|
||||
await server.close();
|
||||
});
|
||||
|
||||
describe('test lists', () => {
|
||||
test('should index lists', async () => {
|
||||
const response = await request(server)
|
||||
.get('/api/lists')
|
||||
.get('/__/lists')
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
@@ -51,13 +53,13 @@ describe('test lists', () => {
|
||||
});
|
||||
test('should not index lists without authentication', async () => {
|
||||
await request(server)
|
||||
.get('/api/lists')
|
||||
.get('/__/lists')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(401);
|
||||
});
|
||||
test('should create list', async () => {
|
||||
const response = await request(server)
|
||||
.post('/api/lists')
|
||||
.post('/__/lists')
|
||||
.send({
|
||||
name: 'List2',
|
||||
})
|
||||
@@ -74,7 +76,7 @@ describe('test lists', () => {
|
||||
test('should create list with custom id', async () => {
|
||||
const id = mongoose.Types.ObjectId();
|
||||
const response = await request(server)
|
||||
.post('/api/lists')
|
||||
.post('/__/lists')
|
||||
.send({
|
||||
name: 'List2',
|
||||
id,
|
||||
@@ -92,7 +94,7 @@ describe('test lists', () => {
|
||||
|
||||
test('should not create list without authentication', async () => {
|
||||
await request(server)
|
||||
.post('/api/lists')
|
||||
.post('/__/lists')
|
||||
.send({
|
||||
name: 'List2',
|
||||
})
|
||||
@@ -102,7 +104,7 @@ describe('test lists', () => {
|
||||
});
|
||||
test('should update list', async () => {
|
||||
const response = await request(server)
|
||||
.patch(`/api/lists/${list._id}`)
|
||||
.patch(`/__/lists/${list._id}`)
|
||||
.send({
|
||||
name: 'List2',
|
||||
})
|
||||
@@ -116,7 +118,7 @@ describe('test lists', () => {
|
||||
});
|
||||
test('should not update list without authentication', async () => {
|
||||
await request(server)
|
||||
.patch(`/api/lists/${list._id}`)
|
||||
.patch(`/__/lists/${list._id}`)
|
||||
.send({
|
||||
name: 'List2',
|
||||
})
|
||||
@@ -127,7 +129,7 @@ describe('test lists', () => {
|
||||
});
|
||||
test('should remove list', async () => {
|
||||
const response = await request(server)
|
||||
.delete(`/api/lists/${list._id}`)
|
||||
.delete(`/__/lists/${list._id}`)
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
@@ -142,7 +144,7 @@ describe('test lists', () => {
|
||||
});
|
||||
test('should not remove list without authentication', async () => {
|
||||
await request(server)
|
||||
.delete(`/api/lists/${list._id}`)
|
||||
.delete(`/__/lists/${list._id}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(401);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
const server = require('../../app.js');
|
||||
|
||||
const request = require('supertest');
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
require('../../models/Todo');
|
||||
require('../../models/TodoList');
|
||||
require('../../models/User');
|
||||
|
||||
const Todo = mongoose.model('Todo');
|
||||
const TodoList = mongoose.model('TodoList');
|
||||
const User = mongoose.model('User');
|
||||
|
||||
jest.setTimeout(60000);
|
||||
const MongoDBMemoryServer = require('mongodb-memory-server').default;
|
||||
const server = require('../../app.js');
|
||||
const { seed, clean, mongodbMemoryServerConfig } = require('./utils');
|
||||
|
||||
let user;
|
||||
@@ -34,13 +37,12 @@ afterEach(async () => {
|
||||
afterAll(async () => {
|
||||
await mongoose.disconnect();
|
||||
await mongoServer.stop();
|
||||
await server.close();
|
||||
});
|
||||
|
||||
describe('test todos', () => {
|
||||
test('should index todos', async () => {
|
||||
const response = await request(server)
|
||||
.get(`/api/lists/${list._id}/todos`)
|
||||
.get(`/__/lists/${list._id}/todos`)
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
@@ -51,7 +53,7 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should index all todos', async () => {
|
||||
const response = await request(server)
|
||||
.get(`/api/todos`)
|
||||
.get(`/__/todos`)
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
@@ -62,13 +64,13 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should not index todos without authentication', async () => {
|
||||
await request(server)
|
||||
.get(`/api/lists/${list._id}/todos`)
|
||||
.get(`/__/lists/${list._id}/todos`)
|
||||
.set('Accept', 'application/json')
|
||||
.expect(401);
|
||||
});
|
||||
test('should create todo', async () => {
|
||||
const response = await request(server)
|
||||
.post(`/api/lists/${list._id}/todos`)
|
||||
.post(`/__/lists/${list._id}/todos`)
|
||||
.send({
|
||||
text: 'Todo2',
|
||||
})
|
||||
@@ -87,7 +89,7 @@ describe('test todos', () => {
|
||||
test('should create todo with custom id', async () => {
|
||||
const id = mongoose.Types.ObjectId();
|
||||
const response = await request(server)
|
||||
.post(`/api/lists/${list._id}/todos`)
|
||||
.post(`/__/lists/${list._id}/todos`)
|
||||
.send({
|
||||
text: 'Todo2',
|
||||
id,
|
||||
@@ -108,7 +110,7 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should not create todo without authentication', async () => {
|
||||
await request(server)
|
||||
.post(`/api/lists/${list._id}/todos`)
|
||||
.post(`/__/lists/${list._id}/todos`)
|
||||
.send({
|
||||
text: 'Todo1',
|
||||
})
|
||||
@@ -118,7 +120,7 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should update todo', async () => {
|
||||
const response = await request(server)
|
||||
.patch(`/api/lists/${list._id}/todos/${todo._id}`)
|
||||
.patch(`/__/lists/${list._id}/todos/${todo._id}`)
|
||||
.send({
|
||||
text: 'Todo2',
|
||||
})
|
||||
@@ -133,7 +135,7 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should not update todo without authentication', async () => {
|
||||
await request(server)
|
||||
.patch(`/api/lists/${list._id}/todos/${todo._id}`)
|
||||
.patch(`/__/lists/${list._id}/todos/${todo._id}`)
|
||||
.send({
|
||||
text: 'Todo2',
|
||||
})
|
||||
@@ -145,7 +147,7 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should remove todo', async () => {
|
||||
const response = await request(server)
|
||||
.delete(`/api/lists/${list._id}/todos/${todo._id}`)
|
||||
.delete(`/__/lists/${list._id}/todos/${todo._id}`)
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
@@ -160,7 +162,7 @@ describe('test todos', () => {
|
||||
});
|
||||
test('should not remove todo without authentication', async () => {
|
||||
await request(server)
|
||||
.delete(`/api/lists/${list._id}/todos/${todo._id}`)
|
||||
.delete(`/__/lists/${list._id}/todos/${todo._id}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(401);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
const server = require('../../app.js');
|
||||
|
||||
const request = require('supertest');
|
||||
const mongoose = require('mongoose');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
require('../../models/Todo');
|
||||
require('../../models/TodoList');
|
||||
require('../../models/User');
|
||||
|
||||
const Todo = mongoose.model('Todo');
|
||||
const TodoList = mongoose.model('TodoList');
|
||||
const User = mongoose.model('User');
|
||||
|
||||
jest.setTimeout(60000);
|
||||
const MongoDBMemoryServer = require('mongodb-memory-server').default;
|
||||
const server = require('../../app.js');
|
||||
const { seed, clean, mongodbMemoryServerConfig } = require('./utils');
|
||||
const { secret } = require('../../config');
|
||||
|
||||
@@ -34,13 +37,12 @@ afterEach(async () => {
|
||||
afterAll(async () => {
|
||||
await mongoose.disconnect();
|
||||
await mongoServer.stop();
|
||||
await server.close();
|
||||
});
|
||||
|
||||
describe('test users', () => {
|
||||
test('should get user', async () => {
|
||||
const response = await request(server)
|
||||
.get('/api/users/user')
|
||||
.get('/__/users/user')
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
@@ -52,7 +54,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should create user', async () => {
|
||||
const response = await request(server)
|
||||
.post('/api/users')
|
||||
.post('/__/users')
|
||||
.send({
|
||||
username: 'User2',
|
||||
password: 'password2',
|
||||
@@ -69,7 +71,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should not create user with no username', async () => {
|
||||
const response = await request(server)
|
||||
.post('/api/users')
|
||||
.post('/__/users')
|
||||
.send({
|
||||
username: '',
|
||||
password: 'password2',
|
||||
@@ -82,7 +84,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should not create user with no password', async () => {
|
||||
const response = await request(server)
|
||||
.post('/api/users')
|
||||
.post('/__/users')
|
||||
.send({
|
||||
username: 'User',
|
||||
password: '',
|
||||
@@ -95,7 +97,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should login user', async () => {
|
||||
const response = await request(server)
|
||||
.post('/api/users/login')
|
||||
.post('/__/users/login')
|
||||
.send({
|
||||
username: 'User1',
|
||||
password: 'password1',
|
||||
@@ -110,18 +112,18 @@ describe('test users', () => {
|
||||
});
|
||||
test('should not login user with no name', async () => {
|
||||
await request(server)
|
||||
.post('/api/users/login')
|
||||
.post('/__/users/login')
|
||||
.send({
|
||||
username: '',
|
||||
password: 'notpassword',
|
||||
})
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(401);
|
||||
.expect(400);
|
||||
});
|
||||
test('should not login user with wrong password', async () => {
|
||||
await request(server)
|
||||
.post('/api/users/login')
|
||||
.post('/__/users/login')
|
||||
.send({
|
||||
username: 'User',
|
||||
password: 'notpassword',
|
||||
@@ -132,7 +134,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should update user', async () => {
|
||||
const response = await request(server)
|
||||
.patch('/api/users/user')
|
||||
.patch('/__/users/user')
|
||||
.send({
|
||||
username: 'User2',
|
||||
password: 'password2',
|
||||
@@ -150,7 +152,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should not update user without authentication', async () => {
|
||||
const response = await request(server)
|
||||
.patch('/api/users/user')
|
||||
.patch('/__/users/user')
|
||||
.send({
|
||||
username: 'User2',
|
||||
password: 'password2',
|
||||
@@ -162,7 +164,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should not delete user without authentication', async () => {
|
||||
const response = await request(server)
|
||||
.delete('/api/users/user')
|
||||
.delete('/__/users/user')
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
.expect(401);
|
||||
@@ -173,7 +175,7 @@ describe('test users', () => {
|
||||
});
|
||||
test('should delete user', async () => {
|
||||
const response = await request(server)
|
||||
.delete('/api/users/user')
|
||||
.delete('/__/users/user')
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
require('../../models/Todo');
|
||||
require('../../models/TodoList');
|
||||
require('../../models/User');
|
||||
|
||||
const User = mongoose.model('User');
|
||||
const Todo = mongoose.model('Todo');
|
||||
const TodoList = mongoose.model('TodoList');
|
||||
|
||||
Reference in New Issue
Block a user