diff --git a/src/lib/questioner.mjs b/src/lib/questioner.mjs index 6dc6e5a..a7bc9cc 100644 --- a/src/lib/questioner.mjs +++ b/src/lib/questioner.mjs @@ -19,7 +19,9 @@ const Questioner = class { // We want source second so that we create a new object rather than modify source. We want 'value' last because // the 'value' attached to the source is always a string, while the final value will have been converted by type. // We could also use 'structuredClone', but Object.assign should be sufficient. - this.#results.push(Object.assign({}, source, { value })) + const result = Object.assign({}, source, { value }) + delete result.mappings + this.#results.push(result) } async #askQuestion(q) { @@ -66,8 +68,11 @@ const Questioner = class { } get(parameter) { - console.error(this.#results) - return this.#results.find((r) => r.parameter === parameter)?.value + return this.getResult(parameter)?.value + } + + getResult(parameter) { + return this.#results.find((r) => r.parameter === parameter) } get interogationBundle() { return this.#interogationBundle } // TODO: clone diff --git a/src/lib/test/questioner.test.js b/src/lib/test/questioner.test.js index 299abcc..7b604c1 100644 --- a/src/lib/test/questioner.test.js +++ b/src/lib/test/questioner.test.js @@ -1,4 +1,4 @@ -/* global afterAll describe expect fail jest test */ +/* global afterAll beforeAll describe expect fail jest test */ import * as fsPath from 'node:path' import { spawn } from 'node:child_process' @@ -6,6 +6,7 @@ import { stdin } from 'mock-stdin' import { badParameterIB, + cookieParameterIB, noQuestionParameterIB, noQuestionPromptIB, simpleIB, @@ -151,4 +152,28 @@ describe('Questioner', () => { const questioner = new Questioner() expect(() => { questioner.interogationBundle = ib }).toThrow(exceptionRe) }) + + describe('cookie parameters', () => { + const questioner = new Questioner({ input }) + + beforeAll(async() => { + questioner.interogationBundle = cookieParameterIB + + const qPromise = questioner.question() + input.send('yes\n') + await qPromise + }) + + test('are passed from questions', () => + expect(questioner.getResult('IS_CLIENT').handling).toBe('bundle') + ) + + test('are passed from question maps', () => + expect(questioner.getResult('ORG_COMMON_NAME').handling).toBe('bundle') + ) + + test('are passed from question maps', () => + expect(questioner.getResult('TARGET_DEMO').handling).toBe('bundle') + ) + }) }) diff --git a/src/lib/test/test-data.js b/src/lib/test/test-data.js index 9f60415..54232c3 100644 --- a/src/lib/test/test-data.js +++ b/src/lib/test/test-data.js @@ -33,6 +33,15 @@ simpleMapIB.mappings = structuredClone(commonMapping) const simpleLocalMapIB = structuredClone(simpleIB) simpleLocalMapIB.questions[0].mappings = structuredClone(commonMapping) +const cookieParameterIB = structuredClone(simpleIB) +cookieParameterIB.mappings = structuredClone(commonMapping) +cookieParameterIB.questions[0].mappings = structuredClone(commonMapping) +cookieParameterIB.mappings[0].maps[0].parameter = 'TARGET_DEMO' +cookieParameterIB.mappings[1].maps[0].parameter = 'TARGET_DEMO' +cookieParameterIB.questions[0].handling = 'bundle' +cookieParameterIB.mappings[0].maps[0].handling = 'bundle' +cookieParameterIB.questions[0].mappings[0].maps[0].handling = 'bundle' + const DO_YOU_LIKE_MILK = 'Do you like milk?' const IS_THIS_THE_END = 'Is this the end?' const conditionalQuestionIB = structuredClone(simpleIB) @@ -62,6 +71,7 @@ export { IS_THE_COMPANY_THE_CLIENT, DO_YOU_LIKE_MILK, IS_THIS_THE_END, + cookieParameterIB, simpleIntQuestionIB, simpleIB, simpleMapIB,