2022-09-19 09:45:52 +03:00
|
|
|
// Switch these lines once there are useful utils
|
|
|
|
// const testUtils = require('./utils');
|
|
|
|
require('./utils');
|
|
|
|
const ReferrerTranslator = require('../lib/referrer-translator');
|
|
|
|
|
|
|
|
describe('ReferrerTranslator', function () {
|
|
|
|
describe('Constructor', function () {
|
|
|
|
it('doesn\'t throw', function () {
|
|
|
|
new ReferrerTranslator({});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getReferrerDetails', function () {
|
|
|
|
let translator;
|
|
|
|
before(function () {
|
|
|
|
translator = new ReferrerTranslator({
|
|
|
|
siteUrl: 'https://example.com',
|
|
|
|
adminUrl: 'https://admin.example.com/ghost'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns ghost explore from source ref for valid history', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: 'ghost-explore',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://t.co'
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'Ghost Explore',
|
|
|
|
refMedium: 'Ghost Network',
|
|
|
|
refUrl: null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns ghost explore from url for valid history', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://ghost.org/explore'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://t.co'
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'Ghost Explore',
|
|
|
|
refMedium: 'Ghost Network',
|
2022-09-21 12:29:55 +03:00
|
|
|
refUrl: 'ghost.org'
|
2022-09-19 09:45:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns ghost explore from admin url for valid history', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://admin.example.com/ghost/#/dashboard'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://t.co'
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'Ghost Explore',
|
|
|
|
refMedium: 'Ghost Network',
|
2022-09-21 12:29:55 +03:00
|
|
|
refUrl: 'admin.example.com'
|
2022-09-19 09:45:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns ghost newsletter ref for valid history', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: 'publisher-weekly-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-explore',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://t.co'
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'publisher weekly newsletter',
|
|
|
|
refMedium: 'Email',
|
|
|
|
refUrl: null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns ghost.org ref for valid history', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://ghost.org/creators/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'publisher-weekly-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-explore',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'Ghost.org',
|
|
|
|
refMedium: 'Ghost Network',
|
2022-09-21 12:29:55 +03:00
|
|
|
refUrl: 'ghost.org'
|
2022-09-19 09:45:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns ref source for valid history', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: 'twitter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'publisher-weekly-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-explore',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'twitter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-19 17:52:19 +03:00
|
|
|
describe('returns source and medium for', function () {
|
|
|
|
it('known external url with path', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://google.ac/products'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://t.co/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'publisher-weekly-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-explore',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'Google Product Search',
|
|
|
|
refMedium: 'search',
|
2022-09-21 12:29:55 +03:00
|
|
|
refUrl: 'google.ac'
|
2022-09-19 17:52:19 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('known external url without path', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://t.co/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'publisher-weekly-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'ghost-explore',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
}
|
|
|
|
])).eql({
|
|
|
|
refSource: 'Twitter',
|
|
|
|
refMedium: 'social',
|
2022-09-21 12:29:55 +03:00
|
|
|
refUrl: 't.co'
|
2022-09-19 17:52:19 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-21 12:29:55 +03:00
|
|
|
it('returns external ref url as source', async function () {
|
2022-09-19 17:52:19 +03:00
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://example.com'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://sample.com'
|
2022-09-21 12:29:55 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
refSource: 'publisher-weekly-newsletter',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
2022-09-19 17:52:19 +03:00
|
|
|
}
|
|
|
|
])).eql({
|
2022-09-21 12:29:55 +03:00
|
|
|
refSource: 'sample.com',
|
2022-09-19 17:52:19 +03:00
|
|
|
refMedium: null,
|
2022-09-21 12:29:55 +03:00
|
|
|
refUrl: 'sample.com'
|
2022-09-19 17:52:19 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-09-19 09:45:52 +03:00
|
|
|
it('returns null for empty history', async function () {
|
2022-09-21 12:29:55 +03:00
|
|
|
should(translator.getReferrerDetails([])).eql({
|
|
|
|
refSource: 'Direct',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
});
|
2022-09-19 09:45:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null for history with only site url', async function () {
|
|
|
|
should(translator.getReferrerDetails([
|
|
|
|
{
|
|
|
|
refSource: null,
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: 'https://example.com'
|
|
|
|
}
|
2022-09-21 12:29:55 +03:00
|
|
|
])).eql({
|
|
|
|
refSource: 'Direct',
|
|
|
|
refMedium: null,
|
|
|
|
refUrl: null
|
|
|
|
});
|
2022-09-19 09:45:52 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|