fix: normalize anki deck sample size

This commit is contained in:
2026-05-17 19:18:12 -07:00
parent 36e767adbc
commit 9139fc2014
2 changed files with 37 additions and 1 deletions
+30
View File
@@ -124,6 +124,36 @@ test('AnkiConnectClient derives field names from sampled notes in a deck', async
});
});
test('AnkiConnectClient treats negative deck note sample sizes as empty samples', async () => {
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
client: { post: (url: string, body: { action: string; params: unknown }) => Promise<unknown> };
};
const calls: Array<{ action: string; params: unknown }> = [];
client.client = {
post: async (_url, body) => {
calls.push({ action: body.action, params: body.params });
if (body.action === 'findNotes') {
return { data: { result: [3, 1, 2], error: null } };
}
if (body.action === 'notesInfo') {
return {
data: {
result: [{ fields: { Sentence: { value: 'x' } } }],
error: null,
},
};
}
return { data: { result: [], error: null } };
},
};
assert.deepEqual(await (client as unknown as AnkiConnectClient).fieldNamesForDeck('Mining', -1), []);
assert.deepEqual(
calls.map((call) => call.action),
['findNotes'],
);
});
test('AnkiConnectClient derives model names from sampled notes in a deck', async () => {
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
client: { post: (url: string, body: { action: string; params: unknown }) => Promise<unknown> };