Skip to content

Commit

Permalink
test: add mongoose test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Aug 13, 2019
1 parent f6f62d2 commit 6675f8e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
@@ -1,6 +1,8 @@
language: node_js
node_js:
- '12.4.0'
services:
- mongodb
script:
- commitlint-travis
- npm test
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -63,6 +63,7 @@
"@commitlint/cli": "^8.1.0",
"@commitlint/config-conventional": "^8.1.0",
"@commitlint/travis-cli": "^8.1.0",
"@lykmapipo/mongoose-test-helpers": "^0.7.17",
"@lykmapipo/test-helpers": "^0.3.2",
"chai": "^4.2.0",
"commitizen": "^4.0.3",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -150,6 +150,8 @@ export const unlocalize = (path, data) => {
* @param {object} parent valid mongoose model instance
* @param {object} optns valid options
* @param {string} optns.path parent path on dependant
* @param {boolean} [optns.self=false] whether to check self existence,
* for hierarchical models
* @param {string[]} optns.dependencies model name of the dependants
* @param {Function} done a callback to invoke on success or failure
* @returns {Function} dependencies cleaner
Expand All @@ -167,7 +169,7 @@ export const unlocalize = (path, data) => {
*/
export const checkDependencyFor = (parent, optns, done) => {
// ensure options
const options = mergeObjects(optns);
const options = mergeObjects({ self: false }, optns);

// obtain path
const { path, dependencies } = options;
Expand Down
11 changes: 10 additions & 1 deletion test/bootstrap.spec.js
@@ -1 +1,10 @@
import '@lykmapipo/test-helpers';
import { connect, clear, drop } from '@lykmapipo/mongoose-test-helpers';

/* setup database */
before(done => connect(done));

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

/* drop database */
after(done => drop(done));
6 changes: 5 additions & 1 deletion test/index.spec.js
@@ -1,4 +1,4 @@
import { expect } from '@lykmapipo/test-helpers';
import { expect, clear } from '@lykmapipo/mongoose-test-helpers';
import {
// models
MODEL_NAME_ACCOUNT,
Expand Down Expand Up @@ -58,6 +58,8 @@ import {
} from '../src';

describe('majifix common', () => {
before(done => clear(done));

it('should expose models name', () => {
expect(MODEL_NAME_ACCOUNT).to.be.equal('Account');
expect(MODEL_NAME_CONTENT).to.be.equal('Content');
Expand Down Expand Up @@ -139,4 +141,6 @@ describe('majifix common', () => {
done(error);
});
});

after(done => clear(done));
});

0 comments on commit 6675f8e

Please sign in to comment.