2020-03-30 18:26:47 +03:00
|
|
|
const models = require('../../../core/server/models');
|
2018-10-02 19:46:38 +03:00
|
|
|
const should = require('should');
|
2018-10-05 11:51:13 +03:00
|
|
|
const sinon = require('sinon');
|
2018-10-02 19:46:38 +03:00
|
|
|
const testUtils = require('../../utils');
|
|
|
|
|
|
|
|
describe('Unit: models/api_key', function () {
|
|
|
|
before(models.init);
|
|
|
|
|
2019-01-22 15:36:30 +03:00
|
|
|
describe('fn: refreshSecret', function () {
|
2019-01-24 16:46:33 +03:00
|
|
|
it('returns a call to edit passing a new admin secret', function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
const editStub = sinon.stub(models.ApiKey, 'edit').resolves();
|
2018-10-05 11:51:13 +03:00
|
|
|
|
|
|
|
const fakeData = {
|
2019-01-24 16:46:33 +03:00
|
|
|
id: 'TREVOR',
|
|
|
|
type: 'admin'
|
2018-10-05 11:51:13 +03:00
|
|
|
};
|
|
|
|
const fakeOptions = {};
|
|
|
|
|
|
|
|
const result = models.ApiKey.refreshSecret(fakeData, fakeOptions);
|
|
|
|
|
|
|
|
should.equal(result, editStub.returnValues[0]);
|
|
|
|
should.equal(editStub.args[0][0].id, 'TREVOR');
|
2019-01-24 16:46:33 +03:00
|
|
|
should.equal(editStub.args[0][0].secret.length, 64);
|
|
|
|
should.equal(editStub.args[0][1], fakeOptions);
|
|
|
|
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a call to edit passing a new content secret', function () {
|
|
|
|
const editStub = sinon.stub(models.ApiKey, 'edit').resolves();
|
|
|
|
|
|
|
|
const fakeData = {
|
|
|
|
id: 'TREVOR',
|
|
|
|
type: 'content'
|
|
|
|
};
|
|
|
|
const fakeOptions = {};
|
|
|
|
|
|
|
|
const result = models.ApiKey.refreshSecret(fakeData, fakeOptions);
|
|
|
|
|
|
|
|
should.equal(result, editStub.returnValues[0]);
|
|
|
|
should.equal(editStub.args[0][0].id, 'TREVOR');
|
|
|
|
should.equal(editStub.args[0][0].secret.length, 26);
|
2018-10-05 11:51:13 +03:00
|
|
|
should.equal(editStub.args[0][1], fakeOptions);
|
|
|
|
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2018-10-05 11:51:13 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-02 19:46:38 +03:00
|
|
|
});
|