fix tests

This commit is contained in:
2018-08-25 13:14:02 +03:00
parent cfe366c469
commit 68d9d979b1
10 changed files with 945 additions and 1343 deletions

4
app.js
View File

@@ -74,8 +74,8 @@ app.use((req, res) => {
// handle errors
app.use((error, req, res, next) => {
if (error.code) {
res.status(error.code);
if (error.status) {
res.status(error.status);
} else {
switch (error.name) {
case 'ValidationError':

View File

@@ -4,7 +4,7 @@ class NotFoundError extends Error {
Error.captureStackTrace(this, NotFoundError);
this.name = 'NotFound';
this.text = text;
this.code = 404;
this.status = 404;
}
}
@@ -14,7 +14,7 @@ class BadRequestError extends Error {
Error.captureStackTrace(this, NotFoundError);
this.name = 'BadRequest';
this.text = text;
this.code = 400;
this.status = 400;
}
}

1576
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@
"author": "",
"dependencies": {
"body-parser": "^1.18.3",
"compression": "^1.7.2",
"compression": "^1.7.3",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
@@ -30,7 +30,7 @@
"express-jwt": "^5.3.1",
"hsts": "^2.1.0",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.2.1",
"mongoose": "^5.2.9",
"mongoose-findorcreate": "^3.0.0",
"mongoose-unique-validator": "^2.0.1",
"morgan": "^1.9.0",
@@ -40,18 +40,18 @@
"passport-local-mongoose": "^5.0.1"
},
"devDependencies": {
"concurrently": "^3.6.0",
"concurrently": "^4.0.0",
"cross-env": "^5.2.0",
"eslint": "^5.1.0",
"eslint-config-airbnb-base": "^13.0.0",
"eslint": "^5.4.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-node": "^3.0.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-prettier": "^2.6.2",
"jest": "^23.4.0",
"mongodb-memory-server": "^1.9.0",
"nodemon": "^1.17.5",
"jest": "^23.5.0",
"mongodb-memory-server": "^2.0.1",
"nodemon": "^1.18.3",
"prettier-eslint": "^8.8.2",
"supertest": "^3.1.0"
},

586
react/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@material-ui/core": "^1.3.1",
"@material-ui/icons": "^1.1.0",
"@material-ui/icons": "^2.0.3",
"@redux-offline/redux-offline": "^2.4.0",
"localforage": "^1.7.2",
"prop-types": "^15.6.2",
@@ -13,7 +13,7 @@
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "1.1.4",
"react-scripts": "1.1.5",
"react-spring": "^5.4.0",
"redux": "^4.0.0",
"redux-form": "^7.4.2",
@@ -34,7 +34,7 @@
"devDependencies": {
"eslint": "^5.1.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-config-prettier": "^2.9.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-jsx-a11y": "^6.1.0",

View File

@@ -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);

View File

@@ -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);

View File

@@ -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')

View File

@@ -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');