forked from labs15-music-meteorologist/backend
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.spec.js
110 lines (102 loc) · 3.09 KB
/
server.spec.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const request = require('supertest');
const server = require('./server.js');
/* ENDPOINT TEST API RUNNING */
describe('API WELCOME MESSAGE RUNNING', () => {
it('greets the user', () => {
return request(server)
.get('/')
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8');
});
});
/* ENDPOINT GET ALL USERS */
describe('GET ALL USERS OK', () => {
it('runs ok', () => {
return request(server)
.get('/v1/users/')
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/);
});
});
/* ENDPOINT GET A SINGLE USER */
describe('GET A SINGLE USER OK', () => {
it('runs ok', () => {
return request(server)
.get('/v1/users/1')
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/);
});
});
/* VALIDATION TESTS REGISTER A USER*/
describe('REGISTER A USER NO BODY', () => {
it('returns 400 No Body Provided', () => {
return request(server)
.post('/v1/users/register')
.send({})
.set('Accept', 'application/json')
.expect(400)
.expect('Content-Type', /json/)
.expect('Content-Length', '41')
.then(res => {
expect(res.body.warning).toBe(`Missing user data entirely.`);
});
});
});
describe('REGISTER A USER NO COMPLETE USER', () => {
it('returns 400 User Data Not Complete', () => {
return request(server)
.post('/v1/users/register')
.send({
email: '[email protected]',
spotify_user_id: 'update',
user_spotify_api_key: 'FromThe',
})
.set('Accept', 'application/json')
.expect(400)
.expect('Content-Type', /json/)
.expect('Content-Length', '172')
.then(res => {
expect(res.body.warning).toBe(
`Missing required email or spotify_user_id or user_spotify_api_key or date_of_birth or spotify_product_type or display_name or country information for an user.`,
);
});
});
});
/* VALIDATION TESTS UPDATE A USER*/
describe('UPDATE A USER NO BODY', () => {
it('returns 400 No Body Provided', () => {
return request(server)
.put('/v1/users/1')
.send({})
.set('Accept', 'application/json')
.expect(400)
.expect('Content-Type', /json/)
.expect('Content-Length', '41')
.then(res => {
expect(res.body.warning).toBe(`Missing user data entirely.`);
});
});
});
describe('UPDATE A USER NO COMPLETE USER', () => {
it('returns 400 User Data Not Complete', () => {
return request(server)
.put('/v1/users/1')
.send({
email: '[email protected]',
spotify_user_id: 'update',
user_spotify_api_key: 'FromThe',
})
.set('Accept', 'application/json')
.expect(400)
.expect('Content-Type', /json/)
.expect('Content-Length', '172')
.then(res => {
expect(res.body.warning).toBe(
`Missing required email or spotify_user_id or user_spotify_api_key or date_of_birth or spotify_product_type or display_name or country information for an user.`,
);
});
});
});