Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix(ua): change the User-Agent to use the new specs lib (version) #481

Merged
merged 14 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
36 changes: 36 additions & 0 deletions src/__tests__/create-ssr-algolia-client.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createSSRSearchClient } from '../create-ssr-algolia-client';
import * as algoliasearchProxy from 'algoliasearch/index';
import { VERSION } from '../version';
import { VERSION as AngularVersion } from '@angular/core';

jest.mock('algoliasearch/index');

describe('Create SSR', () => {
it('passes the User-Agent', () => {
const addAlgoliaAgent = jest.fn();
algoliasearchProxy.mockImplementation(() => {
return {
addAlgoliaAgent,
};
});

const ssrClient = createSSRSearchClient({
appId: 'test',
apiKey: 'test',
httpClient: null,
HttpHeaders: null,
makeStateKey: null,
transferState: null,
});
expect(addAlgoliaAgent).toHaveBeenCalledTimes(3);
expect(addAlgoliaAgent).toHaveBeenCalledWith(
`angular (${AngularVersion.full})`
);
expect(addAlgoliaAgent).toHaveBeenCalledWith(
`angular-instantsearch (${VERSION})`
);
expect(addAlgoliaAgent).toHaveBeenCalledWith(
`angular-instantsearch-server (${VERSION})`
);
});
});
6 changes: 4 additions & 2 deletions src/create-ssr-algolia-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as algoliasearchProxy from 'algoliasearch/index';
import * as encodeProxy from 'querystring-es3/encode';

import { VERSION as AngularVersion } from '@angular/core';
import { VERSION } from './version';

// AOT + Rollup workaround
Expand Down Expand Up @@ -39,7 +39,9 @@ export function createSSRSearchClient({
makeStateKey,
}) {
const client = algoliasearch(appId, apiKey, {});
client.addAlgoliaAgent(`angular-instantsearch ${VERSION}`);
client.addAlgoliaAgent(`angular (${AngularVersion.full})`);
client.addAlgoliaAgent(`angular-instantsearch (${VERSION})`);
francoischalifour marked this conversation as resolved.
Show resolved Hide resolved
francoischalifour marked this conversation as resolved.
Show resolved Hide resolved
client.addAlgoliaAgent(`angular-instantsearch-server (${VERSION})`);

client._request = (rawUrl, opts) => {
let headers = new HttpHeaders();
Expand Down
4 changes: 3 additions & 1 deletion src/instantsearch/instantsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EventEmitter,
Inject,
PLATFORM_ID,
VERSION as AngularVersion,
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

Expand Down Expand Up @@ -262,7 +263,8 @@ export class NgAisInstantSearch implements AfterViewInit, OnInit, OnDestroy {
// custom algolia client agent
if (!config.searchClient && !config.createAlgoliaClient) {
samouss marked this conversation as resolved.
Show resolved Hide resolved
const client = algoliasearch(config.appId, config.apiKey);
client.addAlgoliaAgent(`angular-instantsearch ${VERSION}`);
client.addAlgoliaAgent(`angular (${AngularVersion.full})`);
client.addAlgoliaAgent(`angular-instantsearch (${VERSION})`);

config.searchClient = client;
config.appId = undefined;
Expand Down