Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
Add loging test for is Admin and is not Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sbardian committed Mar 21, 2018
1 parent ac80581 commit 6a1353e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/server/routesLogic/login.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import session from 'supertest-session';
import mockingoose from 'mockingoose';
import { server } from '../server';
import { LOGIN_SUCCESS_MOCK_USER } from '../testEnv/fixtures';
import {
LOGIN_SUCCESS_MOCK_USER,
LOGIN_SUCCESS_MOCK_USER_ADMIN,
} from '../testEnv/fixtures';

jest.mock('./checkAuth');

describe('Test /login API routes', () => {
const serverSession = session(server);

it('Login success, return 200 status: ', async () => {
it('Login success is Admin, return 200 status: ', async () => {
mockingoose.User.toReturn(LOGIN_SUCCESS_MOCK_USER_ADMIN, 'findOne');
const response = await serverSession
.post('/auth/login')
.set('Accept', 'text/html, application/json')
.send({
email: LOGIN_SUCCESS_MOCK_USER.email,
password: LOGIN_SUCCESS_MOCK_USER.passwordConf,
});
expect(response.statusCode).toBe(200);
});
it('Login success not Admin, return 200 status: ', async () => {
mockingoose.User.toReturn(LOGIN_SUCCESS_MOCK_USER, 'findOne');
const response = await serverSession
.post('/auth/login')
Expand Down
12 changes: 11 additions & 1 deletion src/server/testEnv/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const LOGIN_SUCCESS_MOCK_USER = {
export const LOGIN_SUCCESS_MOCK_USER_ADMIN = {
_id: '5a8e41866c6f9f2f5d53330e',
email: 'test@test.com',
username: 'test',
Expand All @@ -8,6 +8,16 @@ export const LOGIN_SUCCESS_MOCK_USER = {
__v: 0,
};

export const LOGIN_SUCCESS_MOCK_USER = {
_id: '5a8e41866c6f9f2f5d53330e',
email: 'test@test.com',
username: 'test',
password: '$2a$10$IL3eU58fJ6ltVpYg0txAa.arQNXI6el9Lmrrc78hdnnbfU5tg3HcW',
passwordConf: 'test',
isAdmin: false,
__v: 0,
};

export const SUCCESS_REGISTER_MOCK_USER = {
email: 'success@success.com',
username: 'success',
Expand Down

0 comments on commit 6a1353e

Please sign in to comment.