Skip to content

Commit 4db8e84

Browse files
committed
Test Update/Delete/List for webhooks
1 parent 5af711b commit 4db8e84

File tree

7 files changed

+104
-1
lines changed

7 files changed

+104
-1
lines changed

src/Share/Notifications/Ops.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,13 @@ deleteProjectWebhook projectId subscriptionId = do
159159
let owner = ProjectSubscriptionOwner projectId
160160
-- First fetch the webhook id associated with this subscription
161161
webhooks <- PG.runTransaction $ do NotifQ.webhooksForSubscription subscriptionId
162+
-- Next delete the subscription, which cascades to delete the webhook rows.
163+
PG.runTransaction $ do NotifQ.deleteNotificationSubscription owner subscriptionId
164+
-- Now delete the webhook configs in Vault, it's possible that this fails, but
165+
-- it's okay if there are dangling webhooks in vault, we can't be fully transactional here,
166+
-- and it's better than having rows that point to missing secrets.
162167
for_ webhooks \webhookId -> do
163168
deleteWebhookDeliveryMethod owner webhookId
164-
PG.runTransaction $ do NotifQ.deleteNotificationSubscription owner subscriptionId
165169

166170
updateProjectWebhook :: SubscriptionOwner -> NotificationSubscriptionId -> Maybe URIParam -> (Maybe ProjectWebhookTopics) -> WebApp ()
167171
updateProjectWebhook subscriptionOwner subscriptionId mayURIUpdate webhookTopics = do
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"body": [],
3+
"status": [
4+
{
5+
"status_code": 200
6+
}
7+
]
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"body": {
3+
"webhooks": []
4+
},
5+
"status": [
6+
{
7+
"status_code": 200
8+
}
9+
]
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"body": {
3+
"webhooks": [
4+
{
5+
"createdAt": "<TIMESTAMP>",
6+
"notificationSubscriptionId": "NS-<UUID>",
7+
"topics": {
8+
"topics": [
9+
"project:contribution:created"
10+
],
11+
"type": "selected"
12+
},
13+
"updatedAt": "<TIMESTAMP>",
14+
"uri": "http://<HOST>:9999/good-webhook-updated"
15+
}
16+
]
17+
},
18+
"status": [
19+
{
20+
"status_code": 200
21+
}
22+
]
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"body": {
3+
"webhooks": [
4+
{
5+
"createdAt": "<TIMESTAMP>",
6+
"notificationSubscriptionId": "NS-<UUID>",
7+
"topics": {
8+
"type": "all"
9+
},
10+
"updatedAt": "<TIMESTAMP>",
11+
"uri": "http://<HOST>:9999/good-webhook"
12+
}
13+
]
14+
},
15+
"status": [
16+
{
17+
"status_code": 200
18+
}
19+
]
20+
}

transcripts/share-apis/notifications/run.zsh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ fetch "$test_user" POST add-project-webhook "/users/test/projects/publictestproj
1616
\"topics\": {\"type\": \"all\"}
1717
}"
1818

19+
fetch "$test_user" GET list-project-webhooks "/users/test/projects/publictestproject/webhooks"
20+
1921
# Subscribe the transcripts user to notifications for a project in the test user.
2022
fetch "$transcripts_user" PUT subscribe-to-other-user-project '/users/test/projects/publictestproject/subscription' '{
2123
"isSubscribed": true
@@ -132,3 +134,18 @@ echo "Successful webhooks: $successful_webhooks\nUnsuccessful webhooks: $unsucce
132134
fetch "$test_user" PUT unsubscribe-from-project '/users/test/projects/publictestproject/subscription' '{
133135
"isSubscribed": false
134136
}'
137+
138+
# Get the project webhook id.
139+
project_webhook_id=$(fetch_data_jq "$test_user" GET project-webhooks-fetch '/users/test/projects/publictestproject/webhooks' '.webhooks[0].notificationSubscriptionId')
140+
141+
# Can update project webhooks
142+
fetch "$test_user" PATCH update-project-webhook "/users/test/projects/publictestproject/webhooks/$project_webhook_id" "{
143+
\"uri\": \"${echo_server}/good-webhook-updated\",
144+
\"topics\": {\"type\": \"selected\", \"topics\": [\"project:contribution:created\"]}
145+
}"
146+
147+
fetch "$test_user" GET list-project-webhooks-after-update "/users/test/projects/publictestproject/webhooks"
148+
149+
fetch "$test_user" DELETE delete-project-webhook "/users/test/projects/publictestproject/webhooks/$project_webhook_id"
150+
151+
fetch "$test_user" GET list-project-webhooks-after-delete "/users/test/projects/publictestproject/webhooks"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"body": {
3+
"webhook": {
4+
"createdAt": "<TIMESTAMP>",
5+
"notificationSubscriptionId": "NS-<UUID>",
6+
"topics": {
7+
"topics": [
8+
"project:contribution:created"
9+
],
10+
"type": "selected"
11+
},
12+
"updatedAt": "<TIMESTAMP>",
13+
"uri": "http://<HOST>:9999/good-webhook-updated"
14+
}
15+
},
16+
"status": [
17+
{
18+
"status_code": 200
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)