Ghost/test/unit/server/models/single-use-token.test.js
Hannah Wolfe 9e96b04542
Moved server unit tests into the server folder
- 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
2021-10-06 12:01:09 +01:00

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');
});
});
});