-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,054 additions
and
1,640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); |
Oops, something went wrong.