Skip to content

Commit 25c0aa9

Browse files
committed
tests for serializeWhere
1 parent 636f134 commit 25c0aa9

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/makeFindUnique.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FindOptions, ModelStatic, Model, Attributes } from 'sequelize';
22

3-
import DataLoaderManager from './dataLoaderManager';
3+
import DataLoaderManager, { ModelBatchLoadFn } from './dataLoaderManager';
44
import { findRowByWhere, getWhereQuery } from './utils';
55
import { FindUniqueOptions } from './types';
66

@@ -18,9 +18,7 @@ const makeFindUnique = <ModelType extends Model>(
1818
) => {
1919
const onLoadBatch = options?.onLoadBatch ?? noop;
2020

21-
const batchLoadFn = async (
22-
keys: ReadonlyArray<FindOptions<any>>,
23-
): Promise<Array<ModelType | null>> => {
21+
const batchLoadFn: ModelBatchLoadFn<ModelType> = async (keys) => {
2422
onLoadBatch(keys);
2523

2624
const whereQuery = getWhereQuery(keys);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`serializeFindUniqueOptions serializes primitive values correctly 1`] = `"{\\"firstName\\":\\"Kalle\\",\\"lastName\\":\\"Ilves\\"}"`;
4+
5+
exports[`serializeFindUniqueOptions throws error for non-primitive values 1`] = `"Where parameter properties can only contain serializable primitive values. Found value of type \\"object\\" in property \\"friends\\""`;

src/tests/serializeWhere.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import serializeWhere from '../serializeWhere';
2+
3+
describe('serializeFindUniqueOptions', () => {
4+
test('serializes primitive values correctly', () => {
5+
expect(
6+
serializeWhere({
7+
firstName: 'Kalle',
8+
lastName: 'Ilves',
9+
}),
10+
).toMatchSnapshot();
11+
});
12+
13+
test('throws error for non-primitive values', () => {
14+
expect(() =>
15+
serializeWhere({
16+
firstName: 'Kalle',
17+
lastName: 'Ilves',
18+
friends: ['elina'],
19+
}),
20+
).toThrowErrorMatchingSnapshot();
21+
});
22+
});

0 commit comments

Comments
 (0)