mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
|
// Switch these lines once there are useful utils
|
||
|
// const testUtils = require('./utils');
|
||
|
require('./utils');
|
||
|
|
||
|
const updateUserLastSeenMiddleware = require('../lib/mw-update-user-last-seen');
|
||
|
|
||
|
class UserMock {
|
||
|
constructor(initialProps) {
|
||
|
this._props = initialProps;
|
||
|
}
|
||
|
|
||
|
get(property) {
|
||
|
return this._props[property];
|
||
|
}
|
||
|
|
||
|
updateLastSeen() {
|
||
|
this._props.last_seen = Date.now();
|
||
|
return Promise.resolve();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
describe('Update User Last Seen Middleware', function () {
|
||
|
it('Does nothing when no user exists', function (done) {
|
||
|
updateUserLastSeenMiddleware({}, undefined, () => {
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('Does nothing when user last seen in future', function (done) {
|
||
|
const lastSeen = Date.now() + 10 * 1000;
|
||
|
const user = new UserMock({
|
||
|
last_seen: lastSeen
|
||
|
});
|
||
|
|
||
|
updateUserLastSeenMiddleware({user}, undefined, () => {
|
||
|
user.get('last_seen').should.equal(lastSeen);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('Does nothing when user last seen less than 1 hour ago', function (done) {
|
||
|
const lastSeen = Date.now() - 59 * 60 * 1000;
|
||
|
const user = new UserMock({
|
||
|
last_seen: lastSeen
|
||
|
});
|
||
|
|
||
|
updateUserLastSeenMiddleware({user}, undefined, () => {
|
||
|
user.get('last_seen').should.equal(lastSeen);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('Sets the last seen when the user last seen over 1 hour ago', function (done) {
|
||
|
const lastSeen = Date.now() - 61 * 60 * 1000;
|
||
|
const user = new UserMock({
|
||
|
last_seen: lastSeen
|
||
|
});
|
||
|
|
||
|
updateUserLastSeenMiddleware({user}, undefined, () => {
|
||
|
user.get('last_seen').should.not.equal(lastSeen);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|