-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.test.js
50 lines (38 loc) · 1.75 KB
/
model.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
// using products model as a testing should cover categories since its the same.
'use strict';
require('@code-fellows/supergoose');
const category = require('../lib/models/categories/categories-model');
describe ('Category Model', ()=> {
it('it can create()', async ()=> {
const catObj = {name: 'solarPower', display_name : 'Solar Power', description: 'Renewable Power from the sun'};
const result = await category.create(catObj);
Object.keys(catObj).forEach(key=> {
expect(result[key]).toEqual(catObj[key]);
});
});
it('it can get()', async ()=> {
const catObj = {name: 'windPower', display_name : 'Wind Power', description: 'Renewable Power but with wind'};
const result = await category.create(catObj);
const records = await category.get(result._id);
Object.keys(catObj).forEach(key=> {
expect(records[0][key]).toEqual(catObj[key]);
});
});
it('it can update()', async ()=> {
const catObj = {name: 'windPower', display_name : 'Wind Power', description: 'Renewable Power but with wind'};
const catObj1 = {name: 'solarPower', display_name : 'Solar Power', description: 'Renewable Power from the sun'};
const result = await category.create(catObj);
await category.update(result._id, catObj1);
const records = await category.get(result._id);
Object.keys(catObj1).forEach(key=> {
expect(records[0][key]).toEqual(catObj1[key]);
});
});
it('it can delete()', async ()=> {
const catObj = {name: 'windPower', display_name : 'Wind Power', description: 'Renewable Power but with wind'};
const result = await category.create(catObj);
const records = await category.get(result._id);
const deleted = await category.delete(records._id);
expect(deleted).toBeNull();
});
});