-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsns-message-publisher.test.ts
52 lines (49 loc) · 1.29 KB
/
sns-message-publisher.test.ts
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
import type { SNSClient } from '@aws-sdk/client-sns'
import assert from 'node:assert'
import { describe, it, mock } from 'node:test'
import { SnsMessagePublisher } from './sns-message-publisher.ts'
const maxRetryAttempts = 3
void describe('SnsMessagePublisher', () => {
void it('should publish messages', async () => {
const mockSend = mock.fn<SNSClient['send']>(async () => Promise.resolve({}))
const messagePublisher = new SnsMessagePublisher(
'SomeTopicArn',
'SomeMessageAttribute',
undefined,
undefined,
{
send: mockSend,
} as any,
() => undefined,
)
const messages = [
{ id: 'A', value: 1 },
{ id: 'B', value: 2 },
]
await messagePublisher.publish(...messages)
assert.equal(mockSend.mock.callCount(), 1)
})
void it('should retry publishing on error', async () => {
const mockSend = mock.fn<SNSClient['send']>(async () =>
Promise.reject(new Error('SomeError')),
)
const messagePublisher = new SnsMessagePublisher(
'SomeTopicArn',
'SomeMessageAttribute',
undefined,
undefined,
{
send: mockSend,
} as any,
() => undefined,
)
const messages = [
{ id: 'A', value: 1 },
{ id: 'B', value: 2 },
]
try {
await messagePublisher.publish(...messages)
} catch {}
assert.equal(mockSend.mock.callCount(), maxRetryAttempts)
})
})