Ghost/test/regression/models/model_single_use_token_spec.js
Fabien 'egg' O'Carroll 812e4b682f
Added SingleUseToken model (#12215)
no-issue

This is a model for the tokens table, which handles the single use
aspect by customising the `findOne` method to automatically destroy the
model after reading from it
2020-09-18 15:05:56 +01:00

31 lines
910 B
JavaScript

const models = require('../../../core/server/models');
const should = require('should');
describe('Regression: models/single-use-token', function () {
before(function () {
models.init();
});
describe('findOne', function () {
it('Does not allow the same token to be read twice', async function () {
const insertedToken = await models.SingleUseToken.add({
data: 'some_data'
}, {});
const tokenFirstRead = await models.SingleUseToken.findOne({
token: insertedToken.get('token')
});
should.exist(tokenFirstRead);
should.equal(tokenFirstRead.id, insertedToken.id);
const tokenSecondRead = await models.SingleUseToken.findOne({
token: insertedToken.get('token')
});
should.not.exist(tokenSecondRead);
});
});
});