Files
TREK/shared/src/notification/notification.schema.spec.ts
T
Maurice fb36ae5678 Format the shared package and drop an unused import to satisfy the lint gate
The i18n and schema changes added code that wasn't prettier-formatted, and place.schema.ts imported categorySchema without using it. Run prettier over shared and remove the import so 'npm run lint' + 'format:check' pass.
2026-05-31 20:22:54 +02:00

60 lines
1.6 KiB
TypeScript

import {
preferencesUpdateRequestSchema,
notificationRespondRequestSchema,
channelTestResultSchema,
inAppListResultSchema,
} from './notification.schema';
import { describe, it, expect } from 'vitest';
describe('preferencesUpdateRequestSchema', () => {
it('accepts a nested event/channel/enabled matrix', () => {
expect(
preferencesUpdateRequestSchema.safeParse({
trip_invite: { inapp: true, email: false },
}).success,
).toBe(true);
expect(
preferencesUpdateRequestSchema.safeParse({
trip_invite: { inapp: 'yes' },
}).success,
).toBe(false);
});
});
describe('notificationRespondRequestSchema', () => {
it('only accepts positive/negative', () => {
expect(
notificationRespondRequestSchema.safeParse({ response: 'positive' })
.success,
).toBe(true);
expect(
notificationRespondRequestSchema.safeParse({ response: 'maybe' }).success,
).toBe(false);
});
});
describe('channelTestResultSchema', () => {
it('accepts a success result and an error result', () => {
expect(channelTestResultSchema.safeParse({ success: true }).success).toBe(
true,
);
expect(
channelTestResultSchema.safeParse({ success: false, error: 'SMTP down' })
.success,
).toBe(true);
});
});
describe('inAppListResultSchema', () => {
it('accepts the list envelope with open notification rows', () => {
expect(
inAppListResultSchema.safeParse({
notifications: [{ id: 1, type: 'info', anything: 'goes' }],
total: 1,
unread_count: 0,
}).success,
).toBe(true);
});
});