Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions spec/src/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ describe('ConstructorIO - Autocomplete', () => {
});
});

it('Should return a response with a valid query and origin referrer', (done) => {
const originReferrer = 'https://localhost';
const { autocomplete } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

autocomplete.getAutocompleteResults(query, {}, { originReferrer }).then((res) => {
Comment thread
constructor-claude-bedrock[bot] marked this conversation as resolved.
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(res).to.have.property('request').to.be.an('object');
expect(res).to.have.property('sections').to.be.an('object');
expect(res).to.have.property('result_id').to.be.an('string');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
done();
}).catch(done);
});

it('Should return a response with a valid query and security token', (done) => {
const securityToken = 'cio-node-test';
const { autocomplete } = new ConstructorIO({
Expand Down
90 changes: 90 additions & 0 deletions spec/src/modules/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should return a response with a valid filterName, filterValue, and origin referrer', (done) => {
const originReferrer = 'https://localhost';
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

browse.getBrowseResults(filterName, filterValue, {}, { originReferrer }).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('result_id').to.be.an('string');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
done();
}).catch(done);
});

it('Should return a response with a valid filterName, filterValue, and security token', (done) => {
const securityToken = 'cio-node-test';
const { browse } = new ConstructorIO({
Expand Down Expand Up @@ -958,6 +976,24 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should return a response with valid ids and origin referrer', (done) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important Issue: The test description "Should return a response with valid ids and origin referrer" (used for getBrowseResultsForItemIds) is also reused verbatim for the getBrowseGroups test block below (line ~1462), which doesn't deal with item IDs at all. The getBrowseGroups test description should be updated to something like "Should return a response with valid groups and origin referrer" to avoid confusion when reading test output.

const originReferrer = 'https://localhost';
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

browse.getBrowseResultsForItemIds(ids, null, { originReferrer }).then((res) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: null is passed as the second argument (parameters) to getBrowseResultsForItemIds. While this likely works due to the if (parameters) guard in the implementation, it would be more idiomatic and self-documenting to pass an empty object {} instead—matching the pattern used by every other test in this PR (e.g., getBrowseResults, getBrowseFacets, etc.).

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('result_id').to.be.an('string');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
done();
}).catch(done);
});

it('Should return a response with valid ids and page', (done) => {
const page = 1;
const { browse } = new ConstructorIO({
Expand Down Expand Up @@ -1426,6 +1462,24 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should return a response with valid ids and origin referrer', (done) => {
const originReferrer = 'https://localhost';
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

browse.getBrowseGroups({}, { originReferrer }).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('result_id').to.be.an('string');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
done();
}).catch(done);
});

it('Should return a response with valid ids and additional filters', (done) => {
const filters = { group_id: ['drill_collection'] };
const { browse } = new ConstructorIO({
Expand Down Expand Up @@ -1737,6 +1791,24 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should return a response with origin referrer', (done) => {
const originReferrer = 'https://localhost';
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

browse.getBrowseFacets({}, { originReferrer }).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('result_id').to.be.an('string');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
done();
}).catch(done);
});

it('Should combine custom headers from function networkParameters and global networkParameters', (done) => {
const { browse } = new ConstructorIO({
...validOptions,
Expand Down Expand Up @@ -1930,6 +2002,24 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should return a response with origin referrer', (done) => {
const originReferrer = 'https://localhost';
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

browse.getBrowseFacetOptions(facetName, {}, { originReferrer }).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('result_id').to.be.an('string');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
done();
}).catch(done);
});

it('Should combine custom headers from function networkParameters and global networkParameters', (done) => {
const { browse } = new ConstructorIO({
...validOptions,
Expand Down
151 changes: 113 additions & 38 deletions spec/src/modules/quizzes.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,31 @@ describe('ConstructorIO - Quizzes', () => {
});
});

it('Should return a result provided a valid apiKey, quizId and origin referrer', () => {
Comment thread
constructor-claude-bedrock[bot] marked this conversation as resolved.
const originReferrer = 'https://localhost';
const { quizzes } = new ConstructorIO({
apiKey: quizApiKey,
fetch: fetchSpy,
});

return quizzes.getQuizNextQuestion(validQuizId, {}, { originReferrer }).then((res) => {
Comment thread
constructor-claude-bedrock[bot] marked this conversation as resolved.
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

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').to.equal(validQuizId);
expect(res).to.have.property('next_question').to.be.an('object');
expect(requestedUrlParams).to.have.property('origin_referrer').to.equal(originReferrer);
});
});

it('Should return result given answers parameter', () => {
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) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Several existing quiz tests were modified to add quizSessionId to the parameters (e.g., getQuizNextQuestion with answers, getQuizResults with page/resultsPerPage/filters/section). These changes appear unrelated to the originReferrer feature being introduced and are not explained in the PR description. Adding quizSessionId to existing tests changes their test scope (they now also implicitly test session ID behavior). These changes should be explained, or kept in a separate commit/PR to keep the diff focused.

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').to.equal(validQuizId);
Expand All @@ -166,11 +184,19 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizNextQuestion(validQuizId, { answers: validAnswers, skipTracking: true }).then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);
return quizzes
.getQuizNextQuestion(validQuizId, {
answers: validAnswers,
skipTracking: true,
quizSessionId,
})
.then(() => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(requestedUrlParams).to.have.property('skip_tracking').to.equal('true');
});
expect(requestedUrlParams)
.to.have.property('skip_tracking')
.to.equal('true');
});
});

