Skip to content

Commit 1a0e4cd

Browse files
committed
Make database cleansing reliable
+ fix duplicate error + fix destroyed topology error
1 parent d0b6317 commit 1a0e4cd

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

features/env/database.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
const {Before, AfterAll, BeforeAll} = require('cucumber');
22
const mongoose = require('mongoose');
33
const sinon = require('sinon');
4+
const userSchema = require('../../human-connection-api/server/models/users.model.js');
45

5-
let db;
6+
mongoose.connect("mongodb://localhost/hc_api_test");
7+
const db = mongoose.connection;
8+
9+
let app = sinon.stub();
10+
sinon.stub(app, 'get').callsFake(function() {
11+
return mongoose;
12+
});
13+
14+
let User;
15+
db.on('error', console.error.bind(console, 'connection error:'));
16+
db.once('open', function() {
17+
User = userSchema(app); // initialize User model
618

7-
BeforeAll(function (callback) {
8-
mongoose.connect("mongodb://localhost/hc_api_test");
9-
db = mongoose.connection;
10-
db.on('error', console.error.bind(console, 'connection error:'));
11-
db.once('open', function() {
12-
callback();
13-
});
1419
});
1520

1621
// Asynchronous Promise
1722
Before(function () {
18-
db.dropDatabase()
23+
User.remove();
1924
});
2025

2126
AfterAll(function() {

features/env/getModel.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

features/env/models.js

Whitespace-only changes.

features/step_definitions/steps.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const { Given, When, Then } = require('cucumber');
2-
const userSchema = require('../../human-connection-api/server/models/users.model.js');
3-
const getModel = require('../env/getModel.js');
4-
const User = getModel(userSchema);
2+
const mongoose = require('mongoose');
53

64
Given('the Human Connection API is up and running', function () {
75
// Just documentation
@@ -12,9 +10,9 @@ Given("there is a 3rd party application running, e.g. 'Democracy'", function ()
1210
});
1311

1412
Given('there is an organization in Human Connection with these credentials:', function (dataTable) {
15-
// Write code here that turns the phrase above into concrete actions
1613
const table = dataTable.hashes()
1714
dataTable.hashes().forEach((row) => {
15+
const User = mongoose.model('users');
1816
const aUser = new User(row);
1917
aUser.save(function (err, user) {
2018
if(err) throw(err);

0 commit comments

Comments
 (0)