Resolve conflicts

This commit is contained in:
Elliot DeNolf
2020-04-12 21:46:11 -04:00
parent df6b9b13ac
commit 375f046cfa
5 changed files with 35 additions and 78 deletions

View File

@@ -3,6 +3,7 @@ module.exports = {
env: {
browser: true,
es6: true,
jest: true,
},
extends: 'airbnb',
parserOptions: {
@@ -65,6 +66,7 @@ module.exports = {
{
"maximum": 1
}
]
],
"linebreak-style": ["off"]
},
};

17
.vscode/settings.json vendored
View File

@@ -1,3 +1,18 @@
{
"eslint.enable": true
"eslint.enable": true,
"workbench.colorCustomizations": {
"editorWhitespace.foreground": "#1e1e1e",
"activityBar.background": "#3399ff",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#bf0060",
"activityBarBadge.foreground": "#e7e7e7",
"titleBar.activeBackground": "#007fff",
"titleBar.inactiveBackground": "#007fff99",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#007fff",
"statusBarItem.hoverBackground": "#3399ff",
"statusBar.foreground": "#e7e7e7"
}
}

View File

@@ -1,12 +1,12 @@
import axios from 'axios';
import * as faker from 'faker';
const axios = require('axios');
const faker = require('faker');
describe('API', () => {
let token = null;
beforeAll(async () => {
const loginResponse = await axios.post('http://localhost:3000/login', {
email: 'test@test.com',
password: 'test123'
password: 'test123',
});
token = loginResponse.data.token;
expect(loginResponse.status).toBe(200);
@@ -16,7 +16,7 @@ describe('API', () => {
const email = `${faker.name.firstName()}@test.com`;
const createResponse = await axios.post('http://localhost:3000/users', {
email: `${email}`,
password: 'test123'
password: 'test123',
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(createResponse.status).toBe(200);
@@ -28,7 +28,7 @@ describe('API', () => {
it('should allow create page', async () => {
const createResponse = await axios.post('http://localhost:3000/pages', {
title: faker.name.firstName(),
content: faker.lorem.lines(20)
content: faker.lorem.lines(20),
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(createResponse.status).toBe(201);
expect(createResponse.data.result.title).not.toBeNull();
@@ -37,14 +37,14 @@ describe('API', () => {
it('should allow create page - locale', async () => {
const englishCreateResponse = await axios.post('http://localhost:3000/pages', {
title: `English-${faker.name.firstName()}`,
content: faker.lorem.lines(20)
content: faker.lorem.lines(20),
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(englishCreateResponse.status).toBe(201);
const id = englishCreateResponse.data.result.id;
const { id } = englishCreateResponse.data.result;
const spanishCreateResponse = await axios.put(`http://localhost:3000/pages/${id}?locale=es`, {
title: `Spanish-${faker.name.firstName()}`,
content: faker.lorem.lines(20)
content: faker.lorem.lines(20),
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(spanishCreateResponse.status).toBe(200);
});
@@ -52,8 +52,8 @@ describe('API', () => {
it('should allow querying of page', async () => {
const title = `English-${faker.name.firstName()}`;
const englishCreateResponse = await axios.post('http://localhost:3000/pages', {
title: title,
content: faker.lorem.lines(20)
title,
content: faker.lorem.lines(20),
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(englishCreateResponse.status).toBe(201);
@@ -67,15 +67,15 @@ describe('API', () => {
const englishTitle = `English-${faker.name.firstName()}`;
const englishCreateResponse = await axios.post('http://localhost:3000/pages', {
title: englishTitle,
content: faker.lorem.lines(20)
content: faker.lorem.lines(20),
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(englishCreateResponse.status).toBe(201);
const id = englishCreateResponse.data.result.id;
const { id } = englishCreateResponse.data.result;
const spanishTitle = `Spanish-${faker.name.firstName()}`;
const spanishCreateResponse = await axios.put(`http://localhost:3000/pages/${id}?locale=es`, {
title: spanishTitle,
content: faker.lorem.lines(20)
content: faker.lorem.lines(20),
}, { headers: { Authorization: `JWT ${token}`, 'Content-Type': 'application/json' } });
expect(spanishCreateResponse.status).toBe(200);

View File

@@ -1,4 +1,4 @@
import defaults from './jest.config';
const defaults = require('./jest.config');
module.exports = {
...defaults,

View File

@@ -1,6 +1,5 @@
import localizationMiddleware from '../../localization/localization.middleware';
import checkRoleMiddleware from '../../auth/checkRole.middleware';
import mockExpress from 'jest-mock-express';
const mockExpress = require('jest-mock-express');
const localizationMiddleware = require('../../localization/middleware');
let res = null;
let next = null;
@@ -10,66 +9,7 @@ describe('Payload Middleware', () => {
next = jest.fn();
});
describe('Payload Role Middleware', () => {
it('Exact role - authorized', () => {
const req = {
user: {
role: 'user'
}
};
checkRoleMiddleware('user')(req, res, next);
expect(next).toHaveBeenCalledTimes(1);
expect(res.status).not.toHaveBeenCalled();
});
it('Exact role - unauthorized', () => {
const req = {
user: {
role: 'user'
}
};
checkRoleMiddleware('admin')(req, res, next);
expect(next).not.toHaveBeenCalled();
expect(res.status).toHaveBeenCalled();
expect(res.send).toHaveBeenCalled();
});
it('Roles handle array - authorized', () => {
const req = {
user: {
role: 'user'
}
};
checkRoleMiddleware('admin', 'user')(req, res, next);
expect(next).toHaveBeenCalledTimes(1);
expect(res.status).not.toHaveBeenCalled();
});
it('Roles handle array - unauthorized', () => {
const req = {
user: {
role: 'user'
}
};
checkRoleMiddleware('admin', 'owner')(req, res, next);
expect(next).not.toHaveBeenCalled();
expect(res.status).toHaveBeenCalled();
expect(res.send).toHaveBeenCalled();
});
});
describe('Payload Locale Middleware', () => {
let req, localization;
beforeEach(() => {