mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
9e96b04542
- this is a small part of a bit of cleanup of our test files - the goal is to make the existing tests clearer with a view to making it easier to write more tests - this makes the test structure follow the codebase structure more closely - eventually we will colocate the tests as we break the codebase down further
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
const models = require('../../../../core/server/models');
|
|
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
let clock;
|
|
let sandbox;
|
|
|
|
describe('Unit: models/single-use-token', function () {
|
|
before(function () {
|
|
models.init();
|
|
sandbox = sinon.createSandbox();
|
|
clock = sandbox.useFakeTimers();
|
|
});
|
|
|
|
after(function () {
|
|
clock.restore();
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('fn: findOne', function () {
|
|
it('Calls destroy after the grace period', async function () {
|
|
const data = {};
|
|
const options = {};
|
|
const fakeModel = {
|
|
id: 'fake_id'
|
|
};
|
|
|
|
const findOneSuperStub = sandbox.stub(models.Base.Model, 'findOne').resolves(fakeModel);
|
|
const destroyStub = sandbox.stub(models.SingleUseToken, 'destroy').resolves();
|
|
|
|
await models.SingleUseToken.findOne(data, options);
|
|
|
|
should.ok(findOneSuperStub.calledWith(data, options), 'super.findOne was called');
|
|
|
|
clock.tick(10000);
|
|
|
|
should.ok(destroyStub.called, 'destroy was called after 10 seconds');
|
|
});
|
|
});
|
|
});
|