File size: 1,631 Bytes
cb43fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
  });
});