mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-07 03:22:21 +03:00
812e4b682f
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
31 lines
910 B
JavaScript
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);
|
|
});
|
|
});
|
|
});
|
|
|