You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
/* eslint-env mocha */
|
|
const mongoClient = require('mongodb').MongoClient
|
|
|
|
const CFG = require('../../config')
|
|
const CTX = {
|
|
db: {}
|
|
}
|
|
const services = require('./services')(CTX)
|
|
|
|
const req = {}
|
|
const res = {
|
|
_done: function () {
|
|
console.error('Mocha done function not set')
|
|
process.exit(1)
|
|
},
|
|
setDone: function (done) {
|
|
this._done = done
|
|
},
|
|
done: function (status, err, json) {
|
|
typeof status === 'number'
|
|
? this._done(status, err, json)
|
|
: this._done(555, status, err)
|
|
}
|
|
}
|
|
|
|
describe('Session - Services', function () {
|
|
// LOGIN ////////////////////////////////////////////////////////////////////
|
|
describe('#login', function () {
|
|
before(function (done) {
|
|
mongoClient.connect(CFG.mongo.url, { useNewUrlParser: true }, function (pErr, pDbHandler) {
|
|
if (pErr) {
|
|
process.exit(1)
|
|
}
|
|
CTX.db.handler = pDbHandler
|
|
CTX.db.airpmp = CTX.db.handler.db('airpmp')
|
|
done()
|
|
})
|
|
})
|
|
|
|
// it('should login with success', function (done) {
|
|
// req.body = {
|
|
// user: 'airpmp',
|
|
// pass: 'admin'
|
|
// }
|
|
// res.setDone(function (pStatus, pErr, pResult) {
|
|
// if (pErr) return done(pErr)
|
|
// if (pResult.user.username !== req.body.user) return done(new Error('CorruptedUser'))
|
|
// done()
|
|
// })
|
|
// services.login(req, res)
|
|
// })
|
|
|
|
// it('should not login with wrong credential', function (done) {
|
|
// req.body = {
|
|
// user: 'test',
|
|
// pass: 'adminz'
|
|
// }
|
|
// res.setDone(function (pStatus, pErr, pResult) {
|
|
// if (pErr) return done()
|
|
// done(new Error('LoggedWithWrongCreditential'))
|
|
// })
|
|
// services.login(req, res)
|
|
// })
|
|
|
|
after(function (done) {
|
|
CTX.db.handler.close()
|
|
done()
|
|
})
|
|
})
|
|
})
|