Skip to content

Commit ffce78f

Browse files
committed
Added further tests for where-builder
1 parent 0d6c9c8 commit ffce78f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

packages/query-typeorm/__tests__/query/__snapshots__/where.builder.spec.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ Array [
1111
]
1212
`;
1313

14+
exports[`WhereBuilder and and multiple expressions together with custom filters 1`] = `SELECT "TestEntity"."test_entity_pk" AS "TestEntity_test_entity_pk", "TestEntity"."string_type" AS "TestEntity_string_type", "TestEntity"."bool_type" AS "TestEntity_bool_type", "TestEntity"."number_type" AS "TestEntity_number_type", "TestEntity"."date_type" AS "TestEntity_date_type", "TestEntity"."oneTestRelationTestRelationPk" AS "TestEntity_oneTestRelationTestRelationPk" FROM "test_entity" "TestEntity" WHERE ((("TestEntity"."number_type" > ?)) AND (("TestEntity"."number_type" < ?)) AND (("TestEntity"."number_type" >= ?)) AND (("TestEntity"."number_type" <= ?)) AND ((("TestEntity"."numberType" % ?) == 0)) AND (((EXTRACT(EPOCH FROM "TestEntity"."dateType") / 3600 / 24) % ?) == 0)) AND ((ST_Distance("TestEntity"."fakePointType", ST_MakePoint(?,?)) <= ?)))`;
15+
16+
exports[`WhereBuilder and and multiple expressions together with custom filters 2`] = `
17+
Array [
18+
10,
19+
20,
20+
30,
21+
40,
22+
5,
23+
3,
24+
45.3,
25+
9.5,
26+
50000,
27+
]
28+
`;
29+
1430
exports[`WhereBuilder and and multiple filters together with multiple fields 1`] = `SELECT "TestEntity"."test_entity_pk" AS "TestEntity_test_entity_pk", "TestEntity"."string_type" AS "TestEntity_string_type", "TestEntity"."bool_type" AS "TestEntity_bool_type", "TestEntity"."number_type" AS "TestEntity_number_type", "TestEntity"."date_type" AS "TestEntity_date_type", "TestEntity"."oneTestRelationTestRelationPk" AS "TestEntity_oneTestRelationTestRelationPk" FROM "test_entity" "TestEntity" WHERE ((("TestEntity"."number_type" > ?) AND ("TestEntity"."string_type" LIKE ?)) AND (("TestEntity"."number_type" < ?) AND ("TestEntity"."string_type" LIKE ?)))`;
1531

1632
exports[`WhereBuilder and and multiple filters together with multiple fields 2`] = `
@@ -85,6 +101,22 @@ Array [
85101
]
86102
`;
87103

104+
exports[`WhereBuilder or or multiple expressions together with custom filter 1`] = `SELECT "TestEntity"."test_entity_pk" AS "TestEntity_test_entity_pk", "TestEntity"."string_type" AS "TestEntity_string_type", "TestEntity"."bool_type" AS "TestEntity_bool_type", "TestEntity"."number_type" AS "TestEntity_number_type", "TestEntity"."date_type" AS "TestEntity_date_type", "TestEntity"."oneTestRelationTestRelationPk" AS "TestEntity_oneTestRelationTestRelationPk" FROM "test_entity" "TestEntity" WHERE ((("TestEntity"."number_type" > ?)) OR (("TestEntity"."number_type" < ?)) OR (("TestEntity"."number_type" >= ?)) OR (("TestEntity"."number_type" <= ?)) OR ((("TestEntity"."numberType" % ?) == 0)) OR (((EXTRACT(EPOCH FROM "TestEntity"."dateType") / 3600 / 24) % ?) == 0)) OR ((ST_Distance("TestEntity"."fakePointType", ST_MakePoint(?,?)) <= ?)))`;
105+
106+
exports[`WhereBuilder or or multiple expressions together with custom filter 2`] = `
107+
Array [
108+
10,
109+
20,
110+
30,
111+
40,
112+
5,
113+
3,
114+
45.3,
115+
9.5,
116+
50000,
117+
]
118+
`;
119+
88120
exports[`WhereBuilder or should properly group OR with a sibling field comparison 1`] = `SELECT "TestEntity"."test_entity_pk" AS "TestEntity_test_entity_pk", "TestEntity"."string_type" AS "TestEntity_string_type", "TestEntity"."bool_type" AS "TestEntity_bool_type", "TestEntity"."number_type" AS "TestEntity_number_type", "TestEntity"."date_type" AS "TestEntity_date_type", "TestEntity"."oneTestRelationTestRelationPk" AS "TestEntity_oneTestRelationTestRelationPk" FROM "test_entity" "TestEntity" WHERE ((("TestEntity"."number_type" = ?)) OR (("TestEntity"."number_type" > ?))) AND ("TestEntity"."string_type" = ?)`;
89121

90122
exports[`WhereBuilder or should properly group OR with a sibling field comparison 2`] = `

packages/query-typeorm/__tests__/query/where.builder.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ describe('WhereBuilder', (): void => {
6464
});
6565
});
6666

67+
it('and multiple expressions together with custom filters', (): void => {
68+
expectSQLSnapshot({
69+
and: [
70+
{ numberType: { gt: 10 } },
71+
{ numberType: { lt: 20 } },
72+
{ numberType: { gte: 30 } },
73+
{ numberType: { lte: 40 } },
74+
{ numberType: { isMultipleOf: 5 } },
75+
{ dateType: { isMultipleOf: 3 } },
76+
{ fakePointType: { distanceFrom: { point: { lat: 45.3, lng: 9.5 }, radius: 50000 } } },
77+
],
78+
});
79+
});
80+
6781
it('and multiple filters together with multiple fields', (): void => {
6882
expectSQLSnapshot({
6983
and: [
@@ -99,6 +113,20 @@ describe('WhereBuilder', (): void => {
99113
});
100114
});
101115

116+
it('or multiple expressions together with custom filter', (): void => {
117+
expectSQLSnapshot({
118+
or: [
119+
{ numberType: { gt: 10 } },
120+
{ numberType: { lt: 20 } },
121+
{ numberType: { gte: 30 } },
122+
{ numberType: { lte: 40 } },
123+
{ numberType: { isMultipleOf: 5 } },
124+
{ dateType: { isMultipleOf: 3 } },
125+
{ fakePointType: { distanceFrom: { point: { lat: 45.3, lng: 9.5 }, radius: 50000 } } },
126+
],
127+
});
128+
});
129+
102130
it('and multiple and filters together', (): void => {
103131
expectSQLSnapshot({
104132
or: [

0 commit comments

Comments
 (0)