-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.test.js
More file actions
65 lines (56 loc) · 2.25 KB
/
server.test.js
File metadata and controls
65 lines (56 loc) · 2.25 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
const request = require('supertest');
const app = require('./server');
const environment = process.env.NODE_ENV || 'development';
const configuration = require('./knexfile')[environment];
const database = require('knex')(configuration);
// describe('API', () => {
// beforeEach(async () => {
// await database.seed.run();
// })
// });
describe('GET / beauty_products', () => {
describe('happy path', () => {
it('should return a status code of 200', async () => {
const res = await request(app).get('/api/v1/beauty_products');
expect(res.status).toBe(200);
});
it('should return all beauty products in the database', async () => {
const expectedProducts = await database('beauty_products').select();
const cleanedExpectedProducts = expectedProducts.map(prod => {
return { name: prod.name, id: prod.id }
})
const result = await request(app).get('/api/v1/beauty_products');
const beautyProducts = result.body;
const cleanedBeautyProducts = beautyProducts.map(prod => {
return { name: prod.name, id: prod.id }
})
expect(cleanedBeautyProducts).toEqual(cleanedExpectedProducts);
});
it('should return a beauty_product with a query name', async () => {
const expectedProductName = "Blush";
const res = await request(app).get('/api/v1/beauty_products/?name=Blush');
const productName = res.body[0].name;
expect(productName).toEqual(expectedProductName);
})
});
});
describe('GET / notes', () => {
describe('happy path', () => {
it('should return a status code of 200', async () => {
const res = await request(app).get('/api/v1/notes');
expect(res.status).toBe(200);
});
it('should return all notes in the database', async () => {
const expectedNotes = await database('notes').select();
const cleanedExpectedNotes = expectedNotes.map(note => {
return { id: note.id, beauty_product_id: note.beauty_product_id }
})
const result = await request(app).get('/api/v1/notes');
const notes = result.body;
const cleanedNotes = notes.map(note => {
return { id: note.id, beauty_product_id: note.beauty_product_id }
})
expect(cleanedNotes).toEqual(cleanedExpectedNotes);
});
});
})