mirror of
https://github.com/Permissionless-Software-Foundation/bch-email-api.git
synced 2026-09-21 16:52:04 -07:00
Creating test scaffold
This commit is contained in:
Vendored
+1
-1
@@ -9,5 +9,5 @@ export default {
|
||||
module.exports = {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-dev'
|
||||
database: 'mongodb://localhost:27017/iredmail-dev'
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -9,5 +9,5 @@ export default {
|
||||
module.exports = {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-prod'
|
||||
database: 'mongodb://localhost:27017/iredmail-prod'
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -9,5 +9,5 @@ export default {
|
||||
module.exports = {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-test'
|
||||
database: 'mongodb://localhost:27017/irestmail-test'
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ try {
|
||||
}
|
||||
|
||||
// Default to development environment.
|
||||
const env = process.env.NODE_ENV || 'development'
|
||||
const env = process.env.APP_ENV || 'development'
|
||||
|
||||
// Load the config object for the selected environment.
|
||||
const config = require(`./env/${env}`)
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"test": "NODE_ENV=test 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",
|
||||
"lint": "eslint src/**/*.js",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// const User = require('../../models/users')
|
||||
|
||||
/*
|
||||
Create a new user by manipulating the postgres database.
|
||||
*/
|
||||
async function createUser (ctx) {
|
||||
try {
|
||||
// Sync the model.
|
||||
await ctx.iRedMail.models.usedQuota.sync()
|
||||
|
||||
// Get all the models in the database:
|
||||
const models = await ctx.iRedMail.usedQuota.findAll()
|
||||
|
||||
console.log(`data: ${JSON.stringify(models, null, 2)}`)
|
||||
ctx.body = { models }
|
||||
} catch (err) {
|
||||
console.log(`Error in iredmail.createUser(): `, err)
|
||||
ctx.throw(500, err.message)
|
||||
}
|
||||
/*
|
||||
const user = new User(ctx.request.body.user)
|
||||
try {
|
||||
await user.save()
|
||||
} catch (err) {
|
||||
ctx.throw(422, err.message)
|
||||
}
|
||||
|
||||
const token = user.generateToken()
|
||||
const response = user.toJSON()
|
||||
|
||||
delete response.password
|
||||
|
||||
ctx.body = {
|
||||
user: response,
|
||||
token
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createUser
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// const ensureUser = require('../../middleware/validators')
|
||||
const iredmail = require('./controller')
|
||||
|
||||
module.exports.baseUrl = '/iredmail'
|
||||
|
||||
module.exports.routes = [
|
||||
{
|
||||
method: 'POST',
|
||||
route: '/adduser',
|
||||
handlers: [
|
||||
iredmail.createUser
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
const rp = require('request-promise')
|
||||
const assert = require('chai').assert
|
||||
|
||||
const IRedMail = require('../bin/iredmail')
|
||||
|
||||
const util = require('util')
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const LOCALHOST = 'http://localhost:5000'
|
||||
|
||||
describe('#iRedMail', () => {
|
||||
let testType = 'unit'
|
||||
let iRedMail
|
||||
|
||||
before(async () => {
|
||||
// Detect integration test flag.
|
||||
if (process.env.TEST_ENV === 'integration') {
|
||||
testType = 'integration'
|
||||
|
||||
iRedMail = new IRedMail()
|
||||
await iRedMail.sequelize.authenticate()
|
||||
}
|
||||
})
|
||||
|
||||
describe('#createUser', () => {
|
||||
it('should get database models', async () => {
|
||||
try {
|
||||
console.log(`Hello world!`)
|
||||
/*
|
||||
const options = {
|
||||
method: 'POST',
|
||||
uri: `${LOCALHOST}/iredmail/adduser`,
|
||||
resolveWithFullResponse: true,
|
||||
json: true,
|
||||
body: {
|
||||
}
|
||||
}
|
||||
|
||||
let result = await rp(options)
|
||||
console.log(`result: ${util.inspect(result)}`)
|
||||
*/
|
||||
} catch (err) {
|
||||
console.log(`Error in #createUser test: `, err)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user