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
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ export class EchoRequester extends Requester {
{ headers, url, connectTimeout, responseTimeout }: EndRequest,
{ data, ...originalRequest }: Request
): Promise<Response> {
const urlSearchParams = new URL(url).searchParams;
const { host, searchParams: urlSearchParams } = new URL(url);
const userAgent = urlSearchParams.get('x-algolia-agent') || undefined;
const originalData =
data && Object.entries(data).length > 0 ? data : undefined;

return Promise.resolve({
content: JSON.stringify({
...originalRequest,
host,
headers,
connectTimeout,
responseTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type Response = {

export type EchoResponse = Request & {
connectTimeout: number;
host: string;
headers: Record<string, string>;
responseTimeout: number;
searchParams?: Record<string, string>;
Expand Down
50 changes: 50 additions & 0 deletions tests/CTS/client/abtesting/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"testName": "calls api with correct user agent",
"steps": [
{
"type": "method",
"object": "$client",
"path": "addABTests",
"parameters": [
{
"name": "test",
"variant": [{ "index": "my-test-index", "trafficPercentage": 90 }],
"endAt": "2022-02-01T13:37:01Z"
}
],
"expected": {
"testSubject": "actual.userAgent",
"match": {
"regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/"
}
}
}
]
},
{
"testName": "calls api with correct timeouts",
"steps": [
{
"type": "method",
"object": "$client",
"path": "addABTests",
"parameters": [
{
"name": "test",
"variant": [{ "index": "my-test-index", "trafficPercentage": 90 }],
"endAt": "2022-02-01T13:37:01Z"
}
],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 30
}
}
}
}
]
}
]
36 changes: 36 additions & 0 deletions tests/CTS/client/abtesting/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"testName": "fallbacks to the alias when region is not given",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": ""
},
"expected": {
"error": false
}
},
{
"type": "method",
"object": "$client",
"path": "getABTest",
"parameters": [
{
"id": "test"
}
],
"expected": {
"match": {
"objectContaining": {
"host": "analytics.algolia.com"
}
}
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/CTS/client/analytics/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"testName": "calls api with correct user agent",
"steps": [
{
"type": "method",
"object": "$client",
"path": "getAverageClickPosition",
"parameters": [{ "index": "my-index" }],
"expected": {
"testSubject": "actual.userAgent",
"match": {
"regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/"
}
}
}
]
},
{
"testName": "calls api with correct timeouts",
"steps": [
{
"type": "method",
"object": "$client",
"path": "getAverageClickPosition",
"parameters": [{ "index": "my-index" }],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 5
}
}
}
}
]
}
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"testName": "does not throw when region is not given",
"testName": "fallbacks to the alias when region is not given",
"autoCreateClient": false,
"steps": [
{
Expand All @@ -13,6 +13,19 @@
"expected": {
"error": false
}
},
{
"type": "method",
"object": "$client",
"path": "getAverageClickPosition",
"parameters": [{ "index": "my-index" }],
"expected": {
"match": {
"objectContaining": {
"host": "analytics.algolia.com"
}
}
}
}
]
},
Expand Down
46 changes: 46 additions & 0 deletions tests/CTS/client/insights/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"testName": "calls api with correct user agent",
"steps": [
{
"type": "method",
"object": "$client",
"path": "pushEvents",
"parameters": [
{
"events": []
}
],
"expected": {
"testSubject": "actual.userAgent",
"match": {
"regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/"
}
}
}
]
},
{
"testName": "calls api with correct timeouts",
"steps": [
{
"type": "method",
"object": "$client",
"path": "pushEvents",
"parameters": [
{
"events": []
}
],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 30
}
}
}
}
]
}
]
32 changes: 32 additions & 0 deletions tests/CTS/client/insights/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"testName": "fallbacks to the alias when region is not given",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": ""
},
"expected": {
"error": false
}
},
{
"type": "method",
"object": "$client",
"path": "pushEvents",
"parameters": [{ "events": [] }],
"expected": {
"match": {
"objectContaining": {
"host": "insights.algolia.io"
}
}
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/CTS/client/personalization/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"testName": "calls api with correct user agent",
"steps": [
{
"type": "method",
"object": "$client",
"path": "getPersonalizationStrategy",
"parameters": [],
"expected": {
"testSubject": "actual.userAgent",
"match": {
"regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/"
}
}
}
]
},
{
"testName": "calls api with correct timeouts",
"steps": [
{
"type": "method",
"object": "$client",
"path": "getPersonalizationStrategy",
"parameters": [],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 5
}
}
}
}
]
}
]
36 changes: 36 additions & 0 deletions tests/CTS/client/personalization/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"testName": "throws when region is not given",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": ""
},
"expected": {
"error": "`region` is missing."
}
}
]
},
{
"testName": "does not throw when region is given",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": "us"
},
"expected": {
"error": false
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/CTS/client/query-suggestions/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"testName": "calls api with correct user agent",
"steps": [
{
"type": "method",
"object": "$client",
"path": "createConfig",
"parameters": [{}],
"expected": {
"testSubject": "actual.userAgent",
"match": {
"regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/"
}
}
}
]
},
{
"testName": "calls api with correct timeouts",
"steps": [
{
"type": "method",
"object": "$client",
"path": "createConfig",
"parameters": [{}],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 30
}
}
}
}
]
}
]
Loading