Skip to content

Commit

Permalink
test: use test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Dec 16, 2019
1 parent 79c1f3d commit a13498c
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 86 deletions.
193 changes: 193 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"main": "index.js",
"scripts": {
"test": "grunt test"
"test": "NODE_ENV=test grunt test"
},
"repository": {
"type": "git",
Expand All @@ -42,6 +42,7 @@
],
"devDependencies": {
"@lykmapipo/mongoose-faker": ">=0.10.5",
"@lykmapipo/mongoose-test-helpers": "^0.7.28",
"chai": "^4.2.0",
"grunt": "^1.0.4",
"grunt-contrib-jshint": "^2.1.0",
Expand Down
31 changes: 3 additions & 28 deletions test/boostrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
'use strict';


/* ensure test environment*/
process.env.NODE_ENV = 'test';

const { connect, drop } = require('@lykmapipo/mongoose-test-helpers');

/* dependencies */
const mongoose = require('mongoose');
mongoose.plugin(require('@lykmapipo/mongoose-faker'));


const wipe = (done) => {
if (mongoose.connection && mongoose.connection.dropDatabase) {
mongoose.connection.dropDatabase(done);
} else {
done();
}
};


//setup database
before((done) => {
const database = 'mongodb://localhost/mongoose-geojson-schemas';
mongoose.connect(database, { useNewUrlParser: true }, done);
});


// clear database
before(wipe);

before(done => connect(done));

// clear database
after(wipe);
after(done => drop(done));
14 changes: 5 additions & 9 deletions test/geometrycollection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
/*** dependencies */
const path = require('path');
const _ = require('lodash');
const mongoose = require('mongoose');
const { expect } = require('chai');
const { Schema } = mongoose;
const { createTestModel, expect } = require('@lykmapipo/mongoose-test-helpers');
const {
GeometryCollection,
GEO_2DSPHERE,
Expand All @@ -17,9 +15,6 @@ const {
describe('GeometryCollection', () => {

let GOIC;
const GoiSchema = new Schema({
trash: GeometryCollection
});

it('should be a schema', () => {
//assert shape
Expand All @@ -42,8 +37,9 @@ describe('GeometryCollection', () => {


it('indexes are created when model is compiled', (done) => {

GOIC = mongoose.model('GOIC', GoiSchema);
GOIC = createTestModel({
trash: GeometryCollection
});

GOIC.on('index', () => {
GOIC
Expand All @@ -52,7 +48,7 @@ describe('GeometryCollection', () => {
//assert indexes
expect(error).to.not.exist;
expect(indexes).to.exist;
expect(indexes).to.have.length(2);
expect(indexes).to.have.length.at.least(2);

//assert trash 2dsphere index
const index = (_.find(indexes, { key: { trash: GEO_2DSPHERE } }));
Expand Down
Loading

0 comments on commit a13498c

Please sign in to comment.