From 4f37c8de6e46ebb8734e4c179aafe37e1cf3acd0 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Mon, 27 Mar 2023 15:43:56 -0700 Subject: [PATCH 01/10] Add quiz_session_id, quiz_version_id --- spec/src/modules/quizzes.js | 45 +++++++++++++++++++++++++++++++++++-- src/modules/quizzes.js | 25 ++++++++++++++------- src/types/quizzes.d.ts | 7 +++++- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index ee836967..b53d0d17 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -106,7 +106,28 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('next_question').to.be.an('object'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); - expect(requestedUrlParams).to.have.property('version_id').to.equal(versionId); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(versionId); + }); + }); + + it('Should return a result provided a valid apiKey, quizId and quizVersionId, quizSessionId', () => { + const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; + const quizSessionId = '123;'; + const { quizzes } = new ConstructorIO({ + apiKey: quizApiKey, + fetch: fetchSpy, + }); + + return quizzes.getQuizNextQuestion(validQuizId, { quizVersionId, quizSessionId }).then((res) => { + const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + expect(res).to.have.property('version_id').to.be.an('string').to.equal(quizVersionId); + expect(res).to.have.property('next_question').to.be.an('object'); + expect(res.next_question.id).to.equal(1); + expect(res.next_question.options[0].id).to.equal(1); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); + expect(requestedUrlParams).to.have.property('quiz_session_id').to.equal(quizSessionId); + }); }); @@ -271,7 +292,27 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); expect(res).to.have.property('version_id').to.be.an('string'); - expect(requestedUrlParams).to.have.property('version_id').to.equal(versionId); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(versionId); + }); + }); + + it('Should return a result provided a valid apiKey, quizId, quizVersionId and quizSessionId', () => { + const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; + const quizSessionId = '12345'; + const { quizzes } = new ConstructorIO({ + apiKey: quizApiKey, + fetch: fetchSpy, + }); + + // eslint-disable-next-line max-len + return quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizVersionId, quizSessionId }).then((res) => { + const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); + + expect(res).to.have.property('result').to.be.an('object'); + expect(res.result).to.have.property('results_url').to.be.an('string'); + expect(res).to.have.property('version_id').to.be.an('string'); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); + expect(requestedUrlParams).to.have.property('quiz_session_id').to.equal(quizSessionId); }); }); diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index e68e4f85..1c5ad66b 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -40,16 +40,21 @@ function createQuizUrl(quizId, parameters, options, path) { } if (parameters) { - const { section, answers, versionId } = parameters; + const { section, answers, versionId, quizSessionId, quizVersionId = versionId } = parameters; // Pull section from parameters if (section) { queryParams.section = section; } - // Pull version_id from parameters - if (versionId) { - queryParams.version_id = versionId; + // Pull quiz_version_id from parameters + if (quizVersionId) { + queryParams.quiz_version_id = quizVersionId; + } + + // Pull quiz_session_id from parameters + if (quizSessionId) { + queryParams.quiz_session_id = quizSessionId; } // Pull a (answers) from parameters and transform @@ -88,7 +93,8 @@ class Quizzes { * @param {string} [parameters] - Additional parameters to refine result set * @param {string} [parameters.section] - Product catalog section * @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]] - * @param {string} [parameters.versionId] - Version identifier for the quiz + * @param {string} [parameters.quizVersionId] - Version identifier for the quiz + * @param {string} [parameters.quizSessionId] - Session identifier for the quiz * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {Promise} @@ -97,7 +103,8 @@ class Quizzes { * constructorio.quizzes.getQuizNextQuestion('quizId', { * answers: [[1,2],[1]], * section: '123', - * versionId: '123' + * quizVersionId: '123', + * quizSessionId: '1234', * }); */ getQuizNextQuestion(id, parameters, networkParameters = {}) { @@ -143,7 +150,8 @@ class Quizzes { * @param {string} [parameters] - Additional parameters to refine result set * @param {string} [parameters.section] - Product catalog section * @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]] - * @param {string} [parameters.versionId] - Specific version identifier for the quiz + * @param {string} [parameters.quizVersionId] - Specific version identifier for the quiz + * @param {string} [parameters.quizSessionId] - Session identifier for the quiz * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {Promise} @@ -152,7 +160,8 @@ class Quizzes { * constructorio.quizzes.getQuizResults('quizId', { * answers: [[1,2],[1]], * section: '123', - * versionId: '123' + * quizVersionId: '123', + * quizSessionId: '234' * }); */ getQuizResults(id, parameters, networkParameters = {}) { diff --git a/src/types/quizzes.d.ts b/src/types/quizzes.d.ts index eed00741..a7fded60 100644 --- a/src/types/quizzes.d.ts +++ b/src/types/quizzes.d.ts @@ -6,7 +6,8 @@ export default Quizzes; export interface QuizzesParameters { section?: string; answers?: any[]; - versionId?: string; + quizVersionId?: string; + quizSessionId?: string; } declare class Quizzes { @@ -32,10 +33,14 @@ export interface NextQuestionResponse extends Record { next_question: Question; is_last_question?: boolean; version_id?: string; + quiz_id?: string; + quiz_session_id?: string; } export interface QuizResultsResponse extends Record { result: Partial; version_id?: string; + quiz_id?: string; + quiz_session_id?: string; } export type Question = SelectQuestion | OpenQuestion | CoverQuestion From 049b29c81d4a56393ea473f11f7962800779bd47 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Mon, 27 Mar 2023 15:49:31 -0700 Subject: [PATCH 02/10] remove quiz version id reject tests --- spec/src/modules/quizzes.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index b53d0d17..e5d1ce76 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -200,15 +200,6 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return expect(quizzes.getQuizNextQuestion(null, {})).to.eventually.be.rejected; }); - it('Should be rejected if an invalid versionId is provided', () => { - const { quizzes } = new ConstructorIO({ - apiKey: quizApiKey, - fetch: fetchSpy, - }); - - return expect(quizzes.getQuizNextQuestion(validQuizId, { versionId: 'foo' })).to.eventually.be.rejected; - }); - if (!skipNetworkTimeoutTests) { it('Should be rejected when network request timeout is provided and reached', () => { const { quizzes } = new ConstructorIO({ @@ -370,15 +361,6 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return expect(quizzes.getQuizResults('invalidQuizId', { answers: validAnswers })).to.eventually.be.rejected; }); - it('Should be rejected if an invalid versionId is provided', () => { - const { quizzes } = new ConstructorIO({ - apiKey: quizApiKey, - fetch: fetchSpy, - }); - - return expect(quizzes.getQuizResults(validQuizId, { answers: validAnswers, versionId: 'foo' })).to.eventually.be.rejected; - }); - it('Should be rejected if an invalid apiKey is provided', () => { const { quizzes } = new ConstructorIO({ apiKey: 'invalidKey', From 0378745cc1483630677218c82d2378b3a553b762 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Wed, 29 Mar 2023 10:12:43 -0700 Subject: [PATCH 03/10] address comments --- src/modules/quizzes.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index 1c5ad66b..21db8677 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -40,18 +40,13 @@ function createQuizUrl(quizId, parameters, options, path) { } if (parameters) { - const { section, answers, versionId, quizSessionId, quizVersionId = versionId } = parameters; + const { section, answers, quizSessionId, quizVersionId } = parameters; // Pull section from parameters if (section) { queryParams.section = section; } - // Pull quiz_version_id from parameters - if (quizVersionId) { - queryParams.quiz_version_id = quizVersionId; - } - // Pull quiz_session_id from parameters if (quizSessionId) { queryParams.quiz_session_id = quizSessionId; @@ -93,8 +88,8 @@ class Quizzes { * @param {string} [parameters] - Additional parameters to refine result set * @param {string} [parameters.section] - Product catalog section * @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]] - * @param {string} [parameters.quizVersionId] - Version identifier for the quiz - * @param {string} [parameters.quizSessionId] - Session identifier for the quiz + * @param {string} [parameters.quizVersionId] - Version identifier for the quiz. Version ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-versioning + * @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-sessions * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {Promise} @@ -150,8 +145,8 @@ class Quizzes { * @param {string} [parameters] - Additional parameters to refine result set * @param {string} [parameters.section] - Product catalog section * @param {array} [parameters.answers] - An array of answers in the format [[1,2],[1]] - * @param {string} [parameters.quizVersionId] - Specific version identifier for the quiz - * @param {string} [parameters.quizSessionId] - Session identifier for the quiz + * @param {string} [parameters.quizVersionId] - Version identifier for the quiz. Version ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-versioning + * @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-sessions * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {Promise} From 3c1adf93ee8be031116bf530ad504f0f7da16fb9 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Wed, 29 Mar 2023 10:16:11 -0700 Subject: [PATCH 04/10] address comments --- spec/src/modules/quizzes.js | 20 ++++++++++---------- src/modules/quizzes.js | 5 +++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index e5d1ce76..d869e262 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -21,7 +21,7 @@ const bundled = process.env.BUNDLED === 'true'; const skipNetworkTimeoutTests = process.env.SKIP_NETWORK_TIMEOUT_TESTS === 'true'; const bundledDescriptionSuffix = bundled ? ' - Bundled' : ''; -describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { +describe.only(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { const validQuizId = 'test-quiz'; const validAnswers = [[1], [1, 2], ['seen']]; const jsdomOptions = { url: 'http://localhost' }; @@ -92,21 +92,21 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); - it('Should return a result provided a valid apiKey, quizId and versionId', () => { - const versionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; + it('Should return a result provided a valid apiKey, quizId and quizVersionId', () => { + const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, fetch: fetchSpy, }); - return quizzes.getQuizNextQuestion(validQuizId, { versionId }).then((res) => { + return quizzes.getQuizNextQuestion(validQuizId, { quizVersionId }).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string').to.equal(versionId); + expect(res).to.have.property('version_id').to.be.an('string').to.equal(quizVersionId); expect(res).to.have.property('next_question').to.be.an('object'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); - expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(versionId); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); }); }); @@ -270,20 +270,20 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); - it('Should return a result provided a valid apiKey, quizId and versionId', () => { - const versionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; + it('Should return a result provided a valid apiKey, quizId and quizVersionId', () => { + const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, fetch: fetchSpy, }); - return quizzes.getQuizResults(validQuizId, { answers: validAnswers, versionId }).then((res) => { + return quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizVersionId }).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); expect(res).to.have.property('version_id').to.be.an('string'); - expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(versionId); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); }); }); diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index 21db8677..32962a27 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -47,6 +47,11 @@ function createQuizUrl(quizId, parameters, options, path) { queryParams.section = section; } + // Pull quiz_version_id from parameters + if (quizVersionId) { + queryParams.quiz_version_id = quizVersionId; + } + // Pull quiz_session_id from parameters if (quizSessionId) { queryParams.quiz_session_id = quizSessionId; From 21b29916a4cfcab9bdd85513e83d2f70bd0bdd57 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Wed, 29 Mar 2023 10:16:28 -0700 Subject: [PATCH 05/10] remove only --- spec/src/modules/quizzes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index d869e262..87d6e4a0 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -21,7 +21,7 @@ const bundled = process.env.BUNDLED === 'true'; const skipNetworkTimeoutTests = process.env.SKIP_NETWORK_TIMEOUT_TESTS === 'true'; const bundledDescriptionSuffix = bundled ? ' - Bundled' : ''; -describe.only(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { +describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { const validQuizId = 'test-quiz'; const validAnswers = [[1], [1, 2], ['seen']]; const jsdomOptions = { url: 'http://localhost' }; From 814ccf4856207547e7d619fc3d9d5cc80d8e0e2a Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Wed, 29 Mar 2023 10:17:01 -0700 Subject: [PATCH 06/10] lint --- src/modules/quizzes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index 32962a27..448d9505 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -50,7 +50,7 @@ function createQuizUrl(quizId, parameters, options, path) { // Pull quiz_version_id from parameters if (quizVersionId) { queryParams.quiz_version_id = quizVersionId; - } + } // Pull quiz_session_id from parameters if (quizSessionId) { From 50b364bfe13a2648a13dacc96d024c3a6269f3e3 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Mon, 3 Apr 2023 09:57:35 -0700 Subject: [PATCH 07/10] address comments --- spec/src/modules/quizzes.js | 64 ++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index 87d6e4a0..38828022 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -61,8 +61,9 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return quizzes.getQuizNextQuestion(validQuizId, {}).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); expect(fetchSpy).to.have.been.called; @@ -84,29 +85,33 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return quizzes.getQuizNextQuestion(validQuizId, { section }).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); expect(requestedUrlParams).to.have.property('section').to.equal(section); }); }); - it('Should return a result provided a valid apiKey, quizId and quizVersionId', () => { + it('Should return a result provided a valid apiKey, quizId, quizVersionId and quizSessionId', () => { const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; + const quizSessionId = '123'; const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, fetch: fetchSpy, }); - return quizzes.getQuizNextQuestion(validQuizId, { quizVersionId }).then((res) => { + return quizzes.getQuizNextQuestion(validQuizId, { quizVersionId, quizSessionId }).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string').to.equal(quizVersionId); + expect(res).to.have.property('quiz_version_id').to.be.an('string').to.equal(quizVersionId); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string').to.equal(quizSessionId); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); + expect(requestedUrlParams).to.have.property('quiz_session_id').to.equal(quizSessionId); }); }); @@ -121,8 +126,9 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return quizzes.getQuizNextQuestion(validQuizId, { quizVersionId, quizSessionId }).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string').to.equal(quizVersionId); + expect(res).to.have.property('quiz_version_id').to.be.an('string').to.equal(quizVersionId); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); @@ -142,8 +148,9 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return quizzes.getQuizNextQuestion(validQuizId, {}).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); expect(requestedUrlParams).to.have.property('ui').to.equal(userId); @@ -161,8 +168,9 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { return quizzes.getQuizNextQuestion(validQuizId, {}).then((res) => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(res.next_question.id).to.equal(1); expect(res.next_question.options[0].id).to.equal(1); expect(requestedUrlParams).to.have.property('us').to.deep.equal(segments); @@ -176,12 +184,22 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); return quizzes.getQuizNextQuestion(validQuizId, { answers: validAnswers }).then((res) => { - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); expect(res).to.have.property('next_question').to.be.an('object'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(res.next_question.id).to.equal(4); }); }); + it('Should be rejected if an invalid quizVersionId is provided', () => { + const { quizzes } = new ConstructorIO({ + apiKey: quizApiKey, + fetch: fetchSpy, + }); + + return expect(quizzes.getQuizNextQuestion(validQuizId, { quizVersionId: 'foo' })).to.eventually.be.rejected; + }); + it('Should be rejected if an invalid quizId is provided', () => { const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, @@ -243,7 +261,8 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(fetchSpy).to.have.been.called; expect(requestedUrlParams).to.have.property('key'); expect(requestedUrlParams).to.have.property('i'); @@ -265,7 +284,8 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(requestedUrlParams).to.have.property('section').to.equal(section); }); }); @@ -282,7 +302,8 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); }); }); @@ -301,7 +322,9 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string').to.equal(quizVersionId); + expect(res).to.have.property('quiz_session_id').to.be.an('string').to.equal(quizSessionId); + expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); expect(requestedUrlParams).to.have.property('quiz_session_id').to.equal(quizSessionId); }); @@ -320,7 +343,8 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(requestedUrlParams).to.have.property('ui').to.equal(userId); }); }); @@ -338,11 +362,21 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { expect(res).to.have.property('result').to.be.an('object'); expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('version_id').to.be.an('string'); + expect(res).to.have.property('quiz_version_id').to.be.an('string'); + expect(res).to.have.property('quiz_session_id').to.be.an('string'); expect(requestedUrlParams).to.have.property('us').to.deep.equal(segments); }); }); + it('Should be rejected if an invalid quizVersionId is provided', () => { + const { quizzes } = new ConstructorIO({ + apiKey: quizApiKey, + fetch: fetchSpy, + }); + + return expect(quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizVersionId: 'foo' })).to.eventually.be.rejected; + }); + it('Should be rejected if no quizId is provided', () => { const { quizzes } = new ConstructorIO({ apiKey: quizApiKey, From e3ccbe64422e4749568ef692c331877e04ab9530 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Mon, 3 Apr 2023 16:55:32 -0700 Subject: [PATCH 08/10] fix tests --- spec/src/modules/quizzes.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index 73479f0d..f236eef4 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -295,24 +295,6 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); - it('Should return a result provided a valid apiKey, quizId and quizVersionId', () => { - const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; - const { quizzes } = new ConstructorIO({ - apiKey: quizApiKey, - fetch: fetchSpy, - }); - - return quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizVersionId }).then((res) => { - const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - - expect(res).to.have.property('result').to.be.an('object'); - expect(res.result).to.have.property('results_url').to.be.an('string'); - expect(res).to.have.property('quiz_version_id').to.be.an('string'); - expect(res).to.have.property('quiz_session_id').to.be.an('string'); - expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); - }); - }); - it('Should return a result provided a valid apiKey, quizId, quizVersionId and quizSessionId', () => { const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; const quizSessionId = '12345'; From 3009668e2d90143b155fba01977dd0764a814204 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Mon, 3 Apr 2023 16:56:56 -0700 Subject: [PATCH 09/10] update version_id --- src/modules/quizzes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/quizzes.js b/src/modules/quizzes.js index 139d54cb..d4021968 100644 --- a/src/modules/quizzes.js +++ b/src/modules/quizzes.js @@ -145,7 +145,7 @@ class Quizzes { return helpers.throwHttpErrorFromResponse(new Error(), response); }) .then((json) => { - if (json.version_id) { + if (json.quiz_version_id) { this.eventDispatcher.queue('quizzes.getQuizNextQuestion.completed', json); return json; @@ -205,7 +205,7 @@ class Quizzes { return helpers.throwHttpErrorFromResponse(new Error(), response); }) .then((json) => { - if (json.version_id) { + if (json.quiz_version_id) { this.eventDispatcher.queue('quizzes.getQuizResults.completed', json); return json; From 124c8d15d06ec78f5f13774a292e0acb0fb0517f Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Mon, 3 Apr 2023 16:58:41 -0700 Subject: [PATCH 10/10] get rid of duplicate test --- spec/src/modules/quizzes.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/spec/src/modules/quizzes.js b/spec/src/modules/quizzes.js index f236eef4..669ac355 100644 --- a/spec/src/modules/quizzes.js +++ b/spec/src/modules/quizzes.js @@ -94,27 +94,6 @@ describe(`ConstructorIO - Quizzes${bundledDescriptionSuffix}`, () => { }); }); - it('Should return a result provided a valid apiKey, quizId, quizVersionId and quizSessionId', () => { - const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; - const quizSessionId = '123'; - const { quizzes } = new ConstructorIO({ - apiKey: quizApiKey, - fetch: fetchSpy, - }); - - return quizzes.getQuizNextQuestion(validQuizId, { quizVersionId, quizSessionId }).then((res) => { - const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - - expect(res).to.have.property('quiz_version_id').to.be.an('string').to.equal(quizVersionId); - expect(res).to.have.property('next_question').to.be.an('object'); - expect(res).to.have.property('quiz_session_id').to.be.an('string').to.equal(quizSessionId); - expect(res.next_question.id).to.equal(1); - expect(res.next_question.options[0].id).to.equal(1); - expect(requestedUrlParams).to.have.property('quiz_version_id').to.equal(quizVersionId); - expect(requestedUrlParams).to.have.property('quiz_session_id').to.equal(quizSessionId); - }); - }); - it('Should return a result provided a valid apiKey, quizId and quizVersionId, quizSessionId', () => { const quizVersionId = 'e03210db-0cc6-459c-8f17-bf014c4f554d'; const quizSessionId = '123;';