mirror of
https://github.com/usatiuk/ustk-todolist.git
synced 2025-10-28 15:47: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 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);
|
||||
|
||||
Reference in New Issue
Block a user