mirror of
https://github.com/Permissionless-Software-Foundation/bch-email-api.git
synced 2026-09-21 16:52:04 -07:00
getting data from postgres successfully
This commit is contained in:
+10
-8
@@ -54,15 +54,17 @@ async function startServer () {
|
|||||||
await app.listen(config.port)
|
await app.listen(config.port)
|
||||||
console.log(`Server started on ${config.port}`)
|
console.log(`Server started on ${config.port}`)
|
||||||
|
|
||||||
try {
|
if (process.env.TEST_ENV !== 'unit') {
|
||||||
const iRedMail = new IRedMail()
|
try {
|
||||||
await iRedMail.sequelize.authenticate()
|
const iRedMail = new IRedMail()
|
||||||
console.log('Connection to the iRedMail postgres database has been established successfully.')
|
await iRedMail.sequelize.authenticate()
|
||||||
|
console.log('Connection to the iRedMail postgres database has been established successfully.')
|
||||||
|
|
||||||
// Attach to iRedMail instantiation to the context object.
|
// Attach to iRedMail instantiation to the context object.
|
||||||
app.context.iRedMail = iRedMail
|
app.context.iRedMail = iRedMail
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`Could not connect to iRedMail instance.`)
|
console.log(`Could not connect to iRedMail instance.`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"test": "APP_ENV=test TEST_ENV=unit nyc --reporter=text ./node_modules/.bin/mocha --exit",
|
"test": "APP_ENV=test TEST_ENV=unit nyc --reporter=text ./node_modules/.bin/mocha --exit",
|
||||||
"test:integration": "APP_ENV=test TEST_ENV=integration nyc --reporter=text ./node_modules/.bin/mocha --exit",
|
"test:integration": "APP_ENV=test TEST_ENV=integration nyc --reporter=text ./node_modules/.bin/mocha --timeout 15000 --exit",
|
||||||
"lint": "eslint src/**/*.js",
|
"lint": "eslint src/**/*.js",
|
||||||
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
|
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
|
||||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
// const User = require('../../models/users')
|
// const User = require('../../models/users')
|
||||||
|
|
||||||
|
const util = require('util')
|
||||||
|
util.inspect.defaultOptions = { depth: 1 }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Create a new user by manipulating the postgres database.
|
Create a new user by manipulating the postgres database.
|
||||||
*/
|
*/
|
||||||
async function createUser (ctx) {
|
async function createUser (ctx) {
|
||||||
try {
|
try {
|
||||||
// Sync the model.
|
// console.log(`ctx.iRedMail: ${util.inspect(ctx.iRedMail)}`)
|
||||||
await ctx.iRedMail.models.usedQuota.sync()
|
|
||||||
|
|
||||||
|
// Sync the model.
|
||||||
|
const model = await ctx.iRedMail.models.usedQuota.sync()
|
||||||
|
|
||||||
|
const data = await model.findAll()
|
||||||
|
/*
|
||||||
// Get all the models in the database:
|
// Get all the models in the database:
|
||||||
const models = await ctx.iRedMail.usedQuota.findAll()
|
const models = await ctx.iRedMail.usedQuota.findAll()
|
||||||
|
|
||||||
console.log(`data: ${JSON.stringify(models, null, 2)}`)
|
console.log(`data: ${JSON.stringify(models, null, 2)}`)
|
||||||
ctx.body = { models }
|
ctx.body = { models }
|
||||||
|
*/
|
||||||
|
ctx.body = data
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`Error in iredmail.createUser(): `, err)
|
console.log(`Error in iredmail.createUser(): `, err)
|
||||||
ctx.throw(500, err.message)
|
ctx.throw(500, err.message)
|
||||||
|
|||||||
+22
-21
@@ -22,31 +22,32 @@ describe('#iRedMail', () => {
|
|||||||
if (process.env.TEST_ENV === 'integration') {
|
if (process.env.TEST_ENV === 'integration') {
|
||||||
testType = 'integration'
|
testType = 'integration'
|
||||||
|
|
||||||
iRedMail = new IRedMail()
|
// iRedMail = new IRedMail()
|
||||||
await iRedMail.sequelize.authenticate()
|
// await iRedMail.sequelize.authenticate()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#createUser', () => {
|
describe('#createUser', () => {
|
||||||
it('should get database models', async () => {
|
if (process.env.TEST_ENV === 'integration') {
|
||||||
try {
|
it('should get database models', async () => {
|
||||||
console.log(`Hello world!`)
|
try {
|
||||||
/*
|
// console.log(`Hello world!`)
|
||||||
const options = {
|
|
||||||
method: 'POST',
|
|
||||||
uri: `${LOCALHOST}/iredmail/adduser`,
|
|
||||||
resolveWithFullResponse: true,
|
|
||||||
json: true,
|
|
||||||
body: {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = await rp(options)
|
const options = {
|
||||||
console.log(`result: ${util.inspect(result)}`)
|
method: 'POST',
|
||||||
*/
|
uri: `${LOCALHOST}/iredmail/adduser`,
|
||||||
} catch (err) {
|
resolveWithFullResponse: true,
|
||||||
console.log(`Error in #createUser test: `, err)
|
json: true,
|
||||||
}
|
body: {
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = await rp(options)
|
||||||
|
console.log(`result: ${util.inspect(result.body)}`)
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`Error in #createUser test: `, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user