-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
/
pages_spec.js
54 lines (45 loc) · 1.55 KB
/
pages_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
const should = require('should');
const sinon = require('sinon');
const testUtils = require('../../../../../../utils');
const mapper = require('../../../../../../../server/api/v2/utils/serializers/output/utils/mapper');
const serializers = require('../../../../../../../server/api/v2/utils/serializers');
const sandbox = sinon.sandbox.create();
describe('Unit: v2/utils/serializers/output/pages', () => {
let pageModel;
beforeEach(() => {
pageModel = (data) => {
return Object.assign(data, {toJSON: sandbox.stub().returns(data)});
};
sandbox.stub(mapper, 'mapPost').returns({});
});
afterEach(() => {
sandbox.restore();
});
it('calls the mapper', () => {
const apiConfig = {};
const frame = {
options: {
withRelated: ['tags', 'authors'],
context: {
private: false
}
}
};
const ctrlResponse = {
data: [
pageModel(testUtils.DataGenerator.forKnex.createPost({
id: 'id1',
page: true
})),
pageModel(testUtils.DataGenerator.forKnex.createPost({
id: 'id2',
page: true
}))
],
meta: {}
};
serializers.output.pages.all(ctrlResponse, apiConfig, frame);
mapper.mapPost.callCount.should.equal(2);
mapper.mapPost.getCall(0).args.should.eql([ctrlResponse.data[0], frame]);
});
});