mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs https://github.com/TryGhost/Team/issues/1004 The `tiers` column for a post/page only contained data if its visibility is set to `tiers`, otherwise its empty. This is because originally the purpose of `tiers` column on `post` was to capture specific tiers with access to post. The best way to ensure a consistent behavior for `tiers` column data on post is to update it to always contain list of all `tiers` that have access to post, and not just when the visibility is `tiers`. This means the value is set to all tiers when visibility is one of public|members, and only paid tiers when visibility is `paid`. This change also allows on frontend to get all relevant `tiers` information for a post locally within post context instead of relying on additional information from outside. This change - - updates the output serializer for post/page to add all desired tiers manually in case of visibility is not `tiers` - updates tests
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const testUtils = require('../../../../../../utils');
|
|
const mapper = require('../../../../../../../core/server/api/canary/utils/serializers/output/utils/mapper');
|
|
const membersService = require('../../../../../../../core/server/services/members');
|
|
const serializers = require('../../../../../../../core/server/api/canary/utils/serializers');
|
|
|
|
describe('Unit: canary/utils/serializers/output/posts', function () {
|
|
let postModel;
|
|
|
|
beforeEach(function () {
|
|
postModel = (data) => {
|
|
return Object.assign(data, {toJSON: sinon.stub().returns(data)});
|
|
};
|
|
|
|
sinon.stub(membersService, 'api').get(() => {
|
|
return {
|
|
productRepository: {
|
|
list: () => {
|
|
return {data: null};
|
|
}
|
|
}
|
|
};
|
|
});
|
|
|
|
sinon.stub(mapper, 'mapPost').returns({});
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('calls the mapper', async function () {
|
|
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: {}
|
|
};
|
|
|
|
await serializers.output.posts.all(ctrlResponse, apiConfig, frame);
|
|
|
|
mapper.mapPost.callCount.should.equal(2);
|
|
mapper.mapPost.getCall(0).args.should.eql([ctrlResponse.data[0], frame, {tiers: []}]);
|
|
});
|
|
});
|