-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.test.js
55 lines (52 loc) · 1.6 KB
/
app.test.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
const app = require('./app.js');
const request = require('supertest');
describe('Server is running', () => {
test('Server responds to GET requests on /reviews/', () => {
return request(app)
.get('/reviews')
.then((res) => {
expect(res.statusCode).not.toBe(404); //should be 422 because no product_id provided, but not testing that here
});
});
test('Server does NOT respond to GET requests on /products', () => {
let requestPromises = [];
return request(app)
.get('/products')
.then((res) => {
expect(res.statusCode).toBe(404);
});
});
test('Server does NOT respond to GET requests on /qa', () => {
return request(app)
.get('/qa')
.then((res) => {
expect(res.statusCode).toBe(404);
});
});
});
describe('GET requests to API endpoint /reviews responds as expected', () => {
test('Request without product_id responds with status code 422', () => {
return request(app)
.get('/reviews')
.then((res) => {
expect(res.statusCode).toBe(422);
});
});
test('Server should respond with an array', () => {
return request(app)
.get('/reviews?product_id=1')
.then((res) => {
console.log('res.body: ', res.body);
expect(res.body).toBeInstanceOf(Array);
});
});
test('Responses should match provided product_id', () => {
return request(app)
.get('/reviews?product_id=1')
.then((res) => {
console.log('res.body: ', res.body);
expect(res.body[0]).toHaveProperty('product_id', 1);
});
});
// more tests: page, count, sort
});