Skip to content

Commit

Permalink
fix: e2e tests by adding modules actions level
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed May 4, 2019
1 parent 0c2d846 commit 5cf77d9
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions test/e2e/nlp-modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
})
}
}
})
}
Expand Down

0 comments on commit 5cf77d9

Please sign in to comment.