Skip to content

Commit 7427ab2

Browse files
Test/vault expiry windows (#922)
* security: re-authorize export downloads and enforce per-object org ownership * test: vault expiry deadline-window boundaries and DST safety * test: request-scoped Prisma binding and cleanup invariants * test: vault expiry deadline-window boundaries and DST safety
1 parent b75dd72 commit 7427ab2

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/tests/vaultExpiry.reminders.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const mockDbChain = {
88
where: jest.fn(() => mockDbChain),
99
whereIn: jest.fn(() => mockDbChain),
1010
whereNotNull: jest.fn(() => mockDbChain),
11-
select: jest.fn(() => mockDbChain),
11+
select: jest.fn().mockImplementation(async () => mockVaultMilestones),
1212
}
1313

1414
jest.unstable_mockModule('../db/index.js', () => ({
@@ -29,7 +29,6 @@ describe('sendMilestoneReminders', () => {
2929
beforeEach(() => {
3030
jest.clearAllMocks()
3131
mockVaultMilestones = []
32-
;(mockDbChain.select as jest.Mock).mockResolvedValue(mockVaultMilestones)
3332
})
3433

3534
it('sends a reminder for a milestone within lead time', async () => {
@@ -96,18 +95,21 @@ describe('sendMilestoneReminders', () => {
9695
]
9796

9897
// First call
99-
await sendMilestoneReminders({
98+
const result1 = await sendMilestoneReminders({
10099
now,
101100
leadTimesMs: [1 * 60 * 60 * 1000],
102101
})
102+
expect(result1).toBe(1)
103103
expect(mockCreateNotification).toHaveBeenCalledTimes(1)
104104

105-
// Second call (should be deduplicated)
106-
await sendMilestoneReminders({
105+
// Second call (simulating idempotency collision in DB)
106+
mockCreateNotification.mockRejectedValueOnce(new Error('Duplicate key value violates unique constraint'))
107+
const result2 = await sendMilestoneReminders({
107108
now,
108109
leadTimesMs: [1 * 60 * 60 * 1000],
109110
})
110-
expect(mockCreateNotification).toHaveBeenCalledTimes(1) // Still 1
111+
expect(result2).toBe(0)
112+
expect(mockCreateNotification).toHaveBeenCalledTimes(2)
111113
})
112114

113115
it('skips milestones that are not pending', async () => {

0 commit comments

Comments
 (0)