-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebhooksApi.test.ts
More file actions
121 lines (96 loc) · 3.27 KB
/
WebhooksApi.test.ts
File metadata and controls
121 lines (96 loc) · 3.27 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { expect, it, describe, beforeAll, jest } from '@jest/globals'
import {
assetsWebhookSchema,
createAssetsWebhookResultSchema,
workflowWebhookSchema,
listAssetsWebhooksResultSchema,
listWorkflowWebhooksResultSchema,
} from '__models__/webhooks-responses.zod'
import { WebhooksApi } from 'apis/webhooks/api'
import { ApiClient } from 'client'
let client: WebhooksApi
jest.retryTimes(3, { logErrorsBeforeRetry: true })
beforeAll(() => {
if (!process.env.API_TOKEN) {
throw new Error('API_TOKEN environment variable not set')
}
client = new WebhooksApi(new ApiClient(process.env.API_TOKEN))
})
describe('Assets Webhooks: ', () => {
const testDeliveryUrl = 'https://example.com/'
const testSecretKey = 'my_secret'
let testId: string
it('Creates a webhook', async () => {
const result = await client.createAssetsWebhook({
delivery_url: testDeliveryUrl,
event_type: 'asset_created',
})
testId = result.id
expect(() =>
createAssetsWebhookResultSchema.strict().parse(result)
).not.toThrow()
})
it('Gets a webhook configuration', async () => {
const result = await client.getAssetsWebhook(testId)
expect(() => assetsWebhookSchema.strict().parse(result)).not.toThrow()
})
it('Pings a webhook', async () => {
await expect(client.pingAssetsWebhook(testId)).resolves.not.toThrow()
})
it('Edits a webhook configuration', async () => {
await expect(
client.editAssetsWebhook({
id: testId,
delivery_enabled: false,
delivery_url: `${testDeliveryUrl}/example`,
event_type: 'asset_asset_groups_updated',
secret_key: testSecretKey,
patch: ['delivery_enabled', 'delivery_url', 'event_type', 'secret_key'],
})
).resolves.not.toThrow()
})
it('Deletes a webhook configuration', async () => {
await expect(client.deleteAssetsWebhook(testId)).resolves.not.toThrow()
})
it('Lists webhooks with no parameters set', async () => {
const result = await client.listAssetsWebhooks()
expect(() =>
listAssetsWebhooksResultSchema.strict().parse(result)
).not.toThrow()
expect(() => {
result.items.forEach((c) => assetsWebhookSchema.strict().parse(c))
}).not.toThrow()
})
it('Lists webhooks with parameters', async () => {
const result = await client.listAssetsWebhooks({
limit: 4,
offset: 1,
})
expect(() =>
listAssetsWebhooksResultSchema.strict().parse(result)
).not.toThrow()
})
})
describe('Workflow Webhooks: ', () => {
const testDeliveryUrl = 'https://example.com/'
const testEvent = 'DELIVERABLE_STATUS_CHANGED'
it('Creates and Deletes a webhook', async () => {
const result = await client.createWorkflowWebhook({
event: testEvent,
target: testDeliveryUrl,
})
expect(() => workflowWebhookSchema.strict().parse(result)).not.toThrow()
})
it('Deletes a webhook', async () => {
await expect(client.deleteWorkflowWebhook(testEvent)).resolves.not.toThrow()
})
it('Lists webhooks', async () => {
const result = await client.listWorkflowWebhooks()
expect(() =>
listWorkflowWebhooksResultSchema.strict().parse(result)
).not.toThrow()
expect(() => {
result.items.forEach((c) => workflowWebhookSchema.strict().parse(c))
}).not.toThrow()
})
})