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
10 changes: 10 additions & 0 deletions spec/src/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ describe('ConstructorIO - Autocomplete', () => {
});
});

it('Should include requestUrl in the promise for getAutocompleteResults', () => {
const { autocomplete } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = autocomplete.getAutocompleteResults(query);
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('Should return a variations_map object in the response', (done) => {
const variationsMap = {
group_by: [
Expand Down
52 changes: 52 additions & 0 deletions spec/src/modules/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,16 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should include requestUrl in the promise for getBrowseResults', () => {
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = browse.getBrowseResults(filterName, filterValue);
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('Should be rejected when invalid filterName is provided', () => {
const { browse } = new ConstructorIO(validOptions);

Expand Down Expand Up @@ -846,6 +856,7 @@ describe('ConstructorIO - Browse', () => {

browse.getBrowseResultsForItemIds(ids).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');
Expand All @@ -858,6 +869,17 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should include requestUrl in the promise for getBrowseResultsForItemIds', () => {
const itemIds = ['item1', 'item2'];
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = browse.getBrowseResultsForItemIds(itemIds);
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('should return a response with valid ids, client id and session id', (done) => {
const userParameters = {
clientId: 'example client id',
Expand Down Expand Up @@ -1375,6 +1397,16 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should include requestUrl in the promise for getBrowseGroups', () => {
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = browse.getBrowseGroups({});
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('Should return a response with valid ids and user id', (done) => {
const userId = 'user-id';
const { browse } = new ConstructorIO({
Expand Down Expand Up @@ -1731,6 +1763,16 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should include requestUrl in the promise for getBrowseFacets', () => {
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = browse.getBrowseFacets({});
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('Should be rejected when invalid apiKey is provided', () => {
const { browse } = new ConstructorIO({ apiKey: 'fyzs7tfF8L161VoAXQ8u' });

Expand Down Expand Up @@ -1914,6 +1956,16 @@ describe('ConstructorIO - Browse', () => {
});
});

it('Should include requestUrl in the promise for getBrowseFacetOptions', () => {
const { browse } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = browse.getBrowseFacetOptions(facetName);
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('Should be rejected when no facetName is provided', () => {
const { browse } = new ConstructorIO(validOptions);

Expand Down
20 changes: 20 additions & 0 deletions spec/src/modules/quizzes.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ describe('ConstructorIO - Quizzes', () => {

return expect(quizzes.getQuizNextQuestion(validQuizId, {})).to.eventually.be.rejected;
});

it('Should include requestUrl in the promise for getQuizNextQuestion', () => {
const { quizzes } = new ConstructorIO({
apiKey: quizApiKey,
fetch: fetchSpy,
});

const promise = quizzes.getQuizNextQuestion(validQuizId, {}, { clientId, sessionId });
expect(promise).to.have.property('requestUrl').that.is.a('string');
});
});

describe('getQuizResults', () => {
Expand Down Expand Up @@ -470,5 +480,15 @@ describe('ConstructorIO - Quizzes', () => {
return expect(quizzes.getQuizResults(validQuizId, { answers: validAnswers })).to.eventually.be.rejectedWith('The operation was aborted.');
});
}

it('Should include requestUrl in the promise for getQuizResults', () => {
const { quizzes } = new ConstructorIO({
apiKey: quizApiKey,
fetch: fetchSpy,
});

const promise = quizzes.getQuizResults(validQuizId, { answers: validAnswers });
expect(promise).to.have.property('requestUrl').that.is.a('string');
});
});
});
10 changes: 10 additions & 0 deletions spec/src/modules/recommendations.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,16 @@ describe('ConstructorIO - Recommendations', () => {
)).to.eventually.be.rejectedWith('The operation was aborted.');
});
}

it('Should include requestUrl in the promise for getRecommendations', () => {
const { recommendations } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = recommendations.getRecommendations(podId, { itemIds: itemId });
expect(promise).to.have.property('requestUrl').that.is.a('string');
});
});

describe('getRecommendationPods', () => {
Expand Down
10 changes: 10 additions & 0 deletions spec/src/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ describe('ConstructorIO - Search', () => {
});
});

it('Should include requestUrl in the promise for getSearchResults', () => {
const { search } = new ConstructorIO({
...validOptions,
fetch: fetchSpy,
});

const promise = search.getSearchResults(query, { section });
expect(promise).to.have.property('requestUrl').that.is.a('string');
});

it('Should be rejected when invalid query is provided', () => {
const { search } = new ConstructorIO(validOptions);

Expand Down
6 changes: 5 additions & 1 deletion src/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Autocomplete {
// Handle network timeout if specified
helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, { headers, signal }).then((response) => {
const promise = fetch(requestUrl, { headers, signal }).then((response) => {
if (response.ok) {
return response.json();
}
Expand Down Expand Up @@ -234,6 +234,10 @@ class Autocomplete {

throw new Error('getAutocompleteResults response data is malformed');
});

promise.requestUrl = requestUrl;

return promise;
}
}

Expand Down
64 changes: 41 additions & 23 deletions src/modules/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class Browse {
// Handle network timeout if specified
helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, { headers, signal }).then((response) => {
const promise = fetch(requestUrl, { headers, signal }).then((response) => {
if (response.ok) {
return response.json();
}
Expand All @@ -321,6 +321,10 @@ class Browse {

throw new Error('getBrowseResults response data is malformed');
});

promise.requestUrl = requestUrl;

return promise;
}

/**
Expand Down Expand Up @@ -375,27 +379,29 @@ class Browse {
// Handle network timeout if specified
helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, { headers, signal })
.then((response) => {
if (response.ok) {
return response.json();
}
const promise = fetch(requestUrl, { headers, signal }).then((response) => {
if (response.ok) {
return response.json();
}

return helpers.throwHttpErrorFromResponse(new Error(), response);
})
.then((json) => {
if (json.response && json.response.results) {
if (json.result_id) {
// Append `result_id` to each result item
json.response.results.forEach((result) => {
// eslint-disable-next-line no-param-reassign
result.result_id = json.result_id;
});
}
return json;
return helpers.throwHttpErrorFromResponse(new Error(), response);
}).then((json) => {
if (json.response && json.response.results) {
if (json.result_id) {
// Append `result_id` to each result item
json.response.results.forEach((result) => {
// eslint-disable-next-line no-param-reassign
result.result_id = json.result_id;
});
}
throw new Error('getBrowseResultsForItemIds response data is malformed');
});
return json;
}
throw new Error('getBrowseResultsForItemIds response data is malformed');
});

promise.requestUrl = requestUrl;

return promise;
}

/**
Expand Down Expand Up @@ -443,13 +449,17 @@ class Browse {
// Handle network timeout if specified
helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, { headers, signal }).then((response) => {
const promise = fetch(requestUrl, { headers, signal }).then((response) => {
if (response.ok) {
return response.json();
}

return helpers.throwHttpErrorFromResponse(new Error(), response);
});

promise.requestUrl = requestUrl;

return promise;
}

/**
Expand Down Expand Up @@ -498,7 +508,7 @@ class Browse {
// Handle network timeout if specified
helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, {
const promise = fetch(requestUrl, {
headers: { ...headers, ...helpers.createAuthHeader(this.options) },
signal,
}).then((response) => {
Expand All @@ -508,6 +518,10 @@ class Browse {

return helpers.throwHttpErrorFromResponse(new Error(), response);
});

promise.requestUrl = requestUrl;

return promise;
}

/**
Expand Down Expand Up @@ -553,7 +567,7 @@ class Browse {
// Handle network timeout if specified
helpers.applyNetworkTimeout(this.options, networkParameters, controller);

return fetch(requestUrl, {
const promise = fetch(requestUrl, {
headers: { ...headers, ...helpers.createAuthHeader(this.options) },
signal,
}).then((response) => {
Expand All @@ -563,6 +577,10 @@ class Browse {

return helpers.throwHttpErrorFromResponse(new Error(), response);
});

promise.requestUrl = requestUrl;

return promise;
}
}

Expand Down
Loading
Loading