diff --git a/src/modules/iredmail/controller.js b/src/modules/iredmail/controller.js index d48f2b0..a39aef0 100644 --- a/src/modules/iredmail/controller.js +++ b/src/modules/iredmail/controller.js @@ -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) diff --git a/test/a03-iredmail.spec.js b/test/a03-iredmail.spec.js index a578fa4..1cc0a09 100644 --- a/test/a03-iredmail.spec.js +++ b/test/a03-iredmail.spec.js @@ -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) }