Skip to content

Commit

Permalink
feat: correct shape of autocomplete redirect response (#125)
Browse files Browse the repository at this point in the history
Co-authored-by: Wesley Walser <[email protected]>
  • Loading branch information
wwalser and Wesley Walser authored Sep 28, 2021
1 parent 35ad133 commit f0d10c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sajari/sdk-js",
"description": "Sajari JavaScript SDK",
"version": "2.1.5",
"version": "2.2.0",
"main": "dist/index.js",
"umd:main": "dist/sajarisdk.umd.production.js",
"module": "dist/sajarisdk.esm.production.js",
Expand Down
10 changes: 2 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class QueryPipeline extends EventEmitter {
async search(
values: Record<string, string>,
tracking?: Tracking
): Promise<[SearchResponse, Record<string, string>]> {
): Promise<[SearchResponse, Record<string, string | Redirects>]> {
let pt: TrackingProto = { type: TrackingType.None };
if (tracking !== undefined) {
const { queryID, ...rest } = tracking;
Expand Down Expand Up @@ -453,7 +453,6 @@ class QueryPipeline extends EventEmitter {
results: results,
aggregates: aggregates,
aggregateFilters: aggregateFilters,
redirects: jsonProto.redirects,
},
jsonProto.values || {},
];
Expand Down Expand Up @@ -485,10 +484,6 @@ export interface SearchResponse {
* AggregateFilters computed on the query results (see [[Aggregates]]).
*/
aggregateFilters: Aggregates;
/**
* All Redirects for which the current query is a starting substring (see [[Redirects]]).
*/
redirects?: Redirects;
}

export interface Result {
Expand Down Expand Up @@ -562,8 +557,7 @@ export interface SearchResponseProto {
aggregateFilters: AggregatesProto;
}>;
tokens?: TokenProto[];
values?: Record<string, string>;
redirects?: Redirects;
values?: Record<string, string | Redirects>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ if (scriptTag) {
* user agent of sdk
* @hidden
*/
export const USER_AGENT = ["sajari-sdk-js/2.1.5", suffix]
export const USER_AGENT = ["sajari-sdk-js/2.2.0", suffix]
.filter(Boolean)
.join(" ");
32 changes: 18 additions & 14 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe("Pipeline", () => {
results: [],
aggregates: {},
aggregateFilters: {},
redirects: undefined,
});

expect(fetchMock.mock.calls.length).toEqual(1);
Expand All @@ -78,28 +77,26 @@ describe("Pipeline", () => {
time: "0.003s",
totalResults: "0",
},
redirects: {
"hello world": {
id: "1",
target: "https://www.google.com",
token: "https://re.sajari.com/12345abcd",
values: {
suggestions: "hello world",
redirects: {
"hello world": {
id: "1",
target: "https://www.google.com",
token: "https://re.sajari.com/12345abcd",
},
},
},
};
fetchMock.mockResponseOnce(JSON.stringify(responseObj));

const session = new DefaultSession(TrackingType.None, "url");
const [response, values] = await client
.pipeline("test", "test")
.pipeline("autocomplete", "test-autocomplete")
.search({ q: "hello" }, session.next());

expect(values).toEqual({});
expect(response).toStrictEqual({
time: 0.003,
totalResults: 0,
results: [],
aggregates: {},
aggregateFilters: {},
expect(values).toEqual({
suggestions: "hello world",
redirects: {
"hello world": {
id: "1",
Expand All @@ -108,6 +105,13 @@ describe("Pipeline", () => {
},
},
});
expect(response).toStrictEqual({
time: 0.003,
totalResults: 0,
results: [],
aggregates: {},
aggregateFilters: {},
});

expect(fetchMock.mock.calls.length).toEqual(1);
expect(fetchMock.mock.calls[0][0]).toEqual(
Expand Down

0 comments on commit f0d10c6

Please sign in to comment.