mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-09-11 12:55:37 +03:00
Added tests for fix - URLs sent in emails containing a % can not be updated (#20569)
ref ENG-1372 ENG-447
This commit is contained in:
parent
c6e001280c
commit
81df7ca05b
@ -5,6 +5,7 @@ const assert = require('assert/strict');
|
||||
const ObjectID = require('bson-objectid').default;
|
||||
const PostLink = require('../lib/PostLink');
|
||||
const {RedirectEvent} = require('@tryghost/link-redirects');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
describe('LinkClickTrackingService', function () {
|
||||
it('exists', function () {
|
||||
@ -208,5 +209,141 @@ describe('LinkClickTrackingService', function () {
|
||||
unsuccessfulData: []
|
||||
});
|
||||
});
|
||||
|
||||
//test for #parseLinkFilter method
|
||||
it('correctly decodes and parses the filter', async function () {
|
||||
const urlUtilsStub = {
|
||||
absoluteToTransformReady: sinon.stub().returnsArg(0),
|
||||
isSiteUrl: sinon.stub().returns(true)
|
||||
};
|
||||
const postLinkRepositoryStub = {
|
||||
updateLinks: sinon.stub().resolves({
|
||||
successful: 0,
|
||||
unsuccessful: 0,
|
||||
errors: [],
|
||||
unsuccessfulData: []
|
||||
})
|
||||
};
|
||||
const linkRedirectServiceStub = {
|
||||
getFilteredIds: sinon.stub().resolves([])
|
||||
};
|
||||
|
||||
const service = new LinkClickTrackingService({
|
||||
urlUtils: urlUtilsStub,
|
||||
postLinkRepository: postLinkRepositoryStub,
|
||||
linkRedirectService: linkRedirectServiceStub
|
||||
});
|
||||
|
||||
const options = {
|
||||
filter: 'post_id:1+to:\'https://example.com/path\''
|
||||
};
|
||||
|
||||
const data = {
|
||||
action: 'updateLink',
|
||||
meta: {
|
||||
link: {to: 'https://example.com/new-path'}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await service.bulkEdit(data, options);
|
||||
|
||||
should(postLinkRepositoryStub.updateLinks.calledOnce).be.true();
|
||||
should(result).eql({
|
||||
successful: 0,
|
||||
unsuccessful: 0,
|
||||
errors: [],
|
||||
unsuccessfulData: []
|
||||
});
|
||||
|
||||
const [filterOptions] = linkRedirectServiceStub.getFilteredIds.firstCall.args;
|
||||
should(filterOptions.filter).equal('post_id:\'1\'+to:\'https://example.com/path\'');
|
||||
});
|
||||
|
||||
//test for #parseLinkFilter method
|
||||
it('correctly decodes and parses the filter for encoded urls', async function () {
|
||||
const urlUtilsStub = {
|
||||
absoluteToTransformReady: sinon.stub().returnsArg(0),
|
||||
isSiteUrl: sinon.stub().returns(true)
|
||||
};
|
||||
const postLinkRepositoryStub = {
|
||||
updateLinks: sinon.stub().resolves({
|
||||
successful: 0,
|
||||
unsuccessful: 0,
|
||||
errors: [],
|
||||
unsuccessfulData: []
|
||||
})
|
||||
};
|
||||
const linkRedirectServiceStub = {
|
||||
getFilteredIds: sinon.stub().resolves([])
|
||||
};
|
||||
|
||||
const service = new LinkClickTrackingService({
|
||||
urlUtils: urlUtilsStub,
|
||||
postLinkRepository: postLinkRepositoryStub,
|
||||
linkRedirectService: linkRedirectServiceStub
|
||||
});
|
||||
|
||||
const options = {
|
||||
filter: 'post_id:1+to:\'https://example.com/path%2Ftestpath\''
|
||||
};
|
||||
|
||||
const data = {
|
||||
action: 'updateLink',
|
||||
meta: {
|
||||
link: {to: 'https://example.com/new-path'}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await service.bulkEdit(data, options);
|
||||
|
||||
should(postLinkRepositoryStub.updateLinks.calledOnce).be.true();
|
||||
should(result).eql({
|
||||
successful: 0,
|
||||
unsuccessful: 0,
|
||||
errors: [],
|
||||
unsuccessfulData: []
|
||||
});
|
||||
|
||||
const [filterOptions] = linkRedirectServiceStub.getFilteredIds.firstCall.args;
|
||||
should(filterOptions.filter).equal('post_id:\'1\'+to:\'https://example.com/path%2Ftestpath\'');
|
||||
});
|
||||
|
||||
//test for #parseLinkFilter method
|
||||
it('throws BadRequestError for invalid filter', async function () {
|
||||
const urlUtilsStub = {
|
||||
absoluteToTransformReady: sinon.stub().returnsArg(0),
|
||||
isSiteUrl: sinon.stub().returns(true)
|
||||
};
|
||||
const postLinkRepositoryStub = {
|
||||
updateLinks: sinon.stub().resolves({
|
||||
successful: 0,
|
||||
unsuccessful: 0,
|
||||
errors: [],
|
||||
unsuccessfulData: []
|
||||
})
|
||||
};
|
||||
const linkRedirectServiceStub = {
|
||||
getFilteredIds: sinon.stub().resolves([])
|
||||
};
|
||||
|
||||
const service = new LinkClickTrackingService({
|
||||
urlUtils: urlUtilsStub,
|
||||
postLinkRepository: postLinkRepositoryStub,
|
||||
linkRedirectService: linkRedirectServiceStub
|
||||
});
|
||||
|
||||
const options = {
|
||||
filter: 'invalid_filter'
|
||||
};
|
||||
|
||||
const data = {
|
||||
action: 'updateLink',
|
||||
meta: {
|
||||
link: {to: 'https://example.com/new-path'}
|
||||
}
|
||||
};
|
||||
|
||||
await should(service.bulkEdit(data, options)).be.rejectedWith(errors.BadRequestError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user