-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.unit.test.js
85 lines (83 loc) · 2.63 KB
/
app.unit.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
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
const service = require('./services/categories');
//mock for main model that my controller function uses
// jest.mock('./models/category', () => {
// const SequelizeMock = require('sequelize-mock');
// const dbMock = new SequelizeMock();
// return dbMock.define('Category', [
// {
// id: 1,
// name: 'Cat 1',
// parent_id: null,
// createdAt: new Date(),
// updatedAt: new Date()
// },
// {
// id: 2,
// name: 'Cat 2',
// parent_id: null,
// createdAt: new Date(),
// updatedAt: new Date()
// },
// {
// id: 3,
// name: 'Cat 3',
// parent_id: 2,
// createdAt: new Date(),
// updatedAt: new Date()
// },
// {
// id: 4,
// name: 'Cat 4',
// parent_id: 2,
// createdAt: new Date(),
// updatedAt: new Date()
// },
// {
// id: 5,
// name: 'Cat 5',
// parent_id: 2,
// createdAt: new Date(),
// updatedAt: new Date()
// },
// {
// id: 6,
// name: 'Cat 6',
// parent_id: 3,
// createdAt: new Date(),
// updatedAt: new Date()
// }
// ])
// });
describe('categories service', () => {
it('should get more than one parent category', async () => {
const category = await service.findParentCategories()
expect(category.length).toBeGreaterThan(1);
});
it('should get single category based on id', async () => {
const category = await service.findSingleCategory(1)
expect(category).toHaveLength(1);
expect(category[0].id).toEqual(1);
});
it('should not get any category', async () => {
const category = await service.findSingleCategory(199999)
expect(category).toHaveLength(0);
});
it('should get a category subcategories', async () => {
const category = await service.findSubCategories(2)
expect(category).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: 3,
subcategory: expect.arrayContaining([
expect.objectContaining({
id: 6,
})
])
})
]));
});
it('should get a category subcategories', async () => {
const category = await service.findSubCategories(1)
expect(category).toEqual(null);
});
});