Skip to content

feat(cts): add tests for host, user agent, and timeouts #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -27,14 +27,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
50 changes: 50 additions & 0 deletions tests/CTS/client/abtesting/basic.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
}
}
}
}
]
}
]
31 changes: 18 additions & 13 deletions tests/CTS/client/analytics/basic.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
[
{
"testName": "does not throw when region is not given",
"autoCreateClient": false,
"testName": "calls api with correct user agent",
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": ""
},
"type": "method",
"object": "$client",
"path": "getAverageClickPosition",
"parameters": [{ "index": "my-index" }],
"expected": {
"error": false
"testSubject": "actual.userAgent",
"match": {
"regexp": "/Algolia%20for%20(.+)%20\\(\\d+\\.\\d+\\.\\d+\\)/"
}
}
}
]
},
{
"testName": "getAverageClickPosition throws without index",
"testName": "calls api with correct timeouts",
"steps": [
{
"type": "method",
"object": "$client",
"path": "getClickPositions",
"parameters": [{}],
"path": "getAverageClickPosition",
"parameters": [{ "index": "my-index" }],
"expected": {
"error": "Parameter `index` is required when calling `getClickPositions`."
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 5
}
}
}
}
]
Expand Down
33 changes: 33 additions & 0 deletions tests/CTS/client/analytics/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"testName": "does not throw when region is not given",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "my-app-id",
"apiKey": "my-api-key",
"region": ""
},
"expected": {
"error": false
}
}
]
},
{
"testName": "getAverageClickPosition throws without index",
"steps": [
{
"type": "method",
"object": "$client",
"path": "getClickPositions",
"parameters": [{}],
"expected": {
"error": "Parameter `index` is required when calling `getClickPositions`."
}
}
]
}
]
46 changes: 46 additions & 0 deletions tests/CTS/client/insights/basic.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
}
}
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/CTS/client/personalization/basic.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
}
}
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/CTS/client/query-suggestions/basic.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
}
}
}
}
]
}
]
38 changes: 38 additions & 0 deletions tests/CTS/client/recommend/basic.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": "getRecommendations",
"parameters": [{ "requests": [] }],
"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": "getRecommendations",
"parameters": [{ "requests": [] }],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 30
}
}
}
}
]
}
]
56 changes: 56 additions & 0 deletions tests/CTS/client/search/basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"testName": "calls api with correct host",
"steps": [
{
"type": "method",
"object": "$client",
"path": "search",
"parameters": [{ "indexName": "my-index", "searchParams": {} }],
"expected": {
"match": {
"objectContaining": {
"host": "algolia-api-key.algolia.net"
}
}
}
}
]
},
{
"testName": "calls api with correct user agent",
"steps": [
{
"type": "method",
"object": "$client",
"path": "search",
"parameters": [{ "indexName": "my-index", "searchParams": {} }],
"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": "search",
"parameters": [{ "indexName": "my-index", "searchParams": {} }],
"expected": {
"match": {
"objectContaining": {
"connectTimeout": 2,
"responseTimeout": 30
}
}
}
}
]
}
]
2 changes: 1 addition & 1 deletion tests/CTS/client/search/parameters.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"testName": "constructor throws with invalid parameters",
"testName": "client throws with invalid parameters",
"autoCreateClient": false,
"steps": [
{
Expand Down
Loading