Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial tooling to support test for routes
- Loading branch information
Showing
12 changed files
with
162 additions
and
9 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
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
env: { | ||
mocha: true, | ||
}, | ||
}; |
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
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
|
||
const httpUtils = require('../../testHttpUtils'); | ||
const testMongoUtils = require('../../testMongoUtils'); | ||
const asPromise = require('../../testUtils').asPromise; | ||
|
||
describe('Routers index', () => { | ||
let request; | ||
let close; | ||
let db; | ||
before(() => { | ||
const server = httpUtils.createServer(); | ||
request = server.request; | ||
close = server.close; | ||
return testMongoUtils.initializeDb() | ||
.then((newDb) => { | ||
db = newDb; | ||
}); | ||
}); | ||
|
||
it('GET / should return html', () => | ||
asPromise(cb => request.get('/').expect(200).end(cb)) | ||
.then((res) => { | ||
expect(res.text).to.match(/<h4 style="font-weight: bold;">Databases<\/h4>/); | ||
expect(res.text).to.match(new RegExp('<a href="/db/mongo-express-test-db/">mongo-express-test-db</a></h3>')); | ||
}) | ||
); | ||
|
||
after(() => Promise.all([ | ||
testMongoUtils.cleanAndCloseDb(db), | ||
close(), | ||
])); | ||
}); | ||
|
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 +1,2 @@ | ||
--recursive | ||
--reporter dot |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const mongoConfig = require('./testMongoConfig'); | ||
|
||
module.exports = () => ({ | ||
mongodb: { | ||
server: mongoConfig.host, | ||
port: mongoConfig.port, | ||
|
||
autoReconnect: true, | ||
poolSize: 4, | ||
admin: true, | ||
auth: [], | ||
|
||
adminUsername: '', | ||
adminPassword: '', | ||
whitelist: [mongoConfig.dbName], | ||
blacklist: [], | ||
}, | ||
|
||
site: { | ||
host: 'localhost', | ||
port: 3000, | ||
cookieSecret: 'cookiesecret', | ||
sessionSecret: 'sessionsecret', | ||
cookieKeyName: 'mongo-express', | ||
sslEnabled: false, | ||
sslCert: '', | ||
sslKey: '', | ||
}, | ||
|
||
useBasicAuth: false, | ||
|
||
options: { | ||
documentsPerPage: 10, | ||
editorTheme: 'rubyblue', | ||
|
||
logger: { skip: () => true }, | ||
readOnly: false, | ||
}, | ||
|
||
defaultKeyNames: {}, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
const supertest = require('supertest'); | ||
|
||
const defaultConf = require('./testDefaultConfig'); | ||
const asPromise = require('./testUtils').asPromise; | ||
const middleware = require('../lib/middleware'); | ||
|
||
exports.createServer = () => { | ||
const app = middleware(defaultConf()); | ||
const httpServer = app.listen(); | ||
const request = supertest.agent(httpServer); | ||
return { request, close: () => asPromise(cb => httpServer.close(cb)) }; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
host: 'localhost', | ||
port: 27017, | ||
dbName: 'mongo-express-test-db', | ||
makeConnectionUrl: () => { | ||
const m = module.exports; | ||
return `mongodb://${m.host}:${m.port}/${m.dbName}`; | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const MongoClient = require('mongodb').MongoClient; | ||
|
||
const mongoConfig = require('./testMongoConfig'); | ||
const asPromise = require('./testUtils').asPromise; | ||
|
||
exports.testData = [ | ||
{ testItem: 1 }, | ||
{ testItem: 2 }, | ||
{ testItem: 3 }, | ||
{ testItem: 4 }, | ||
]; | ||
exports.testCollectionName = 'test/items'; | ||
|
||
exports.createConnection = () => | ||
asPromise(cb => MongoClient.connect(mongoConfig.makeConnectionUrl(), cb)); | ||
|
||
exports.createTestCollection = db => | ||
asPromise(cb => db.collection(exports.testCollectionName).insertMany(exports.testData, cb)); | ||
|
||
exports.dropTestCollection = db => | ||
asPromise(cb => db.collection(exports.testCollectionName).drop(cb)); | ||
|
||
exports.closeDb = db => | ||
asPromise(cb => db.close(cb)); | ||
|
||
exports.initializeDb = () => | ||
exports.createConnection().then(db => | ||
exports.createTestCollection(db).then(() => db) | ||
); | ||
|
||
exports.cleanAndCloseDb = db => | ||
exports.dropTestCollection(db).then(() => exports.closeDb(db)); |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
exports.asPromise = function asPromise(fct) { | ||
return new Promise((resolve, reject) => | ||
fct((err, result) => { | ||
if (err) reject(err); | ||
else resolve(result); | ||
}) | ||
); | ||
}; |