Skip to content

Commit 64afc37

Browse files
author
Luke Melia
committed
Add 'in' filter tests using the id field
Covers filtering cards by id with the 'in' operator in both host (SQLite) and realm-server (Postgres) test suites.
1 parent fdfdb72 commit 64afc37

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

packages/host/tests/unit/index-query-engine-test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,33 @@ module('Unit | query', function (hooks) {
908908
assert.deepEqual(getIds(results), [vangogh.id], 'results are correct');
909909
});
910910

911+
test(`can filter using 'in' with the id field`, async function (assert) {
912+
let { mango, vangogh, ringo } = testCards;
913+
await setupIndex(dbAdapter, [
914+
{ card: mango, data: { search_doc: { name: 'Mango' } } },
915+
{ card: vangogh, data: { search_doc: { name: 'Van Gogh' } } },
916+
{ card: ringo, data: { search_doc: { name: 'Ringo' } } },
917+
]);
918+
919+
let type = await personCardType(testCards);
920+
let { cards: results, meta } = await indexQueryEngine.searchCards(
921+
new URL(testRealmURL),
922+
{
923+
filter: {
924+
on: type,
925+
in: { id: [mango.id, ringo.id] },
926+
},
927+
},
928+
);
929+
930+
assert.strictEqual(meta.page.total, 2, 'the total results meta is correct');
931+
assert.deepEqual(
932+
getIds(results),
933+
[mango.id, ringo.id],
934+
'results are correct',
935+
);
936+
});
937+
911938
test(`can search with a 'not' filter`, async function (assert) {
912939
let { mango, vangogh, ringo } = testCards;
913940
await setupIndex(dbAdapter, [

packages/realm-server/tests/realm-endpoints/search-test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,34 @@ module(`realm-endpoints/${basename(__filename)}`, function () {
11211121
);
11221122
});
11231123

1124+
test(`can filter using 'in' with the id field`, async function (assert) {
1125+
let response = await request
1126+
.post(searchPath)
1127+
.set('Accept', 'application/vnd.card+json')
1128+
.set('X-HTTP-Method-Override', 'QUERY')
1129+
.send({
1130+
filter: {
1131+
on: personType(),
1132+
in: {
1133+
id: [`${realmHref}mango`, `${realmHref}ringo`],
1134+
},
1135+
},
1136+
});
1137+
1138+
assert.strictEqual(response.status, 200, 'HTTP 200 status');
1139+
assert.strictEqual(
1140+
response.body.meta.page.total,
1141+
2,
1142+
'total count is correct',
1143+
);
1144+
let ids = response.body.data.map((d: any) => d.id).sort();
1145+
assert.deepEqual(
1146+
ids,
1147+
[`${realmHref}mango`, `${realmHref}ringo`],
1148+
'correct cards returned by id',
1149+
);
1150+
});
1151+
11241152
test(`can negate an 'in' filter with 'not'`, async function (assert) {
11251153
let response = await request
11261154
.post(searchPath)

0 commit comments

Comments
 (0)