-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathemail-callbacks.models.test.ts
More file actions
83 lines (78 loc) · 2.49 KB
/
email-callbacks.models.test.ts
File metadata and controls
83 lines (78 loc) · 2.49 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type { EmailCallback } from './email-callbacks.types';
import { describe, expect, test } from 'vitest';
import { formatEmailCallbackForApi, parseEmailAddress } from './email-callbacks.models';
describe('email-callbacks models', () => {
describe('formatEmailCallbackForApi', () => {
test('the webhook secret should not be disclosed, so it is replaced with fixed asterisks', () => {
const emailCallback: EmailCallback = {
id: '1',
username: 'test',
domain: 'test.com',
webhookUrl: 'https://example.com/webhook',
webhookSecret: '1234567890',
allowedOrigins: [],
isEnabled: true,
createdAt: new Date('2025-01-01'),
updatedAt: new Date('2025-01-01'),
userId: '1',
};
expect(formatEmailCallbackForApi({ emailCallback })).to.deep.equal({
id: '1',
username: 'test',
domain: 'test.com',
webhookUrl: 'https://example.com/webhook',
hasWebhookSecret: true,
allowedOrigins: [],
isEnabled: true,
createdAt: new Date('2025-01-01'),
updatedAt: new Date('2025-01-01'),
userId: '1',
});
});
test('the webhook secret is not redacted if it is not set', () => {
expect(
formatEmailCallbackForApi({ emailCallback: {
id: '1',
username: 'test',
domain: 'test.com',
webhookUrl: 'https://example.com/webhook',
webhookSecret: null,
allowedOrigins: [],
isEnabled: true,
createdAt: new Date('2025-01-01'),
updatedAt: new Date('2025-01-01'),
userId: '1',
} }),
).to.deep.equal({
id: '1',
username: 'test',
domain: 'test.com',
webhookUrl: 'https://example.com/webhook',
hasWebhookSecret: false,
allowedOrigins: [],
isEnabled: true,
createdAt: new Date('2025-01-01'),
updatedAt: new Date('2025-01-01'),
userId: '1',
});
});
});
describe('parseEmailAddress', () => {
test('extracts the username, domain and extra from an email address', () => {
expect(
parseEmailAddress({ emailAddress: 'test+extra@test.com' }),
).to.deep.equal({
username: 'test',
domain: 'test.com',
extra: 'extra',
});
expect(
parseEmailAddress({ emailAddress: 'test@test.com' }),
).to.deep.equal({
username: 'test',
domain: 'test.com',
extra: undefined,
});
});
});
});