getUsers returns usernames

This commit is contained in:
Chris Troutner
2019-01-22 16:53:07 -08:00
parent 49002dc105
commit 87cb1fc815
2 changed files with 13 additions and 7 deletions
+7 -5
View File
@@ -12,16 +12,18 @@ async function createUser (ctx) {
*/
async function getUsers (ctx) {
try {
// console.log(`ctx.iRedMail: ${util.inspect(ctx.iRedMail)}`)
// Sync the model.
// const model = await ctx.iRedMail.models.usedQuota.sync()
// const model = await ctx.iRedMail.models.mailbox.sync()
const model = await ctx.iRedMail.models.forwardings.sync()
const model = await ctx.iRedMail.models.mailbox.sync()
// const model = await ctx.iRedMail.models.forwardings.sync()
// Get every model in the database.
const data = await model.findAll()
ctx.body = data
// Get just the user name.
const users = data.map(x => x.username)
ctx.body = users
} catch (err) {
console.log(`Error in iredmail.createUser(): `, err)
ctx.throw(500, err.message)
+6 -2
View File
@@ -52,7 +52,7 @@ describe('#iRedMail', () => {
describe('#getUsers', () => {
if (process.env.TEST_ENV === 'integration') {
it('should get database models', async () => {
it('should get usernames of all users in mailbox table', async () => {
try {
// console.log(`Hello world!`)
@@ -64,7 +64,11 @@ describe('#iRedMail', () => {
}
let result = await rp(options)
console.log(`result: ${util.inspect(result.body)}`)
// console.log(`result: ${util.inspect(result.body)}`)
// Returns an array of username/email strings.
assert.isArray(result.body)
assert.isString(result.body[0])
} catch (err) {
console.log(`Error in #createUser test: `, err)
}