|
1 | 1 | import type { EchoResponse } from '@algolia/client-common';
|
| 2 | +import { |
| 3 | + DEFAULT_CONNECT_TIMEOUT_NODE, |
| 4 | + DEFAULT_READ_TIMEOUT_NODE, |
| 5 | + DEFAULT_WRITE_TIMEOUT_NODE, |
| 6 | +} from '@algolia/client-common'; |
2 | 7 | import { echoRequester } from '@algolia/requester-node-http';
|
3 | 8 |
|
4 | 9 | import { algoliasearch, apiClientVersion } from '../builds/node';
|
@@ -39,6 +44,100 @@ describe('api', () => {
|
39 | 44 | expect(client.search).not.toBeUndefined();
|
40 | 45 | });
|
41 | 46 |
|
| 47 | + describe('_ua', () => { |
| 48 | + it('provides a backward compatible `_ua` variable at the root of the client', () => { |
| 49 | + expect(client._ua).toEqual( |
| 50 | + expect.stringContaining( |
| 51 | + `Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion});` |
| 52 | + ) |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it('keeps `_ua` updated with the transporter algolia agent', () => { |
| 57 | + expect(client._ua).toEqual( |
| 58 | + expect.stringMatching(/.*; Node\.js \(.*\)$/g) |
| 59 | + ); |
| 60 | + |
| 61 | + client.addAlgoliaAgent('Jest', '0.0.1'); |
| 62 | + |
| 63 | + expect(client._ua).toEqual( |
| 64 | + expect.stringMatching(/.*; Jest \(0\.0\.1\)$/g) |
| 65 | + ); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it('exposes the search client transporter for the algoliasearch client', () => { |
| 70 | + expect(client.transporter).not.toBeUndefined(); |
| 71 | + expect(client.transporter).toEqual({ |
| 72 | + algoliaAgent: { |
| 73 | + add: expect.any(Function), |
| 74 | + value: expect.stringContaining( |
| 75 | + `Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion});` |
| 76 | + ), |
| 77 | + }, |
| 78 | + baseHeaders: { |
| 79 | + 'content-type': 'text/plain', |
| 80 | + 'x-algolia-api-key': 'API_KEY', |
| 81 | + 'x-algolia-application-id': 'APP_ID', |
| 82 | + }, |
| 83 | + baseQueryParameters: {}, |
| 84 | + hosts: expect.arrayContaining([ |
| 85 | + { |
| 86 | + accept: 'read', |
| 87 | + protocol: 'https', |
| 88 | + url: 'APP_ID-dsn.algolia.net', |
| 89 | + }, |
| 90 | + { |
| 91 | + accept: 'write', |
| 92 | + protocol: 'https', |
| 93 | + url: 'APP_ID.algolia.net', |
| 94 | + }, |
| 95 | + { |
| 96 | + accept: 'readWrite', |
| 97 | + protocol: 'https', |
| 98 | + url: 'APP_ID-3.algolianet.com', |
| 99 | + }, |
| 100 | + { |
| 101 | + accept: 'readWrite', |
| 102 | + protocol: 'https', |
| 103 | + url: 'APP_ID-1.algolianet.com', |
| 104 | + }, |
| 105 | + { |
| 106 | + accept: 'readWrite', |
| 107 | + protocol: 'https', |
| 108 | + url: 'APP_ID-2.algolianet.com', |
| 109 | + }, |
| 110 | + ]), |
| 111 | + hostsCache: { |
| 112 | + clear: expect.any(Function), |
| 113 | + delete: expect.any(Function), |
| 114 | + get: expect.any(Function), |
| 115 | + set: expect.any(Function), |
| 116 | + }, |
| 117 | + request: expect.any(Function), |
| 118 | + requester: { |
| 119 | + send: expect.any(Function), |
| 120 | + }, |
| 121 | + requestsCache: { |
| 122 | + clear: expect.any(Function), |
| 123 | + delete: expect.any(Function), |
| 124 | + get: expect.any(Function), |
| 125 | + set: expect.any(Function), |
| 126 | + }, |
| 127 | + responsesCache: { |
| 128 | + clear: expect.any(Function), |
| 129 | + delete: expect.any(Function), |
| 130 | + get: expect.any(Function), |
| 131 | + set: expect.any(Function), |
| 132 | + }, |
| 133 | + timeouts: { |
| 134 | + connect: DEFAULT_CONNECT_TIMEOUT_NODE, |
| 135 | + read: DEFAULT_READ_TIMEOUT_NODE, |
| 136 | + write: DEFAULT_WRITE_TIMEOUT_NODE, |
| 137 | + }, |
| 138 | + }); |
| 139 | + }); |
| 140 | + |
42 | 141 | describe('init clients', () => {
|
43 | 142 | it('provides an init method for the analytics client', () => {
|
44 | 143 | expect(client.initAnalytics).not.toBeUndefined();
|
|
0 commit comments