Skip to content

Commit

Permalink
chore(test): implement to es
Browse files Browse the repository at this point in the history
  • Loading branch information
rijkerd committed Jun 30, 2019
1 parent 6c18f72 commit 30a693e
Show file tree
Hide file tree
Showing 16 changed files with 1,054 additions and 1,640 deletions.
14 changes: 2 additions & 12 deletions test/bootstrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
'use strict';
import '@lykmapipo/mongoose-test-helpers';

//force environment to be test
/* set environment variables */
process.env.NODE_ENV = 'test';
process.env.DEFAULT_LOCALE = 'en';

//setup mongoose
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;

//setup
require('chai').use(require('sinon-chai'));
require('sinon');
require('sinon-mongoose');
33 changes: 5 additions & 28 deletions test/integration/account.boostrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
'use strict';


process.env.NODE_ENV = 'test';


/* dependencies */
const mongoose = require('mongoose');
const MONGODB_URI = 'mongodb://localhost/majifix-account';


/* clean and restore database */
const wipe = (done) => {
if (mongoose.connection && mongoose.connection.dropDatabase) {
mongoose.connection.dropDatabase(done);
} else {
done();
}
};

import { clear, connect, drop } from '@lykmapipo/mongoose-test-helpers';

/* setup database */
before((done) => {
const options = { useNewUrlParser: true };
mongoose.connect(MONGODB_URI, options, done);
});

before(done => connect(done));

/* clear database */
before(wipe);
before(done => clear(done));


/* clear database */
after(wipe);
/* drop database */
after(done => drop(done));
126 changes: 53 additions & 73 deletions test/integration/account.delete.spec.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,69 @@
'use strict';

/* dependencies */
const path = require('path');
const { expect } = require('chai');
const { Account } = require(path.join(__dirname, '..', '..'));

describe('Account', function () {

before(function (done) {
Account.deleteMany(done);
});

describe('static delete', function () {

let account;

before(function (done) {
const fake = Account.fake();
fake
.post(function (error, created) {
account = created;
done(error, created);
});
import { expect } from 'chai';
import { clear } from '@lykmapipo/mongoose-test-helpers';
import account from '../../src/index';

const { Account } = account;

describe('Account', () => {
let customerAccount;
before(done => clear(Account, done));
describe('static delete', () => {
before(done => {
customerAccount = Account.fake();
customerAccount.post((error, created) => {
customerAccount = created;
done(error, created);
});
});

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

it('should throw if not exists', function (done) {
Account
.del(account._id, function (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 => {
Account.del(customerAccount._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', function () {

let account;

before(function (done) {
const fake = Account.fake();
fake
.post(function (error, created) {
account = created;
done(error, created);
});
describe('instance delete', () => {
before(done => {
customerAccount = Account.fake();
customerAccount.post((error, created) => {
customerAccount = created;
done(error, created);
});
});

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

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

});

after(function (done) {
Account.deleteMany(done);
});

after(done => clear(Account, done));
});
Loading

0 comments on commit 30a693e

Please sign in to comment.