Skip to content

Commit cc90d05

Browse files
committed
chore: generate test
1 parent dec43f7 commit cc90d05

File tree

12 files changed

+412
-128
lines changed

12 files changed

+412
-128
lines changed

clients/algoliasearch-client-javascript/packages/client-common/src/transporter/errors.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ export class AlgoliaError extends Error {
1212
}
1313
}
1414

15+
export class IndexNotFoundError extends AlgoliaError {
16+
constructor(indexName: string) {
17+
super(`${indexName} does not exist`, 'IndexNotFoundError');
18+
}
19+
}
20+
21+
export class IndicesInSameAppError extends AlgoliaError {
22+
constructor() {
23+
super('Indices are in the same application. Use operationIndex instead.', 'IndicesInSameAppError');
24+
}
25+
}
26+
27+
export class IndexAlreadyExistsError extends AlgoliaError {
28+
constructor(indexName: string) {
29+
super(`${indexName} index already exists.`, 'IndexAlreadyExistsError');
30+
}
31+
}
32+
1533
export class ErrorWithStackTrace extends AlgoliaError {
1634
stackTrace: StackFrame[];
1735

playground/javascript/node/algoliasearch.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,14 @@ async function testAlgoliasearch() {
131131
}
132132
}
133133

134-
testAlgoliasearch();
134+
async function testAccountCopyIndex() {
135+
try {
136+
await client.accountCopyIndex({destinationClient: client, destinationIndexName: "foo", sourceIndexName: "bar"})
137+
} catch(e) {
138+
console.log(e)
139+
}
140+
141+
}
142+
143+
// testAlgoliasearch();
144+
testAccountCopyIndex()

playground/javascript/node/realtimePersonalization.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import type { Server } from 'http';
2+
3+
import { expect } from 'chai';
4+
import type { Express } from 'express';
5+
import express from 'express';
6+
7+
import { setupServer } from './index.ts';
8+
9+
const aciState: Record<
10+
string,
11+
{
12+
setSettingsCount: number;
13+
getSettingsCount: number;
14+
saveRulesCount: number;
15+
browseRulesCount: number;
16+
saveSynonymsCount: number;
17+
browseSynonymsCount: number;
18+
saveObjectsCount: number;
19+
browseObjectsCount: number;
20+
waitTaskCount: number;
21+
successful: boolean;
22+
}
23+
> = {};
24+
25+
export function assertValidAccountCopyIndex(expectedCount: number): void {
26+
expect(Object.keys(aciState)).to.have.length(expectedCount);
27+
for (const lang in aciState) {
28+
expect(aciState[lang].successful).to.equal(true);
29+
}
30+
}
31+
32+
function addRoutes(app: Express): void {
33+
app.use(express.urlencoded({ extended: true }));
34+
app.use(
35+
express.json({
36+
type: ['application/json', 'text/plain'], // the js client sends the body as text/plain
37+
}),
38+
);
39+
40+
app.get('/1/indexes/:indexName/settings', (req, res) => {
41+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_(source|destination)_(.*)\d+$/)?.[1] as string;
42+
expect(aciState).to.include.keys(lang);
43+
44+
aciState[lang].getSettingsCount++;
45+
46+
res.json({
47+
minWordSizefor1Typo: 4,
48+
minWordSizefor2Typos: 8,
49+
hitsPerPage: 100,
50+
maxValuesPerFacet: 100,
51+
paginationLimitedTo: 10,
52+
exactOnSingleWordQuery: 'attribute',
53+
ranking: ['typo', 'geo', 'words', 'filters', 'proximity', 'attribute', 'exact', 'custom'],
54+
separatorsToIndex: '',
55+
removeWordsIfNoResults: 'none',
56+
queryType: 'prefixLast',
57+
highlightPreTag: '<em>',
58+
highlightPostTag: '</em>',
59+
alternativesAsExact: ['ignorePlurals', 'singleWordSynonym'],
60+
});
61+
});
62+
63+
app.put('/1/indexes/:indexName/settings', (req, res) => {
64+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_destination_(.*)\d+$/)?.[1] as string;
65+
expect(aciState).to.include.keys(lang);
66+
67+
aciState[lang].setSettingsCount++;
68+
69+
res.json({ taskID: 123 + aciState[lang].setSettingsCount, updatedAt: '2021-01-01T00:00:00.000Z' });
70+
});
71+
72+
app.get('/1/indexes/:indexName/rules/search', (req, res) => {
73+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_source_(.*)\d+$/)?.[1] as string;
74+
expect(aciState).to.include.keys(lang);
75+
76+
aciState[lang].browseRulesCount++;
77+
78+
res.json({
79+
hits: [
80+
{
81+
conditions: [
82+
{
83+
alternatives: true,
84+
anchoring: 'contains',
85+
pattern: 'zorro',
86+
},
87+
],
88+
consequence: {
89+
params: {
90+
ignorePlurals: 'true',
91+
},
92+
filterPromotes: true,
93+
promote: [
94+
{
95+
objectIDs: ['\u00C6on Flux'],
96+
position: 0,
97+
},
98+
],
99+
},
100+
description: 'test_rule',
101+
enabled: true,
102+
objectID: 'qr-1725004648916',
103+
},
104+
],
105+
nbHits: 1,
106+
nbPages: 1,
107+
page: 0,
108+
});
109+
});
110+
111+
app.post('/1/indexes/:indexName/rules/batch', (req, res) => {
112+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_destination_(.*)\d+$/)?.[1] as string;
113+
expect(aciState).to.include.keys(lang);
114+
115+
aciState[lang].saveRulesCount++;
116+
117+
res.json({ taskID: 456 + aciState[lang].saveRulesCount, updatedAt: '2021-01-01T00:00:00.000Z' });
118+
});
119+
120+
app.get('/1/indexes/:indexName/synonyms/search', (req, res) => {
121+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_source_(.*)\d+$/)?.[1] as string;
122+
expect(aciState).to.include.keys(lang);
123+
124+
aciState[lang].browseSynonymsCount++;
125+
126+
res.json({
127+
hits: [
128+
{
129+
objectID: 'foo',
130+
},
131+
],
132+
nbHits: 1,
133+
nbPages: 1,
134+
page: 0,
135+
});
136+
});
137+
138+
app.post('/1/indexes/:indexName/synonyms/batch', (req, res) => {
139+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_destination_(.*)\d+$/)?.[1] as string;
140+
expect(aciState).to.include.keys(lang);
141+
142+
aciState[lang].saveSynonymsCount++;
143+
144+
res.json({ taskID: 789 + aciState[lang].saveSynonymsCount, updatedAt: '2021-01-01T00:00:00.000Z' });
145+
});
146+
147+
app.post('/1/indexes/:indexName/browse', (req, res) => {
148+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_source_(.*)\d+$/)?.[1] as string;
149+
expect(aciState).to.include.keys(lang);
150+
151+
aciState[lang].browseObjectsCount++;
152+
153+
res.json({
154+
page: 0,
155+
nbHits: 1,
156+
nbPages: 1,
157+
hitsPerPage: 1000,
158+
query: '',
159+
params: '',
160+
hits: [{ objectID: 'bar' }],
161+
});
162+
});
163+
164+
app.post('/1/indexes/:indexName/batch', (req, res) => {
165+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_destination_(.*)\d+$/)?.[1] as string;
166+
expect(aciState).to.include.keys(lang);
167+
168+
aciState[lang].saveObjectsCount++;
169+
170+
res.json({ taskID: 10 + aciState[lang].saveObjectsCount, updatedAt: '2021-01-01T00:00:00.000Z' });
171+
});
172+
173+
app.get('/1/indexes/:indexName/task/:taskID', (req, res) => {
174+
const lang = req.params.indexName.match(/^cts_e2e_account_copy_index_destination_(.*)\d+$/)?.[1] as string;
175+
expect(aciState).to.include.keys(lang);
176+
177+
aciState[lang].waitTaskCount++;
178+
179+
res.json({ status: 'published', updatedAt: '2021-01-01T00:00:00.000Z' });
180+
});
181+
}
182+
183+
export function accountCopyIndexServer(): Promise<Server> {
184+
// this server is used to simulate the responses for the accountCopyIndex method,
185+
// and uses a state machine to determine if the logic is correct.
186+
return setupServer('accountCopyIndex', 6687, addRoutes);
187+
}

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 { accountCopyIndexServer } from './accountCopyIndex.ts';
1011
import { algoliaMockServer } from './algoliaMock.ts';
1112
import { apiKeyServer } from './apiKey.ts';
1213
import { benchmarkServer } from './benchmark.ts';
@@ -26,6 +27,7 @@ export async function startTestServer(suites: Record<CTSType, boolean>): Promise
2627
timeoutServer(),
2728
gzipServer(),
2829
timeoutServerBis(),
30+
accountCopyIndexServer(),
2931
replaceAllObjectsServer(),
3032
replaceAllObjectsServerFailed(),
3133
replaceAllObjectsScopesServer(),

