Browse Source

[resources] Add db and request resource

master
Muthu Kumar 6 years ago
parent
commit
fa0db8ba69
  1. 19
      lib/resources/db.js
  2. 7
      lib/resources/index.js
  3. 12
      lib/resources/request.js

19
lib/resources/db.js

@ -0,0 +1,19 @@
const Mongoose = require("mongoose");
module.exports = context => {
const mongoose = new Mongoose.Mongoose();
mongoose.connect(
context.connectionString,
{ useNewUrlParser: true }
);
const db = context.collections.reduce((dbObj, coll) => {
dbObj[coll] = mongoose.model(coll,
new mongoose.Schema({}, { strict: false }));
return dbObj;
}, {});
db.__mongoose__ = mongoose;
return db;
};

7
lib/resources/index.js

@ -0,0 +1,7 @@
const request = require('./request');
const db = require('./db');
module.exports = {
request,
db,
};

12
lib/resources/request.js

@ -0,0 +1,12 @@
module.exports = context => {
const chai = require('chai');
const chaiHttp = require('chai-http');
chai.use(chaiHttp);
const agent = (
chai.request
.agent(context.baseUrl)
);
return agent;
};
Loading…
Cancel
Save