-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathadminSignIn.js
More file actions
86 lines (81 loc) · 2.86 KB
/
Copy pathadminSignIn.js
File metadata and controls
86 lines (81 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import request from 'supertest';
import app from '../api';
describe('Admin Signin', () => {
const signinRoute = '/api/v1/auth/admin/signin';
it('Successful', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'admin@test.com',
password: 'password'
});
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('token');
expect(res.body).toHaveProperty('refreshToken');
expect(res.body.status).toBe(200);
expect(res.body.message).toBe('Successfully Signed In');
});
it('when no data', async () => {
const res = await request(app)
.post(signinRoute)
.send();
expect(res.statusCode).toEqual(400);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('data');
expect(res.body.data).toHaveProperty('email');
expect(res.body.data).toHaveProperty('password');
expect(res.body.status).toBe(400);
expect(res.body.message).toBe('Fields are required');
expect(res.body.data.email).toBe('Please put in a valid email');
expect(res.body.data.password)
.toBe('Password should be at least 7 characters long');
});
it('Email dont exist', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'freddy48@test.com',
password: 'password'
});
expect(res.statusCode).toEqual(404);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('data');
expect(res.body.data).toHaveProperty('email');
expect(res.body.status).toBe(404);
expect(res.body.message).toBe('Email error');
expect(res.body.data.email).toBe('Email does not exist');
});
it('Incorrect Password', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'admin@test.com',
password: 'password22'
});
expect(res.statusCode).toEqual(400);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body).toHaveProperty('data');
expect(res.body.data).toHaveProperty('password');
expect(res.body.status).toBe(400);
expect(res.body.message).toBe('Password error');
expect(res.body.data.password).toBe('Password is incorrect');
});
it('when not admin', async () => {
const res = await request(app)
.post(signinRoute)
.send({
email: 'freddy@test.com',
password: 'password'
});
expect(res.statusCode).toEqual(401);
expect(res.body).toHaveProperty('message');
expect(res.body).toHaveProperty('status');
expect(res.body.status).toBe(401);
expect(res.body.message).toBe('Unauthorized Account');
});
});