From d781a161837b48f000c0bf3215f49b19aa211024 Mon Sep 17 00:00:00 2001 From: Ralph Huwiler Date: Thu, 8 Feb 2018 21:44:20 +0100 Subject: [PATCH] added a test for promised data --- test/promise-data.spec.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/promise-data.spec.js diff --git a/test/promise-data.spec.js b/test/promise-data.spec.js new file mode 100644 index 0000000..108eff3 --- /dev/null +++ b/test/promise-data.spec.js @@ -0,0 +1,35 @@ +'use strict' + +/** + * adonis-bumblebee + * + * (c) Ralph Huwiler + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. +*/ + +const test = require('japa') +const { ioc } = require('@adonisjs/fold') + +const setup = require('./setup') + +test.group('Promise Data', (group) => { + group.before(async () => { + await setup() + }) + + test('data can be a promis and will resolve before transforming', async (assert) => { + const Context = ioc.use('Adonis/Src/HttpContext') + const {transform} = new Context() + + let data = new Promise((resolve, reject) => { + setTimeout(resolve, 1, {item_id: 3}) + }) + + let transformed = await transform + .item(data, model => ({id: model.item_id})) + + assert.equal(transformed.id, 3) + }) +})