feat(referrals): partition key migration to /referrerId with dual-write backfill
This commit is contained in:
parent
3e05260a6f
commit
770bc5ae51
@ -104,7 +104,7 @@ describe('webhooks', () => {
|
|||||||
|
|
||||||
describe('triggerJobWebhook', () => {
|
describe('triggerJobWebhook', () => {
|
||||||
it('delivers webhook successfully', async () => {
|
it('delivers webhook successfully', async () => {
|
||||||
global.fetch = vi.fn().mockResolvedValue({
|
globalThis.fetch = vi.fn().mockResolvedValue({
|
||||||
ok: true,
|
ok: true,
|
||||||
status: 200,
|
status: 200,
|
||||||
});
|
});
|
||||||
@ -128,7 +128,7 @@ describe('webhooks', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('records delivery on failure', async () => {
|
it('records delivery on failure', async () => {
|
||||||
global.fetch = vi.fn().mockRejectedValue(new Error('Network error'));
|
globalThis.fetch = vi.fn().mockRejectedValue(new Error('Network error'));
|
||||||
|
|
||||||
await triggerJobWebhook(mockJob, mockConfig);
|
await triggerJobWebhook(mockJob, mockConfig);
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ describe('webhooks', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('includes correct signature in request', async () => {
|
it('includes correct signature in request', async () => {
|
||||||
global.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
globalThis.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
||||||
|
|
||||||
await triggerJobWebhook(mockJob, mockConfig);
|
await triggerJobWebhook(mockJob, mockConfig);
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ describe('webhooks', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('accurately counts delivery statuses', async () => {
|
it('accurately counts delivery statuses', async () => {
|
||||||
global.fetch = vi.fn()
|
globalThis.fetch = vi.fn()
|
||||||
.mockResolvedValueOnce({ ok: true, status: 200 })
|
.mockResolvedValueOnce({ ok: true, status: 200 })
|
||||||
.mockRejectedValueOnce(new Error('Failed'));
|
.mockRejectedValueOnce(new Error('Failed'));
|
||||||
|
|
||||||
@ -183,14 +183,14 @@ describe('webhooks', () => {
|
|||||||
describe('retryWebhookDelivery', () => {
|
describe('retryWebhookDelivery', () => {
|
||||||
it('retries failed delivery successfully', async () => {
|
it('retries failed delivery successfully', async () => {
|
||||||
// First, make all fetch calls fail (for initial trigger with retries)
|
// First, make all fetch calls fail (for initial trigger with retries)
|
||||||
global.fetch = vi.fn().mockRejectedValue(new Error('Persistent failure'));
|
globalThis.fetch = vi.fn().mockRejectedValue(new Error('Persistent failure'));
|
||||||
|
|
||||||
await triggerJobWebhook(mockJob, mockConfig);
|
await triggerJobWebhook(mockJob, mockConfig);
|
||||||
const delivery = listJobDeliveries('job-123')[0];
|
const delivery = listJobDeliveries('job-123')[0];
|
||||||
expect(delivery.status).toBe('failed');
|
expect(delivery.status).toBe('failed');
|
||||||
|
|
||||||
// Now set up mock to succeed for the retry
|
// Now set up mock to succeed for the retry
|
||||||
global.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
globalThis.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
||||||
|
|
||||||
const retried = await retryWebhookDelivery(delivery.id, mockJob, mockConfig);
|
const retried = await retryWebhookDelivery(delivery.id, mockJob, mockConfig);
|
||||||
expect(retried).toBe(true);
|
expect(retried).toBe(true);
|
||||||
@ -207,7 +207,7 @@ describe('webhooks', () => {
|
|||||||
|
|
||||||
describe('listJobDeliveries', () => {
|
describe('listJobDeliveries', () => {
|
||||||
it('returns deliveries sorted by creation time', async () => {
|
it('returns deliveries sorted by creation time', async () => {
|
||||||
global.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
globalThis.fetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
|
||||||
|
|
||||||
const job1 = { ...mockJob, id: 'job-1' };
|
const job1 = { ...mockJob, id: 'job-1' };
|
||||||
const job2 = { ...mockJob, id: 'job-2' };
|
const job2 = { ...mockJob, id: 'job-2' };
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Fastify from 'fastify';
|
import Fastify from 'fastify';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
|
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
const migrationRepoMock = {
|
const migrationRepoMock = {
|
||||||
|
|||||||
@ -377,11 +377,12 @@ export async function backfillOldToNew(
|
|||||||
|
|
||||||
await newCollection().create(doc);
|
await newCollection().create(doc);
|
||||||
result.migrated++;
|
result.migrated++;
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
if (err.code === 409) {
|
const error = err as { code?: number; message?: string };
|
||||||
|
if (error.code === 409) {
|
||||||
result.skipped++;
|
result.skipped++;
|
||||||
} else {
|
} else {
|
||||||
result.errors.push(`Doc ${doc.id}: ${err.message}`);
|
result.errors.push(`Doc ${doc.id}: ${error.message ?? String(err)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user