Skip to content

Commit

Permalink
fix: Add tests for ensuring that closures include specified variables…
Browse files Browse the repository at this point in the history
… on hook callbacks
  • Loading branch information
bdfoster committed Nov 21, 2017
1 parent cb3a3c6 commit 0389925
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test/Container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import accounts from './fixtures/data/accounts';
import Query from '../src/Query';
import {inspect} from 'util';
import {Record} from '../src/Record';
import Mapper from '../src/Mapper';

describe('Container', () => {
const config = require('./fixtures/config/' + process.env.NODE_ENV + '.json')['arangodb'];
Expand Down Expand Up @@ -38,33 +39,40 @@ describe('Container', () => {
});
},
afterInsert(mapper, record) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(record).to.be.an.instanceOf(Record);
},
afterUpdate(mapper, record) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(record).to.be.an.instanceOf(Record);
},
afterValidate(mapper, record, operation) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(record).to.be.an.instanceOf(Record);
expect(operation).to.be.a('string');
},
beforeGet(mapper, id) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(id).to.be.a('string');
},
beforeInsert(mapper, record) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(record).to.be.an.instanceOf(Record);
record.createdAt = new Date();
},
beforeUpdate(mapper, record) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(record).to.be.an.instanceOf(Record);
record.updatedAt = new Date();
},
beforeValidate(mapper, record, operation) {
expect(this).to.equal(instance);
expect(mapper).to.be.a('string');
expect(record).to.be.an.instanceOf(Record);
expect(operation).to.be.a('string');
Expand All @@ -79,7 +87,41 @@ describe('Container', () => {
mapper: 'people'
}
}
}
},
afterGet(record) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
},
afterInsert(record) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
},
afterUpdate(record) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
},
afterValidate(record, operation) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
expect(operation).to.be.a('string');
},
beforeGet(id) {
expect(this).to.be.an.instanceOf(Mapper);
expect(id).to.be.a('string');
},
beforeInsert(record) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
},
beforeUpdate(record) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
},
beforeValidate(record, operation) {
expect(this).to.be.an.instanceOf(Mapper);
expect(record).to.be.an.instanceOf(Record);
expect(operation).to.be.a('string');
},
},
people: {
virtuals: {
Expand Down

0 comments on commit 0389925

Please sign in to comment.