Skip to content

Commit 7c52fe1

Browse files
committed
add test server for saveObjects
1 parent 7130a10 commit 7c52fe1

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { Server } from 'http';
2+
3+
import type { Express, Request, Response } from 'express';
4+
5+
import { setupServer } from './index.ts';
6+
7+
// Checks that the client sends a different API key after the first request.
8+
function addRoutes(app: Express): void {
9+
app.post('/1/indexes/:indexName/batch', (req: Request, res: Response) => {
10+
res.json({
11+
taskID: 333,
12+
objectIDs: ['1', '2'],
13+
});
14+
});
15+
app.get('/1/indexes/:indexName/task/:taskID', (req, res) => {
16+
res.json({
17+
status: 'published',
18+
});
19+
});
20+
}
21+
22+
export function algoliaMockServer(): Promise<Server> {
23+
return setupServer('algoliaMock', 6686, addRoutes);
24+
}

scripts/cts/testServer/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createSpinner } from '../../spinners.ts';
77
import type { CTSType } from '../runCts.ts';
88

99
import { expect } from 'chai';
10+
import { algoliaMockServer } from './algoliaMock.ts';
1011
import { apiKeyServer } from './apiKey.ts';
1112
import { benchmarkServer } from './benchmark.ts';
1213
import { chunkWrapperServer } from './chunkWrapper.ts';
@@ -31,6 +32,7 @@ export async function startTestServer(suites: Record<CTSType, boolean>): Promise
3132
chunkWrapperServer(),
3233
waitForApiKeyServer(),
3334
apiKeyServer(),
35+
algoliaMockServer(),
3436
);
3537
}
3638
if (suites.benchmark) {

tests/CTS/client/search/saveObjects.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,20 @@
118118
},
119119
{
120120
"testName": "saveObjectsPublicUser",
121-
"autoCreateClient": true,
121+
"autoCreateClient": false,
122122
"steps": [
123+
{
124+
"type": "createClient",
125+
"parameters": {
126+
"appId": "test-app-id",
127+
"apiKey": "test-api-key",
128+
"customHosts": [
129+
{
130+
"port": 6686
131+
}
132+
]
133+
}
134+
},
123135
{
124136
"type": "method",
125137
"method": "saveObjects",
@@ -135,11 +147,11 @@
135147
}
136148
]
137149
},
138-
"requestOptions": {
139-
"headers": {
140-
"X-Algolia-User-ID": "*"
141-
}
150+
"requestOptions": {
151+
"headers": {
152+
"X-Algolia-User-ID": "*"
142153
}
154+
}
143155
}
144156
]
145157
}

0 commit comments

Comments
 (0)