Skip to content

Commit 6e348fc

Browse files
committed
Add conversation create test for non-429 error
1 parent f80e8f6 commit 6e348fc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/utils/createConversation.util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ export const createConversation = async (options: SessionPostBody) : Promise<Con
88

99
return retry(async (quit) => {
1010
try {
11-
const conversation = await client.conversations.conversations.create(options);
12-
return conversation;
11+
return client.conversations.conversations.create(options);
1312
} catch (err) {
1413
if (err.status !== 429) {
14+
console.log('Quit without retry')
1515
console.log(err)
1616
quit(new Error('Quit without retry'));
1717
return;

tests/utils/createConversation.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,34 @@ describe('createConversation util', () => {
1010
})
1111

1212
it('it creates conversation with options passed', async () => {
13-
const createSpy = jest.fn((options) => {})
13+
const createSpy = jest.fn((options) => { return options })
1414
mockedClient['conversations'] = {
1515
conversations: {
1616
create: (options) => createSpy(options)
1717
}
1818
} as any
1919

20-
createConversation({ friendlyName: "my conversation", addresses: ['1', '2'] })
20+
const result = await createConversation({ friendlyName: "my conversation", addresses: ['1', '2'] })
2121

2222
expect(createSpy).toBeCalledWith({ friendlyName: "my conversation", addresses: ['1', '2'] })
23+
expect(result).toEqual({ friendlyName: "my conversation", addresses: ['1', '2'] })
2324
})
2425

2526
it('calls quit if error is not a 429 retry', async () => {
26-
27+
mockedClient['conversations'] = {
28+
conversations: {
29+
create: (options) => {
30+
throw new Error('Twilio Problem')
31+
}
32+
}
33+
} as any
34+
35+
const consoleSpy = jest.spyOn(console, 'log');
36+
37+
try {
38+
await createConversation({ friendlyName: "my conversation", addresses: ['1', '2'] });
39+
} catch (e) {
40+
expect(consoleSpy).toHaveBeenCalledWith('Quit without retry');
41+
}
2742
})
2843
})

0 commit comments

Comments
 (0)