mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
104f84f252
As discussed with the product team we want to enforce kebab-case file names for all files, with the exception of files which export a single class, in which case they should be PascalCase and reflect the class which they export. This will help find classes faster, and should push better naming for them too. Some files and packages have been excluded from this linting, specifically when a library or framework depends on the naming of a file for the functionality e.g. Ember, knex-migrator, adapter-manager
112 lines
2.7 KiB
JavaScript
112 lines
2.7 KiB
JavaScript
// Switch these lines once there are useful utils
|
|
// const testUtils = require('./utils');
|
|
require('./utils');
|
|
const UrlHistory = require('../lib/UrlHistory');
|
|
|
|
describe('UrlHistory', function () {
|
|
it('sets history to empty array if invalid', function () {
|
|
const inputs = [
|
|
'string',
|
|
undefined,
|
|
12,
|
|
null,
|
|
{},
|
|
NaN,
|
|
[
|
|
{
|
|
time: 1,
|
|
path: '/test'
|
|
},
|
|
't'
|
|
],
|
|
[{}],
|
|
['test'],
|
|
[0],
|
|
[undefined],
|
|
[NaN],
|
|
[[]],
|
|
[{
|
|
time: 'test',
|
|
path: 'test'
|
|
}],
|
|
[{
|
|
path: 'test'
|
|
}],
|
|
[{
|
|
time: 123
|
|
}],
|
|
[{
|
|
time: 123,
|
|
type: 'post'
|
|
}],
|
|
[{
|
|
time: 123,
|
|
id: 'id'
|
|
}],
|
|
[{
|
|
time: 123,
|
|
type: 123,
|
|
id: 'test'
|
|
}],
|
|
[{
|
|
time: 123,
|
|
type: 'invalid',
|
|
id: 'test'
|
|
}],
|
|
[{
|
|
time: 123,
|
|
type: 'post',
|
|
id: 123
|
|
}]
|
|
];
|
|
|
|
for (const input of inputs) {
|
|
const history = UrlHistory.create(input);
|
|
should(history.history).eql([]);
|
|
}
|
|
});
|
|
|
|
it('sets history for valid arrays', function () {
|
|
const inputs = [
|
|
[],
|
|
[{
|
|
time: Date.now(),
|
|
path: '/test'
|
|
}],
|
|
[{
|
|
time: Date.now(),
|
|
type: 'post',
|
|
id: '123'
|
|
}],
|
|
[{
|
|
time: Date.now(),
|
|
type: 'post',
|
|
id: '123',
|
|
referrerSource: 'ghost-explore',
|
|
referrerMedium: null,
|
|
referrerUrl: 'https://ghost.org'
|
|
}]
|
|
];
|
|
for (const input of inputs) {
|
|
const history = UrlHistory.create(input);
|
|
should(history.history).eql(input);
|
|
}
|
|
});
|
|
|
|
it('removes entries older than 24 hours', function () {
|
|
const input = [{
|
|
time: Date.now() - 1000 * 60 * 60 * 25,
|
|
path: '/old'
|
|
}, {
|
|
time: Date.now() - 1000 * 60 * 60 * 23,
|
|
path: '/not-old'
|
|
}, {
|
|
time: Date.now() - 1000 * 60 * 60 * 25,
|
|
type: 'post',
|
|
id: 'old'
|
|
}];
|
|
const history = UrlHistory.create(input);
|
|
should(history.history).eql([input[1]]);
|
|
});
|
|
});
|