specs/search/helpers/accountCopyIndex.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
method:
2-
post:
2+
get:
33
x-helper: true
44
tags:
55
- Account
66
operationId: accountCopyIndex
7-
summary: Copies the index of an Algolia application, to an other Algolia application
7+
summary: Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`
88
description: |
9-
Copies the index of an Algolia application, to an other Algolia application.
9+
Copies the given `sourceIndexName` records, rules and synonyms to an other Algolia application for the given `destinationIndexName`.
1010
parameters:
1111
- in: query
1212
name: sourceIndexName
13-
description: The name of the index to copy in the `sourceClient`.
13+
description: The name of the index to copy.
1414
required: true
1515
schema:
1616
type: string
1717
- in: query
18-
name: destinationClient
19-
description: The already initialized search client with write ACL credentials, this is the application to copy the index to.
18+
name: destinationAppID
19+
description: The application ID to write the index to.
2020
required: true
2121
schema:
22-
type: object
22+
type: string
23+
- in: query
24+
name: destinationApiKey
25+
description: The API Key of the `destinationAppID` to write the index to, must have write ACLs.
26+
required: true
27+
schema:
28+
type: string
2329
- in: query
2430
name: destinationIndexName
25-
description: The name of the index to write the copied index to in the `destinationClient`.
31+
description: The name of the index to write the copied index to.
2632
required: true
2733
schema:
2834
type: string

specs/search/spec.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ paths:
372372
/generateSecuredApiKey:
373373
$ref: 'helpers/generateSecuredApiKey.yml#/method'
374374

375+
/accountCopyIndex:
376+
$ref: 'helpers/accountCopyIndex.yml#/method'
377+
375378
/replaceAllObjects:
376379
$ref: 'helpers/replaceAllObjects.yml#/method'
377380

0 commit comments

Comments
 (0)