From c468ce77c775ab4ce2d08ae34a74869c8e292bb2 Mon Sep 17 00:00:00 2001 From: Zane Rockenbaugh Date: Fri, 17 Mar 2023 13:05:45 -0500 Subject: [PATCH 1/4] added 'getResult'; added test for cookie parameters --- src/lib/questioner.mjs | 11 ++++++++--- src/lib/test/questioner.test.js | 28 +++++++++++++++++++++++++++- src/lib/test/test-data.js | 10 ++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) 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..68c6e4e 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,29 @@ describe('Questioner', () => { const questioner = new Questioner() expect(() => { questioner.interogationBundle = ib }).toThrow(exceptionRe) }) + + describe('cookie parameters', () => { + const questioner = new Questioner({ input }) + let results + beforeAll(async () => { + questioner.interogationBundle = cookieParameterIB + + const qPromise = questioner.question() + input.send('yes\n') + await qPromise + results = questioner.results + }) + + 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, From 36d57e9b8791222038da272fdd49786ff3631568 Mon Sep 17 00:00:00 2001 From: Zane Rockenbaugh Date: Fri, 17 Mar 2023 13:07:11 -0500 Subject: [PATCH 2/4] lint fixes --- src/lib/test/questioner.test.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/test/questioner.test.js b/src/lib/test/questioner.test.js index 68c6e4e..7b604c1 100644 --- a/src/lib/test/questioner.test.js +++ b/src/lib/test/questioner.test.js @@ -155,25 +155,24 @@ describe('Questioner', () => { describe('cookie parameters', () => { const questioner = new Questioner({ input }) - let results - beforeAll(async () => { + + beforeAll(async() => { questioner.interogationBundle = cookieParameterIB const qPromise = questioner.question() input.send('yes\n') await qPromise - results = questioner.results }) test('are passed from questions', () => expect(questioner.getResult('IS_CLIENT').handling).toBe('bundle') ) - - test('are passed from question maps', () => + + test('are passed from question maps', () => expect(questioner.getResult('ORG_COMMON_NAME').handling).toBe('bundle') ) - test('are passed from question maps', () => + test('are passed from question maps', () => expect(questioner.getResult('TARGET_DEMO').handling).toBe('bundle') ) }) From fd8d81986efd4745aab9f151d0ea977579420404 Mon Sep 17 00:00:00 2001 From: Zane Rockenbaugh Date: Fri, 17 Mar 2023 13:07:23 -0500 Subject: [PATCH 3/4] Save QA files. --- last-lint.txt | 0 last-test.txt | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 last-lint.txt create mode 100644 last-test.txt diff --git a/last-lint.txt b/last-lint.txt new file mode 100644 index 0000000..e69de29 diff --git a/last-test.txt b/last-test.txt new file mode 100644 index 0000000..b261acb --- /dev/null +++ b/last-test.txt @@ -0,0 +1,50 @@ + +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) +Is the Company the client? (y=client/n=contractor) PASS test-staging/test/questioner.test.js + Questioner + ✓ can process a simple boolean question (3 ms) + ✓ Global map yes -> us (1 ms) + ✓ Global map no -> them + ✓ Local map yes -> us + ✓ Local map no -> them + ✓ Conditional question yes -> Do you like milk? (62 ms) + ✓ Conditional question no -> Is this the end? (57 ms) + ✓ Value 'true' type 'boolean' -> true (1 ms) + ✓ Value 'true' type 'bool' -> true + ✓ Value 'true' type 'string' -> "true" (1 ms) + ✓ Value '5' type 'integer' -> 5 (1 ms) + ✓ Value '5.5' type 'float' -> 5.5 + ✓ Value '6.6' type 'numeric' -> 6.6 (1 ms) + ✓ Will re-ask questions when answer form invalid (63 ms) + ✓ Will raise an exception on an invalid parameter type. (20 ms) + ✓ Will raise an exception on no 'parameter' for question. + ✓ Will raise an exception on no 'prompt' for question. (1 ms) + cookie parameters + ✓ are passed from questions + ✓ are passed from question maps (1 ms) + ✓ are passed from question maps + +-----------------|---------|----------|---------|---------|---------------------------------------------- +File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s +-----------------|---------|----------|---------|---------|---------------------------------------------- +All files | 91.8 | 75.28 | 88.46 | 89.23 | + lib | 89.65 | 75.28 | 88.46 | 86 | + questioner.mjs | 89.65 | 75.28 | 88.46 | 86 | 28,50-52,71,78,85,88,126,132,151,172,181,186 + lib/test | 100 | 100 | 100 | 100 | + test-data.js | 100 | 100 | 100 | 100 | +-----------------|---------|----------|---------|---------|---------------------------------------------- +Test Suites: 1 passed, 1 total +Tests: 20 passed, 20 total +Snapshots: 0 total +Time: 0.472 s, estimated 1 s +Ran all test suites matching /.\/test-staging/i. From 1227c69e64b0083ba708f2a2956478265fc3216c Mon Sep 17 00:00:00 2001 From: Zane Rockenbaugh Date: Fri, 17 Mar 2023 13:07:23 -0500 Subject: [PATCH 4/4] removed QA files --- last-lint.txt | 0 last-test.txt | 50 -------------------------------------------------- 2 files changed, 50 deletions(-) delete mode 100644 last-lint.txt delete mode 100644 last-test.txt diff --git a/last-lint.txt b/last-lint.txt deleted file mode 100644 index e69de29..0000000 diff --git a/last-test.txt b/last-test.txt deleted file mode 100644 index b261acb..0000000 --- a/last-test.txt +++ /dev/null @@ -1,50 +0,0 @@ - -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) -Is the Company the client? (y=client/n=contractor) PASS test-staging/test/questioner.test.js - Questioner - ✓ can process a simple boolean question (3 ms) - ✓ Global map yes -> us (1 ms) - ✓ Global map no -> them - ✓ Local map yes -> us - ✓ Local map no -> them - ✓ Conditional question yes -> Do you like milk? (62 ms) - ✓ Conditional question no -> Is this the end? (57 ms) - ✓ Value 'true' type 'boolean' -> true (1 ms) - ✓ Value 'true' type 'bool' -> true - ✓ Value 'true' type 'string' -> "true" (1 ms) - ✓ Value '5' type 'integer' -> 5 (1 ms) - ✓ Value '5.5' type 'float' -> 5.5 - ✓ Value '6.6' type 'numeric' -> 6.6 (1 ms) - ✓ Will re-ask questions when answer form invalid (63 ms) - ✓ Will raise an exception on an invalid parameter type. (20 ms) - ✓ Will raise an exception on no 'parameter' for question. - ✓ Will raise an exception on no 'prompt' for question. (1 ms) - cookie parameters - ✓ are passed from questions - ✓ are passed from question maps (1 ms) - ✓ are passed from question maps - ------------------|---------|----------|---------|---------|---------------------------------------------- -File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------------|---------|----------|---------|---------|---------------------------------------------- -All files | 91.8 | 75.28 | 88.46 | 89.23 | - lib | 89.65 | 75.28 | 88.46 | 86 | - questioner.mjs | 89.65 | 75.28 | 88.46 | 86 | 28,50-52,71,78,85,88,126,132,151,172,181,186 - lib/test | 100 | 100 | 100 | 100 | - test-data.js | 100 | 100 | 100 | 100 | ------------------|---------|----------|---------|---------|---------------------------------------------- -Test Suites: 1 passed, 1 total -Tests: 20 passed, 20 total -Snapshots: 0 total -Time: 0.472 s, estimated 1 s -Ran all test suites matching /.\/test-staging/i.