[NO-REF] - fix abscence of quiz session id on subsequent requests in tests#448
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Quizzes integration tests to include a quizSessionId when calling getQuizNextQuestion / getQuizResults, addressing failures caused by missing quiz session context on follow-up requests.
Changes:
- Pass
quizSessionIdalongsideanswersingetQuizNextQuestiontests. - Introduce and reuse a
quizSessionIdconstant in thegetQuizResultstest suite and pass it through multiple result-fetching scenarios. - Adjust one
getQuizResultstest to derivequizVersionIdfromgetQuizNextQuestionbefore requesting results.
Comments suppressed due to low confidence (2)
spec/src/modules/quizzes.js:385
quizSessionIdis now passed intogetQuizResults, but this test never asserts that it actually makes it onto the request asquiz_session_id(similar to how other parameter-specific tests assertsection,page, etc.). Adding an assertion onrequestedUrlParams.quiz_session_idwould ensure the regression this PR fixes is covered by the test suite.
return quizzes.getQuizResults(validQuizId, {
answers: validAnswers, quizSessionId,
}).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);
expect(res).to.have.property('request').to.be.an('object');
expect(res).to.have.property('response').to.be.an('object');
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(res).to.have.property('quiz_id').to.be.an('string');
expect(fetchSpy).to.have.been.called;
expect(res.response).to.have.property('results').to.be.an('array');
expect(requestedUrlParams).to.have.property('key');
expect(requestedUrlParams).to.have.property('i');
expect(requestedUrlParams).to.have.property('s');
expect(requestedUrlParams).to.have.property('c').to.equal(clientVersion);
expect(requestedUrlParams).to.have.property('_dt');
});
spec/src/modules/quizzes.js:476
- This test derives
quizVersionIdfrom an initial API call, butquizSessionIdis a shared hardcoded constant. Since the API returnsquiz_session_idon the first request (and docs recommend reusing it on subsequent requests), consider usinginitialResponse.quiz_session_idhere as well so the test exercises the real "subsequent request" flow and avoids potential mismatches if the backend ties session ids to the version/session lifecycle.
return quizzes.getQuizNextQuestion(validQuizId, {}).then((initialResponse) => {
const quizVersionId = initialResponse.quiz_version_id;
return quizzes.getQuizResults(validQuizId, {
answers: validAnswers,
quizVersionId,
quizSessionId,
}).then((res) => {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
270
to
+277
| it('Should return result given answers parameter', () => { | ||
| const quizSessionId = 'test-session-id'; | ||
| const { quizzes } = new ConstructorIO({ | ||
| apiKey: quizApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| return quizzes.getQuizNextQuestion(validQuizId, { answers: validAnswers }).then((res) => { | ||
| return quizzes.getQuizNextQuestion(validQuizId, { answers: validAnswers, quizSessionId }).then((res) => { |
Alexey-Pavlov
previously approved these changes
Apr 30, 2026
| }); | ||
|
|
||
| it('Should return result given answers parameter', () => { | ||
| const quizSessionId = 'test-session-id'; |
Contributor
There was a problem hiding this comment.
Maybe it makes sense to define it on the top, right under
describe('getQuizNextQuestion', () => { ?
And reuse it twice
Alexey-Pavlov
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix failing quizzes tests