2019-08-09 19:55:12 +05:30
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const testUtils = require('../../../../../../utils');
|
2022-03-16 12:44:11 +00:00
|
|
|
const mappers = require('../../../../../../../core/server/api/canary/utils/serializers/output/mappers');
|
2022-03-02 21:30:22 +05:30
|
|
|
const membersService = require('../../../../../../../core/server/services/members');
|
2020-03-30 16:26:47 +01:00
|
|
|
const serializers = require('../../../../../../../core/server/api/canary/utils/serializers');
|
2019-08-09 19:55:12 +05:30
|
|
|
|
2019-08-19 12:41:09 +01:00
|
|
|
describe('Unit: canary/utils/serializers/output/posts', function () {
|
2019-08-09 19:55:12 +05:30
|
|
|
let postModel;
|
|
|
|
|
2019-08-19 12:41:09 +01:00
|
|
|
beforeEach(function () {
|
2019-08-09 19:55:12 +05:30
|
|
|
postModel = (data) => {
|
|
|
|
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
|
|
|
|
};
|
|
|
|
|
2022-03-02 21:30:22 +05:30
|
|
|
sinon.stub(membersService, 'api').get(() => {
|
|
|
|
return {
|
|
|
|
productRepository: {
|
|
|
|
list: () => {
|
|
|
|
return {data: null};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-03-16 12:44:11 +00:00
|
|
|
sinon.stub(mappers, 'posts').returns({});
|
2019-08-09 19:55:12 +05:30
|
|
|
});
|
|
|
|
|
2019-08-19 12:41:09 +01:00
|
|
|
afterEach(function () {
|
2019-08-09 19:55:12 +05:30
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2022-01-26 16:56:33 +05:30
|
|
|
it('calls the mapper', async function () {
|
2019-08-09 19:55:12 +05:30
|
|
|
const apiConfig = {};
|
|
|
|
const frame = {
|
|
|
|
options: {
|
|
|
|
withRelated: ['tags', 'authors'],
|
|
|
|
context: {
|
|
|
|
private: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ctrlResponse = {
|
|
|
|
data: [
|
|
|
|
postModel(testUtils.DataGenerator.forKnex.createPost({})),
|
|
|
|
postModel(testUtils.DataGenerator.forKnex.createPost({}))
|
|
|
|
],
|
|
|
|
meta: {}
|
|
|
|
};
|
|
|
|
|
2022-01-26 16:56:33 +05:30
|
|
|
await serializers.output.posts.all(ctrlResponse, apiConfig, frame);
|
2019-08-09 19:55:12 +05:30
|
|
|
|
2022-03-16 12:44:11 +00:00
|
|
|
mappers.posts.callCount.should.equal(2);
|
|
|
|
mappers.posts.getCall(0).args.should.eql([ctrlResponse.data[0], frame, {tiers: []}]);
|
2019-08-09 19:55:12 +05:30
|
|
|
});
|
|
|
|
});
|