Skip to content

Commit 5bf4e0f

Browse files
authored
feat(NOJIRA-123): Add Webhook toggle funcion (#74)
* Add a way to toggle webhook Just a simple function to toggle enable on a webhook * Update webhooks.test.ts * Update README.md
1 parent c48541f commit 5bf4e0f

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ Each one of them encapsulates the operations related to it (like listing, updati
340340
- `secret`: If specified, will be used to sign the webhook payload with HMAC SHA256, so that you can verify that it came from Typeform.
341341
- `verifySSL`: `true` if you want Typeform to verify SSL certificates when delivering payloads.
342342

343+
#### `webhooks.toggle({ uid, tag, enabled })`
344+
345+
- Turn on or off a webhook.
346+
- `uid`: Unique ID for the form.
347+
- `tag`: tag of the webhook created.
348+
- `enabled`: `true` or `false`.
349+
343350
## Examples
344351

345352
### Update specific typeform property, as [referenced here](https://developer.typeform.com/create/reference/update-form-patch/)

src/webhooks.ts

+12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ export class Webhooks {
4040
url: `/forms/${uid}/webhooks`,
4141
})
4242
}
43+
44+
public toggle (args: { uid: string, tag: string, enabled: boolean }): Promise<Typeform.API.Webhooks.List> {
45+
const { uid, tag, enabled } = args
46+
47+
return this._http.request({
48+
method: 'put',
49+
url: `/forms/${uid}/webhooks/${tag}`,
50+
data: {
51+
enabled
52+
}
53+
})
54+
}
4355

4456
update(args: {
4557
uid: string

tests/unit/webhooks.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,19 @@ test('Delete a webhook has the correct path and method', async () => {
6363
)
6464
expect(axios.history.delete[0].method).toBe('delete')
6565
})
66+
67+
test('toggle(false) Disable a webhook', async () => {
68+
await webhooksRequest.toggle({ uid: '2', tag: 'test', enabled: false })
69+
const bodyParsed = JSON.parse(axios.history.put[0].data)
70+
expect(axios.history.put[0].method).toBe('put')
71+
expect(axios.history.put[0].url).toBe(`${API_BASE_URL}/forms/2/webhooks/test`)
72+
expect(bodyParsed.enabled).toBe(false)
73+
})
74+
75+
test('toggle(true) Enable a webhook', async () => {
76+
await webhooksRequest.toggle({ uid: '2', tag: 'test', enabled: true })
77+
const bodyParsed = JSON.parse(axios.history.put[0].data)
78+
expect(axios.history.put[0].method).toBe('put')
79+
expect(axios.history.put[0].url).toBe(`${API_BASE_URL}/forms/2/webhooks/test`)
80+
expect(bodyParsed.enabled).toBe(true)
81+
})

0 commit comments

Comments
 (0)