mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
4c5ba4ed7d
closes https://github.com/TryGhost/Team/issues/1916 closes https://github.com/TryGhost/Team/issues/1917 - Added database storage for link redirects and click events via repositories (hides away database layer) defined in the wrapper services - Added LinkClickRepository to store click events to database - Added LinkRedirectRepository to store link redirects to database - Added PostLinkRepository to link LinkRedirects with posts - Renamed link-replacement package to link-replacer, and made it dependency less (it only replaces links now, doesn't do anything else) - The link-tracking service has a new `addTrackingToUrl` which returns a new URL that includes tracking. The new `addRedirectToUrl` method does the same but without tracking for now. - MEGA service now uses the link-replacer to replace links in the emails using a combination of different services (member attribution + link-tracking service)
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
const assert = require('assert');
|
|
const linkReplacer = require('../lib/LinkReplacer');
|
|
|
|
describe('LinkReplacementService', function () {
|
|
it('exported', function () {
|
|
assert.equal(require('../index'), linkReplacer);
|
|
});
|
|
|
|
describe('replace', function () {
|
|
it('Can replace to URL', async function () {
|
|
const html = '<a href="http://localhost:2368/dir/path">link</a>';
|
|
const expected = '<a href="https://google.com/test-dir?test-query">link</a>';
|
|
|
|
const replaced = await linkReplacer.replace(html, () => new URL('https://google.com/test-dir?test-query'));
|
|
assert.equal(replaced, expected);
|
|
});
|
|
|
|
it('Can replace to string', async function () {
|
|
const html = '<a href="http://localhost:2368/dir/path">link</a>';
|
|
const expected = '<a href="#valid-string">link</a>';
|
|
|
|
const replaced = await linkReplacer.replace(html, () => '#valid-string');
|
|
assert.equal(replaced, expected);
|
|
});
|
|
|
|
it('Ignores invalid links', async function () {
|
|
const html = '<a href="invalid">link</a>';
|
|
const expected = '<a href="invalid">link</a>';
|
|
|
|
const replaced = await linkReplacer.replace(html, () => 'valid');
|
|
assert.equal(replaced, expected);
|
|
});
|
|
});
|
|
});
|