mirror of
https://github.com/Permissionless-Software-Foundation/bch-email-api.git
synced 2026-09-21 16:52:04 -07:00
ported test code into boilerplate
This commit is contained in:
@@ -8,6 +8,7 @@ const passport = require('koa-passport')
|
||||
const mount = require('koa-mount')
|
||||
const serve = require('koa-static')
|
||||
const cors = require('kcors')
|
||||
const Sequelize = require('sequelize')
|
||||
|
||||
const config = require('../config')
|
||||
const errorMiddleware = require('../src/middleware')
|
||||
@@ -52,10 +53,56 @@ async function startServer () {
|
||||
await app.listen(config.port)
|
||||
console.log(`Server started on ${config.port}`)
|
||||
|
||||
runTest()
|
||||
|
||||
return app
|
||||
}
|
||||
// startServer()
|
||||
|
||||
async function runTest () {
|
||||
try {
|
||||
const sequelize = new Sequelize('vmail', 'postgres', 'postgres', {
|
||||
host: 'box.bchtest.net',
|
||||
dialect: 'postgres',
|
||||
|
||||
pool: {
|
||||
max: 5,
|
||||
min: 0,
|
||||
acquire: 30000,
|
||||
idle: 10000
|
||||
},
|
||||
|
||||
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
|
||||
operatorsAliases: false
|
||||
})
|
||||
|
||||
const UsedQuota = sequelize.define(
|
||||
'used_quota',
|
||||
{
|
||||
username: { type: Sequelize.STRING, primaryKey: true },
|
||||
bytes: Sequelize.BIGINT,
|
||||
messages: Sequelize.BIGINT,
|
||||
domain: Sequelize.STRING
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
}
|
||||
)
|
||||
|
||||
await sequelize.authenticate()
|
||||
|
||||
console.log('Connection has been established successfully.')
|
||||
|
||||
await UsedQuota.sync()
|
||||
|
||||
const data = await UsedQuota.findAll()
|
||||
|
||||
console.log(`data: ${JSON.stringify(data, null, 2)}`)
|
||||
} catch (err) {
|
||||
console.log(`Error: `, err)
|
||||
}
|
||||
}
|
||||
|
||||
// export default app
|
||||
// module.exports = app
|
||||
module.exports = {
|
||||
|
||||
+3
-1
@@ -46,8 +46,10 @@
|
||||
"koa-static": "^5.0.0",
|
||||
"mongoose": "^5.0.8",
|
||||
"passport-local": "^1.0.0",
|
||||
"pg": "^7.8.0",
|
||||
"request": "^2.85.0",
|
||||
"request-promise": "^4.2.2"
|
||||
"request-promise": "^4.2.2",
|
||||
"sequelize": "^4.42.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.1.2",
|
||||
|
||||
Reference in New Issue
Block a user