mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
test: cover notification attribution persistence
This commit is contained in:
1 parent
389f2a042b
commit
6771b9060f
1 file changed
+57
@@ -0,0 +1,57 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { getPrismaClient, truncateAllTables } from "./setup";
|
||||
import { recordPushAttempt } from "@/lib/notifications/senders/push-attempt-record";
|
||||
|
||||
let sequence = 0;
|
||||
|
||||
async function createUser(label: string) {
|
||||
const suffix = sequence++;
|
||||
return getPrismaClient().user.create({
|
||||
data: {
|
||||
username: `${label}-${suffix}`,
|
||||
email: `${label}-${suffix}@example.test`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await truncateAllTables(getPrismaClient());
|
||||
});
|
||||
|
||||
describe("notification attribution (real Postgres)", () => {
|
||||
it("persistence retains distinct record and recipient principals", async () => {
|
||||
const recordUser = await createUser("record");
|
||||
const recipientUser = await createUser("recipient");
|
||||
|
||||
recordPushAttempt({
|
||||
recordUserId: recordUser.id,
|
||||
recipientUserId: recipientUser.id,
|
||||
channel: "NTFY",
|
||||
eventType: "MEDICATION_REMINDER",
|
||||
result: "ok",
|
||||
});
|
||||
|
||||
await vi.waitFor(async () => {
|
||||
const attempt = await getPrismaClient().pushAttempt.findFirstOrThrow({
|
||||
where: {
|
||||
recordUserId: recordUser.id,
|
||||
recipientUserId: recipientUser.id,
|
||||
},
|
||||
select: {
|
||||
recordUserId: true,
|
||||
recipientUserId: true,
|
||||
channel: true,
|
||||
eventType: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(attempt).toEqual({
|
||||
recordUserId: recordUser.id,
|
||||
recipientUserId: recipientUser.id,
|
||||
channel: "NTFY",
|
||||
eventType: "MEDICATION_REMINDER",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user