Skip to content

Commit 07362ad

Browse files
author
lucas
committed
Add test cases covering $is filters where the filtered field is
inherited from a delegate base model (e.g. `viewCount` on `Asset` accessed via `$is: { video: { viewCount: ... } }`), including: - single inherited-field filter - mixed inherited + own-field filter - inherited-field filter returning no rows - nested delegate level (Video → RatedVideo) with inherited field
1 parent d62333d commit 07362ad

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/e2e/orm/client-api/delegate.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,37 @@ describe('Delegate model tests ', () => {
612612
where: { $is: { video: { $is: { ratedVideo: { rating: 5 } } } } },
613613
}),
614614
).toResolveWithLength(1);
615+
616+
// $is filtering on inherited (base-model) fields — viewCount lives on Asset,
617+
// not on Video directly; this exercises the correlated-subquery path for
618+
// fields where fieldDef.originModel !== subModelName.
619+
await expect(
620+
client.asset.findMany({
621+
where: { $is: { video: { viewCount: { gt: 0 } } } },
622+
}),
623+
).toResolveWithLength(1); // only v2 has viewCount=1, v1 has viewCount=0
624+
625+
// combine inherited-field filter with sub-model-own-field filter
626+
await expect(
627+
client.asset.findMany({
628+
where: { $is: { video: { viewCount: { gte: 0 }, duration: { gte: 100 } } } },
629+
}),
630+
).toResolveWithLength(2); // both videos match
631+
632+
// inherited-field filter that matches nothing
633+
await expect(
634+
client.asset.findMany({
635+
where: { $is: { video: { viewCount: { gt: 10 } } } },
636+
}),
637+
).toResolveWithLength(0);
638+
639+
// $is on nested delegate (Video → RatedVideo) filtering on Video's own
640+
// inherited base field (viewCount from Asset)
641+
await expect(
642+
client.video.findMany({
643+
where: { $is: { ratedVideo: { viewCount: { gt: 0 } } } },
644+
}),
645+
).toResolveWithLength(1); // only v2 (viewCount=1, rating=4)
615646
});
616647
});
617648

0 commit comments

Comments
 (0)