it('Should be rejected if an invalid quizId is provided', () => {
Expand Down Expand Up @@ -248,23 +274,29 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers }, { clientId, sessionId }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);
return quizzes
.getQuizResults(
validQuizId,
{ answers: validAnswers, quizSessionId },
{ clientId, sessionId },
)
.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('result_id').to.be.an('string');
expect(res.response).to.have.property('results').to.be.an('array');
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').to.equal(validQuizId);
expect(fetchSpy).to.have.been.called;
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');
});
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('result_id').to.be.an('string');
expect(res.response).to.have.property('results').to.be.an('array');
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').to.equal(validQuizId);
expect(fetchSpy).to.have.been.called;
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');
});
});

it('Should return a result given valid API key, answers and page parameters', () => {
Expand All @@ -274,7 +306,7 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers, page }).then((res) => {
return quizzes.getQuizResults(validQuizId, { answers: validAnswers, page, quizSessionId }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(res).to.have.property('request').to.be.an('object');
Expand All @@ -295,18 +327,29 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers, resultsPerPage }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);
return quizzes
.getQuizResults(validQuizId, {
answers: validAnswers,
resultsPerPage,
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('result_id').to.be.an('string');
expect(res.response).to.have.property('results').to.be.an('array');
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').to.equal(validQuizId);
expect(requestedUrlParams).to.have.property('num_results_per_page').to.equal(resultsPerPage);
});
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('result_id').to.be.an('string');
expect(res.response).to.have.property('results').to.be.an('array');
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')
.to.equal(validQuizId);
expect(requestedUrlParams)
.to.have.property('num_results_per_page')
.to.equal(resultsPerPage);
});
});

it('Should return a result given valid API key, answers and filters parameters', () => {
Expand All @@ -316,7 +359,7 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers, filters }).then((res) => {
return quizzes.getQuizResults(validQuizId, { answers: validAnswers, filters, quizSessionId }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(res).to.have.property('request').to.be.an('object');
Expand All @@ -337,7 +380,7 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers, section }).then((res) => {
return quizzes.getQuizResults(validQuizId, { answers: validAnswers, section, quizSessionId }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(res).to.have.property('request').to.be.an('object');
Expand All @@ -357,7 +400,7 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers }).then((initialResponse) => {
return quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizSessionId }).then((initialResponse) => {
const { quiz_version_id: quizVersionId } = initialResponse;

// eslint-disable-next-line max-len
Expand All @@ -384,7 +427,7 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers }, { userId }).then((res) => {
return quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizSessionId }, { userId }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(res).to.have.property('request').to.be.an('object');
Expand All @@ -405,7 +448,7 @@ describe('ConstructorIO - Quizzes', () => {
fetch: fetchSpy,
});

return quizzes.getQuizResults(validQuizId, { answers: validAnswers }, { segments }).then((res) => {
return quizzes.getQuizResults(validQuizId, { answers: validAnswers, quizSessionId }, { segments }).then((res) => {
const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy);

expect(res).to.have.property('request').to.be.an('object');
Expand All @@ -419,6 +462,38 @@ describe('ConstructorIO - Quizzes', () => {
});
});

it('Should return a result provided a valid apiKey, quizId and origin referrer', () => {
const originReferrer = 'https://localhost';
const { quizzes } = new ConstructorIO({
apiKey: quizApiKey,
fetch: fetchSpy,
});

return quizzes
.getQuizResults(
validQuizId,
{ answers: validAnswers, quizSessionId },
{ originReferrer },
)
.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('result_id').to.be.an('string');
expect(res.response).to.have.property('results').to.be.an('array');
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')
.to.equal(validQuizId);
expect(requestedUrlParams)
.to.have.property('origin_referrer')
.to.equal(originReferrer);
});
});

it('Should be rejected if no quizId is provided', () => {
const { quizzes } = new ConstructorIO({
apiKey: quizApiKey,
Expand Down
Loading
Loading