Ghost/core/test/unit/models/invite_spec.js
Katharina Irrgang 835fd6c45b
Removed knex mock (#9685)
no issue

- this mock eat already too much of my/our time
- the idea of adding a knex mock was definitely a failed approach/try
- it's too much to maintaince and have not found a module which does this already
  - we have to support any query format
  - this is too crazy
- the idea was to use the knex mock for model unit tests, because if we want to unit test models we have to
  run through bookshelf, because the whole model layer depends on bookshelf e.g. events
- for now we simply use the real database
  - we could use the sqlite3 memory mode, but that would mean every unit test runs on sqlite3
  - something to consider for later e.g. run unit tests on one matrix
  - run the rest on another matrix for sqlite + mysql
2018-06-12 20:26:16 +02:00

72 lines
2.6 KiB
JavaScript

const should = require('should'),
sinon = require('sinon'),
common = require('../../../server/lib/common'),
models = require('../../../server/models'),
settingsCache = require('../../../server/services/settings/cache'),
testUtils = require('../../utils'),
sandbox = sinon.sandbox.create();
describe('Unit: models/invite', function () {
before(function () {
models.init();
sandbox.stub(settingsCache, 'get').withArgs('db_hash').returns('12345678');
});
after(function () {
sandbox.restore();
});
before(testUtils.teardown);
describe('add', function () {
beforeEach(testUtils.setup('roles'));
afterEach(testUtils.teardown);
it('default', function () {
return models.Invite.add({email: 'invited@test.org', role_id: testUtils.DataGenerator.forKnex.roles[1].id})
.then(function (invite) {
invite.get('status').should.eql('pending');
invite.get('email').should.eql('invited@test.org');
should.exist(invite.get('token'));
should.exist(invite.get('expires'));
});
});
it('set status with none internal context', function () {
return models.Invite.add({
email: 'invited@test.org',
role_id: testUtils.DataGenerator.forKnex.roles[1].id,
status: 'sent'
}).then(function (invite) {
invite.get('status').should.eql('pending');
invite.get('email').should.eql('invited@test.org');
should.exist(invite.get('token'));
should.exist(invite.get('expires'));
});
});
it('set status with internal context', function () {
return models.Invite.add({
email: 'invited@test.org',
role_id: testUtils.DataGenerator.forKnex.roles[1].id,
status: 'sent'
}, testUtils.context.internal).then(function (invite) {
invite.get('status').should.eql('sent');
invite.get('email').should.eql('invited@test.org');
should.exist(invite.get('token'));
should.exist(invite.get('expires'));
});
});
it('[error] no role passed', function () {
return models.Invite.add({email: 'invited@test.org'})
.then(function () {
'Should fail'.should.be.true();
})
.catch(function (err) {
(err[0] instanceof common.errors.ValidationError).should.be.true();
});
});
});
});