style(13-03): apply Prettier formatting across repo
Mechanical reformat — no logic changes. 398 files changed, 19125 insertions(+), 16457 deletions(-). Prettier 3.8.4 with .prettierrc (singleQuote:true, semi:true, tabWidth:2, trailingComma:all, printWidth:100). Isolated per D-13-08 for reviewability.
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
* Run: pnpm --filter @familysync/api exec vitest run tests/lib/pushDispatcher.test.ts
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import type { PushSubscription } from '../../src/lib/pushDispatcher.js'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import type { PushSubscription } from '../../src/lib/pushDispatcher.js';
|
||||
|
||||
// Mock web-push so no real network calls occur
|
||||
vi.mock('web-push', () => ({
|
||||
@@ -20,7 +20,7 @@ vi.mock('web-push', () => ({
|
||||
sendNotification: vi.fn(),
|
||||
setVapidDetails: vi.fn(),
|
||||
},
|
||||
}))
|
||||
}));
|
||||
|
||||
// Mock the DB module so we can assert on deletes without a real database
|
||||
vi.mock('../../src/db/client.js', () => ({
|
||||
@@ -29,7 +29,7 @@ vi.mock('../../src/db/client.js', () => ({
|
||||
where: vi.fn().mockResolvedValue(undefined),
|
||||
}),
|
||||
},
|
||||
}))
|
||||
}));
|
||||
|
||||
const FAKE_SUB: PushSubscription = {
|
||||
id: 1,
|
||||
@@ -37,60 +37,64 @@ const FAKE_SUB: PushSubscription = {
|
||||
endpoint: 'https://push.example.com/sub/abc',
|
||||
p256dh: 'fake_p256dh',
|
||||
auth: 'fake_auth',
|
||||
}
|
||||
};
|
||||
|
||||
describe('pushDispatcher — 410/404 subscription pruning', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('deletes the subscription row when the push service returns 410 (Gone)', async () => {
|
||||
const webpush = (await import('web-push')).default
|
||||
const { db } = await import('../../src/db/client.js')
|
||||
const webpush = (await import('web-push')).default;
|
||||
const { db } = await import('../../src/db/client.js');
|
||||
vi.mocked(webpush.sendNotification).mockRejectedValueOnce(
|
||||
Object.assign(new Error('Gone'), { statusCode: 410 }),
|
||||
)
|
||||
);
|
||||
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js')
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' })
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js');
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' });
|
||||
|
||||
expect(vi.mocked(db.delete)).toHaveBeenCalled()
|
||||
})
|
||||
expect(vi.mocked(db.delete)).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('deletes the subscription row when the push service returns 404 (Not Found)', async () => {
|
||||
const webpush = (await import('web-push')).default
|
||||
const { db } = await import('../../src/db/client.js')
|
||||
const webpush = (await import('web-push')).default;
|
||||
const { db } = await import('../../src/db/client.js');
|
||||
vi.mocked(webpush.sendNotification).mockRejectedValueOnce(
|
||||
Object.assign(new Error('Not Found'), { statusCode: 404 }),
|
||||
)
|
||||
);
|
||||
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js')
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' })
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js');
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' });
|
||||
|
||||
expect(vi.mocked(db.delete)).toHaveBeenCalled()
|
||||
})
|
||||
expect(vi.mocked(db.delete)).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does NOT delete the row on 201 success', async () => {
|
||||
const webpush = (await import('web-push')).default
|
||||
const { db } = await import('../../src/db/client.js')
|
||||
vi.mocked(webpush.sendNotification).mockResolvedValueOnce({ statusCode: 201, body: '', headers: {} })
|
||||
const webpush = (await import('web-push')).default;
|
||||
const { db } = await import('../../src/db/client.js');
|
||||
vi.mocked(webpush.sendNotification).mockResolvedValueOnce({
|
||||
statusCode: 201,
|
||||
body: '',
|
||||
headers: {},
|
||||
});
|
||||
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js')
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' })
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js');
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' });
|
||||
|
||||
expect(vi.mocked(db.delete)).not.toHaveBeenCalled()
|
||||
})
|
||||
expect(vi.mocked(db.delete)).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does NOT delete the row on transient 5xx error', async () => {
|
||||
const webpush = (await import('web-push')).default
|
||||
const { db } = await import('../../src/db/client.js')
|
||||
const webpush = (await import('web-push')).default;
|
||||
const { db } = await import('../../src/db/client.js');
|
||||
vi.mocked(webpush.sendNotification).mockRejectedValueOnce(
|
||||
Object.assign(new Error('Service Unavailable'), { statusCode: 503 }),
|
||||
)
|
||||
);
|
||||
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js')
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' })
|
||||
const { dispatchPush } = await import('../../src/lib/pushDispatcher.js');
|
||||
await dispatchPush(FAKE_SUB, { title: 'Test', body: 'Hello' });
|
||||
|
||||
expect(vi.mocked(db.delete)).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
expect(vi.mocked(db.delete)).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user