Skip to content

Commit dccd50f

Browse files
Striftbrunoocasali
authored andcommitted
Update typo tolerance tests using snapshots
1 parent b69f25e commit dccd50f

File tree

4 files changed

+94
-22
lines changed

4 files changed

+94
-22
lines changed

src/indexes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,9 @@ export class Index<T extends RecordAny = RecordAny> {
963963
* settings.
964964
* @returns Promise containing object of the enqueued update
965965
*/
966-
updateTypoTolerance(typoTolerance: TypoTolerance): EnqueuedTaskPromise {
966+
updateTypoTolerance(
967+
typoTolerance: Partial<TypoTolerance> | null,
968+
): EnqueuedTaskPromise {
967969
return this.#httpRequestsWithTask.patch({
968970
path: `indexes/${this.uid}/settings/typo-tolerance`,
969971
body: typoTolerance,

src/types/types.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,15 @@ export type RankingRules = string[] | null;
522522
export type StopWords = string[] | null;
523523
export type Synonyms = Record<string, string[]> | null;
524524
export type TypoTolerance = {
525-
enabled?: boolean | null;
526-
disableOnAttributes?: string[] | null;
527-
disableOnWords?: string[] | null;
528-
minWordSizeForTypos?: {
529-
oneTypo?: number | null;
530-
twoTypos?: number | null;
525+
enabled: boolean;
526+
disableOnAttributes: string[];
527+
disableOnNumbers: boolean;
528+
disableOnWords: string[];
529+
minWordSizeForTypos: {
530+
oneTypo: number;
531+
twoTypos: number;
531532
};
532-
} | null;
533+
};
533534
export type SeparatorTokens = string[] | null;
534535
export type NonSeparatorTokens = string[] | null;
535536
export type Dictionary = string[] | null;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Tests on typo tolerance > Admin key: Get default typo tolerance settings 1`] = `
4+
{
5+
"disableOnAttributes": [],
6+
"disableOnNumbers": false,
7+
"disableOnWords": [],
8+
"enabled": true,
9+
"minWordSizeForTypos": {
10+
"oneTypo": 5,
11+
"twoTypos": 9,
12+
},
13+
}
14+
`;
15+
16+
exports[`Tests on typo tolerance > Admin key: Reset typo tolerance settings 1`] = `
17+
{
18+
"disableOnAttributes": [],
19+
"disableOnNumbers": false,
20+
"disableOnWords": [],
21+
"enabled": true,
22+
"minWordSizeForTypos": {
23+
"oneTypo": 5,
24+
"twoTypos": 9,
25+
},
26+
}
27+
`;
28+
29+
exports[`Tests on typo tolerance > Admin key: Update typo tolerance using null as value 1`] = `
30+
{
31+
"disableOnAttributes": [],
32+
"disableOnNumbers": false,
33+
"disableOnWords": [],
34+
"enabled": true,
35+
"minWordSizeForTypos": {
36+
"oneTypo": 5,
37+
"twoTypos": 9,
38+
},
39+
}
40+
`;
41+
42+
exports[`Tests on typo tolerance > Master key: Get default typo tolerance settings 1`] = `
43+
{
44+
"disableOnAttributes": [],
45+
"disableOnNumbers": false,
46+
"disableOnWords": [],
47+
"enabled": true,
48+
"minWordSizeForTypos": {
49+
"oneTypo": 5,
50+
"twoTypos": 9,
51+
},
52+
}
53+
`;
54+
55+
exports[`Tests on typo tolerance > Master key: Reset typo tolerance settings 1`] = `
56+
{
57+
"disableOnAttributes": [],
58+
"disableOnNumbers": false,
59+
"disableOnWords": [],
60+
"enabled": true,
61+
"minWordSizeForTypos": {
62+
"oneTypo": 5,
63+
"twoTypos": 9,
64+
},
65+
}
66+
`;
67+
68+
exports[`Tests on typo tolerance > Master key: Update typo tolerance using null as value 1`] = `
69+
{
70+
"disableOnAttributes": [],
71+
"disableOnNumbers": false,
72+
"disableOnWords": [],
73+
"enabled": true,
74+
"minWordSizeForTypos": {
75+
"oneTypo": 5,
76+
"twoTypos": 9,
77+
},
78+
}
79+
`;

tests/typo_tolerance.test.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ const index = {
1313
uid: "movies_test",
1414
};
1515

16-
const defaultTypoTolerance = {
17-
enabled: true,
18-
minWordSizeForTypos: {
19-
oneTypo: 5,
20-
twoTypos: 9,
21-
},
22-
disableOnWords: [],
23-
disableOnAttributes: [],
24-
};
25-
2616
afterAll(() => {
2717
return clearAllIndexes(config);
2818
});
@@ -39,7 +29,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
3929
test(`${permission} key: Get default typo tolerance settings`, async () => {
4030
const client = await getClient(permission);
4131
const response = await client.index(index.uid).getTypoTolerance();
42-
expect(response).toEqual(defaultTypoTolerance);
32+
expect(response).toMatchSnapshot();
4333
});
4434

4535
test(`${permission} key: Update typo tolerance settings`, async () => {
@@ -52,14 +42,14 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
5242
},
5343
disableOnWords: ["title"],
5444
disableOnAttributes: ["hello"],
45+
disableOnNumbers: true,
5546
};
5647
await client
5748
.index(index.uid)
5849
.updateTypoTolerance(newTypoTolerance)
5950
.waitTask();
6051

6152
const response = await client.index(index.uid).getTypoTolerance();
62-
6353
expect(response).toEqual(newTypoTolerance);
6454
});
6555

@@ -69,7 +59,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
6959

7060
const response = await client.index(index.uid).getTypoTolerance();
7161

72-
expect(response).toEqual(defaultTypoTolerance);
62+
expect(response).toMatchSnapshot();
7363
});
7464

7565
test(`${permission} key: Reset typo tolerance settings`, async () => {
@@ -78,7 +68,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
7868

7969
const response = await client.index(index.uid).getTypoTolerance();
8070

81-
expect(response).toEqual(defaultTypoTolerance);
71+
expect(response).toMatchSnapshot();
8272
});
8373
},
8474
);

0 commit comments

Comments
 (0)