Skip to content

Commit

Permalink
Merge ccdd1e9 into 1b42f6f
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkerd committed Sep 23, 2019
2 parents 1b42f6f + ccdd1e9 commit 6329cef
Show file tree
Hide file tree
Showing 9 changed files with 583 additions and 559 deletions.
111 changes: 59 additions & 52 deletions test/integration/alert.delete.spec.js
Expand Up @@ -2,77 +2,84 @@ import { Jurisdiction } from '@codetanzania/majifix-jurisdiction';
import { clear, create, expect } from '@lykmapipo/mongoose-test-helpers';
import { Alert } from '../../src/index';

describe('Alert', () => {
describe('Alert static delete', () => {
const jurisdiction = Jurisdiction.fake();

before(done => clear(Alert, Jurisdiction, done));

before(done => create(jurisdiction, done));
describe('static delete', () => {
let alert;

before(done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);
alert.post((error, created) => {
alert = created;
done(error, created);
});

let alert;

before(done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);
alert.post((error, created) => {
alert = created;
done(error, created);
});
});

it('should be able to delete', done => {
Alert.del(alert._id, (error, deleted) => {
expect(error).to.not.exist;
expect(deleted).to.exist;
expect(deleted._id).to.eql(alert._id);
it('should be able to delete', done => {
Alert.del(alert._id, (error, deleted) => {
expect(error).to.not.exist;
expect(deleted).to.exist;
expect(deleted._id).to.eql(alert._id);

// assert jurisdictions
expect(deleted.jurisdictions).to.exist;
done(error, deleted);
});
// assert jurisdictions
expect(deleted.jurisdictions).to.exist;
done(error, deleted);
});
});

it('should throw if not exists', done => {
Alert.del(alert._id, (error, deleted) => {
expect(error).to.exist;
// expect(error.status).to.exist;
expect(error.name).to.be.equal('DocumentNotFoundError');
expect(deleted).to.not.exist;
done();
});
it('should throw if not exists', done => {
Alert.del(alert._id, (error, deleted) => {
expect(error).to.exist;
// expect(error.status).to.exist;
expect(error.name).to.be.equal('DocumentNotFoundError');
expect(deleted).to.not.exist;
done();
});
});

describe('instance delete', () => {
let alert;
after(done => clear('Alert', 'Jurisdiction', done));
});

describe('Alert instance delete', () => {
const jurisdiction = Jurisdiction.fake();

before(done => clear(Alert, Jurisdiction, done));

before(done => create(jurisdiction, done));

let alert;

before(done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);
alert.post((error, created) => {
alert = created;
done(error, created);
});
before(done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);
alert.post((error, created) => {
alert = created;
done(error, created);
});
});

it('should be able to delete', done => {
alert.del((error, deleted) => {
expect(error).to.not.exist;
expect(deleted).to.exist;
expect(deleted._id).to.eql(alert._id);
done(error, deleted);
});
it('should be able to delete', done => {
alert.del((error, deleted) => {
expect(error).to.not.exist;
expect(deleted).to.exist;
expect(deleted._id).to.eql(alert._id);
done(error, deleted);
});
});

it('should throw if not exists', done => {
alert.del((error, deleted) => {
expect(error).to.not.exist;
expect(deleted).to.exist;
expect(deleted._id).to.eql(alert._id);
done();
});
it('should throw if not exists', done => {
alert.del((error, deleted) => {
expect(error).to.not.exist;
expect(deleted).to.exist;
expect(deleted._id).to.eql(alert._id);
done();
});
});

after(done => clear('Alert', 'Jurisdiction', done));
after(done => clear(Alert, Jurisdiction, done));
});
100 changes: 46 additions & 54 deletions test/integration/alert.getById.spec.js
Expand Up @@ -3,79 +3,71 @@ import { Jurisdiction } from '@codetanzania/majifix-jurisdiction';
import { clear, create, expect } from '@lykmapipo/mongoose-test-helpers';
import { Alert } from '../../src/index';

describe('Alert', () => {
describe('Alert get by id', () => {
const jurisdiction = Jurisdiction.fake();

before(done => clear(Alert, Jurisdiction, done));

before(done => create(jurisdiction, done));

describe('get by id', () => {
let alert;
let alert;

before(done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);
alert.post((error, created) => {
alert = created;
done(error, created);
});
before(done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);
alert.post((error, created) => {
alert = created;
done(error, created);
});
});

it('should be able to get an instance', done => {
Alert.getById(alert._id, (error, found) => {
expect(error).to.not.exist;
expect(found).to.exist;
expect(found._id).to.eql(alert._id);
it('should be able to get an instance', done => {
Alert.getById(alert._id, (error, found) => {
expect(error).to.not.exist;
expect(found).to.exist;
expect(found._id).to.eql(alert._id);

// assert jurisdiction
expect(found.jurisdictions).to.exist;
done(error, found);
});
// assert jurisdiction
expect(found.jurisdictions).to.exist;
done(error, found);
});
});

it('should be able to get with options', done => {
const options = {
_id: alert._id,
select: 'subject',
};

Alert.getById(options, (error, found) => {
expect(error).to.not.exist;
expect(found).to.exist;
expect(found._id).to.eql(alert._id);
expect(found.subject).to.exist;
it('should be able to get with options', done => {
const options = {
_id: alert._id,
select: 'subject',
};

// ...assert selection
const fields = _.keys(found.toObject());
expect(fields).to.have.length(3);
_.map(['message'], field => {
expect(fields).to.not.include(field);
});
Alert.getById(options, (error, found) => {
expect(error).to.not.exist;
expect(found).to.exist;
expect(found._id).to.eql(alert._id);
expect(found.subject).to.exist;

done(error, found);
// ...assert selection
const fields = _.keys(found.toObject());
expect(fields).to.have.length(3);
_.map(['message'], field => {
expect(fields).to.not.include(field);
});
});

it('should throw if not exists', done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);

Alert.getById(alert._id, (error, found) => {
expect(error).to.exist;
// expect(error.status).to.exist;
expect(error.name).to.be.equal('DocumentNotFoundError');
expect(found).to.not.exist;
done();
});
done(error, found);
});
});

after(done => {
Alert.deleteMany(done);
});
it('should throw if not exists', done => {
alert = Alert.fake();
alert.jurisdictions = [].concat(jurisdiction);

after(done => {
Jurisdiction.deleteMany(done);
Alert.getById(alert._id, (error, found) => {
expect(error).to.exist;
// expect(error.status).to.exist;
expect(error.name).to.be.equal('DocumentNotFoundError');
expect(found).to.not.exist;
done();
});
});

after(done => clear(Alert, Jurisdiction, done));
});

0 comments on commit 6329cef

Please sign in to comment.