From 5cf77d9011a80b326f229b2309a6910ac0f1cfa2 Mon Sep 17 00:00:00 2001 From: Louistiti Date: Sat, 4 May 2019 09:41:37 +0800 Subject: [PATCH] fix: e2e tests by adding modules actions level --- test/e2e/nlp-modules.spec.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/e2e/nlp-modules.spec.js b/test/e2e/nlp-modules.spec.js index f71535b46..88faea85c 100644 --- a/test/e2e/nlp-modules.spec.js +++ b/test/e2e/nlp-modules.spec.js @@ -30,7 +30,7 @@ describe('NLU modules', () => { const lang = langs[langKeys[i]] const nlu = new Nlu() const brain = new Brain({ emit: jest.fn() }, lang.short) - let expressions = { } + let expressionsObj = { } nlu.brain = { wernicke: jest.fn(), talk: jest.fn(), socket: { emit: jest.fn() } } brain.talk = jest.fn() @@ -48,26 +48,32 @@ describe('NLU modules', () => { // eslint-disable-next-line no-loop-func describe(`${packages[j]} package`, () => { const expressionsFile = `${global.paths.packages}/${packages[j]}/data/expressions/${lang.short}.json` - expressions = JSON.parse(fs.readFileSync(expressionsFile, 'utf8')) + expressionsObj = JSON.parse(fs.readFileSync(expressionsFile, 'utf8')) - const modules = Object.keys(expressions) + const modules = Object.keys(expressionsObj) for (let k = 0; k < modules.length; k += 1) { + const module = modules[k] + const actions = Object.keys(expressionsObj[module]) + // eslint-disable-next-line no-loop-func - describe(`${modules[k]} module`, () => { - const exprs = expressions[modules[k]] + describe(`${module} module`, () => { + for (let l = 0; l < actions.length; l += 1) { + const action = actions[l] + const exprs = expressionsObj[module][action].expressions - for (let l = 0; l < exprs.length; l += 1) { - // eslint-disable-next-line no-loop-func - test(`"${exprs[l]}" queries this module`, async () => { - // Need to redefine the NLU brain execution to update the mocking - nlu.brain.execute = jest.fn() + for (let m = 0; m < exprs.length; m += 1) { + // eslint-disable-next-line no-loop-func + test(`"${exprs[m]}" queries this module`, async () => { + // Need to redefine the NLU brain execution to update the mocking + nlu.brain.execute = jest.fn() - await nlu.process(exprs[l]) - const [obj] = nlu.brain.execute.mock.calls + await nlu.process(exprs[m]) + const [obj] = nlu.brain.execute.mock.calls - expect(obj[0].classification.package).toBe(packages[j]) - expect(obj[0].classification.module).toBe(modules[k]) - }) + expect(obj[0].classification.package).toBe(packages[j]) + expect(obj[0].classification.module).toBe(module) + }) + } } }) }