Skip to content

[NO-REF] - fix abscence of quiz session id on subsequent requests in tests#448

Merged
esezen merged 3 commits into
Constructor-io:masterfrom
vladconstructor:NO-REF/fix-abscence-of-quiz-session-id-on-subsequent-requests-in-tests
May 11, 2026
Merged

[NO-REF] - fix abscence of quiz session id on subsequent requests in tests#448
esezen merged 3 commits into
Constructor-io:masterfrom
vladconstructor:NO-REF/fix-abscence-of-quiz-session-id-on-subsequent-requests-in-tests

Conversation

@vladconstructor
Copy link
Copy Markdown
Contributor

Fix failing quizzes tests

Copilot AI review requested due to automatic review settings April 30, 2026 12:47
@vladconstructor vladconstructor requested a review from a team as a code owner April 30, 2026 12:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 quizSessionId alongside answers in getQuizNextQuestion tests.
  • Introduce and reuse a quizSessionId constant in the getQuizResults test suite and pass it through multiple result-fetching scenarios.
  • Adjust one getQuizResults test to derive quizVersionId from getQuizNextQuestion before requesting results.
Comments suppressed due to low confidence (2)

spec/src/modules/quizzes.js:385

  • quizSessionId is now passed into getQuizResults, but this test never asserts that it actually makes it onto the request as quiz_session_id (similar to how other parameter-specific tests assert section, page, etc.). Adding an assertion on requestedUrlParams.quiz_session_id would 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 quizVersionId from an initial API call, but quizSessionId is a shared hardcoded constant. Since the API returns quiz_session_id on the first request (and docs recommend reusing it on subsequent requests), consider using initialResponse.quiz_session_id here 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
Alexey-Pavlov previously approved these changes Apr 30, 2026
Copy link
Copy Markdown
Contributor

@Alexey-Pavlov Alexey-Pavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread spec/src/modules/quizzes.js Outdated
});

it('Should return result given answers parameter', () => {
const quizSessionId = 'test-session-id';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to define it on the top, right under
describe('getQuizNextQuestion', () => { ?
And reuse it twice

@esezen esezen merged commit b9f117d into Constructor-io:master May 11, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants