mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 09:53:32 +03:00
6161f94910
refs: https://github.com/TryGhost/Toolbox/issues/595 We're rolling out new rules around the node assert library, the first of which is enforcing the use of assert/strict. This means we don't need to use the strict version of methods, as the standard version will work that way by default. This caught some gotchas in our existing usage of assert where the lack of strict mode had unexpected results: - Url matching needs to be done on `url.href` seeaa58b354a4
- Null and undefined are not the same thing, there were a few cases of this being confused - Particularly questionable changes in [PostExporter tests](c1a468744b
) tracked [here](https://github.com/TryGhost/Team/issues/3505). - A typo seeeaac9c293a
Moving forward, using assert strict should help us to catch unexpected behaviour, particularly around nulls and undefineds during implementation.
47 lines
1.9 KiB
JavaScript
47 lines
1.9 KiB
JavaScript
require('should');
|
|
const {agentProvider, fixtureManager, mockManager} = require('../../utils/e2e-framework');
|
|
const models = require('../../../core/server/models');
|
|
const assert = require('assert/strict');
|
|
let agent;
|
|
|
|
describe('Last Seen At Updater', function () {
|
|
before(async function () {
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
await fixtureManager.init('newsletters', 'members:newsletters');
|
|
await agent.loginAsOwner();
|
|
});
|
|
|
|
it('updateLastSeenAtWithoutKnownLastSeen', async function () {
|
|
const membersEvents = require('../../../core/server/services/members-events');
|
|
|
|
// Fire lots of EmailOpenedEvent for the same
|
|
const memberId = fixtureManager.get('members', 0).id;
|
|
|
|
const firstDate = new Date(Date.UTC(2099, 11, 31, 21, 0, 0, 0));
|
|
// In UTC this is 2099-12-31 21:00:00
|
|
// In CET this is 2099-12-31 22:00:00
|
|
|
|
const secondDate = new Date(Date.UTC(2099, 11, 31, 22, 0, 0, 0));
|
|
// In UTC this is 2099-12-31 22:00:00
|
|
// In CET this is 2099-12-31 23:00:00
|
|
|
|
const newDay = new Date(Date.UTC(2099, 11, 31, 23, 0, 0, 0));
|
|
// In UTC this is 2099-12-31 23:00:00
|
|
// In CET this is 2100-01-01 00:00:00
|
|
|
|
async function assertLastSeen(date) {
|
|
const member = await models.Member.findOne({id: memberId}, {require: true});
|
|
assert.equal(member.get('last_seen_at').getTime(), date.getTime());
|
|
}
|
|
|
|
mockManager.mockSetting('timezone', 'CET');
|
|
|
|
await membersEvents.lastSeenAtUpdater.updateLastSeenAtWithoutKnownLastSeen(memberId, firstDate);
|
|
await assertLastSeen(firstDate);
|
|
await membersEvents.lastSeenAtUpdater.updateLastSeenAtWithoutKnownLastSeen(memberId, secondDate);
|
|
await assertLastSeen(firstDate); // not changed
|
|
await membersEvents.lastSeenAtUpdater.updateLastSeenAtWithoutKnownLastSeen(memberId, newDay);
|
|
await assertLastSeen(newDay); // changed
|
|
});
|
|
});
|