Skip to content

Commit c8ab1e2

Browse files
committed
feat: Add delete webhook functionality
1 parent 07a4500 commit c8ab1e2

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/webhooks.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@ export const getWebhook = (http, { uid, tag }) => {
99
})
1010
}
1111

12-
export const createWebhook = (http, { uid, tag, url, enable = false }) => {
12+
export const createWebhook = (http, args) => {
13+
return createOrUpdateWebhook(http, args)
14+
}
15+
16+
export const updateWebhook = (http, args) => {
17+
return createOrUpdateWebhook(http, args)
18+
}
19+
20+
export const deleteWebhook = (http, { uid, tag }) => {
21+
return http.request({
22+
method: 'delete',
23+
url: `/forms/${uid}/webhooks/${tag}`
24+
})
25+
}
26+
27+
export const createOrUpdateWebhook = (
28+
http,
29+
{ uid, tag, url, enable = false }
30+
) => {
1331
if (url === undefined) {
1432
throw `Please provide an url for ${tag}`
1533
}

tests/unit/webhooks.test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import axios from 'axios'
22

33
import { stub, spy } from 'sinon'
4-
import { getWebhook, createWebhook } from '../../src/webhooks'
4+
import {
5+
getWebhook,
6+
createOrUpdateWebhook,
7+
deleteWebhook
8+
} from '../../src/webhooks'
59

610
beforeEach(() => {
711
stub(axios, 'request').returns({})
@@ -18,7 +22,7 @@ test('List webhooks has the correct path and method', () => {
1822
})
1923

2024
test('Create a new webhooks has the correct path and method', () => {
21-
createWebhook(axios, {
25+
createOrUpdateWebhook(axios, {
2226
uid: 2,
2327
tag: 'test',
2428
url: 'http://test.com',
@@ -29,10 +33,20 @@ test('Create a new webhooks has the correct path and method', () => {
2933
})
3034

3135
test('Create a new webhooks requires a url', () => {
32-
expect(() => createWebhook(axios, { uid: 2, tag: 'test' })).toThrow()
36+
expect(() => createOrUpdateWebhook(axios, { uid: 2, tag: 'test' })).toThrow()
3337
})
3438

3539
test('Create a new webhooks sends the correct payload', () => {
36-
createWebhook(axios, { uid: 2, tag: 'test', url: 'http://example.com' })
40+
createOrUpdateWebhook(axios, {
41+
uid: 2,
42+
tag: 'test',
43+
url: 'http://example.com'
44+
})
3745
expect(axios.request.args[0][0].data.url).toBe('http://example.com')
3846
})
47+
48+
test('Delete a webhook has the correct path and method', () => {
49+
deleteWebhook(axios, { uid: 2, tag: 'test' })
50+
expect(axios.request.args[0][0].method).toBe('delete')
51+
expect(axios.request.args[0][0].url).toBe('/forms/2/webhooks/test')
52+
})

0 commit comments

Comments
 (0)