Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3be84b4

Browse files
committed
test push notifications endpoint
1 parentfa6ea36 commit3be84b4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

‎coderd/notifications_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ func TestPushNotificationSubscription(t *testing.T) {
412412
require.NoError(t,err,"create notification push subscription")
413413
require.True(t,<-handlerCalled,"handler should have been called")
414414

415+
err=memberClient.TestPushNotification(ctx)
416+
require.NoError(t,err,"test push notification")
417+
require.True(t,<-handlerCalled,"handler should have been called again")
418+
415419
err=memberClient.DeleteNotificationPushSubscription(ctx,"me", codersdk.DeletePushNotificationSubscription{
416420
Endpoint:server.URL,
417421
})

‎codersdk/deployment.go‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,12 @@ type NotificationsConfig struct {
700700
WebhookNotificationsWebhookConfig`json:"webhook" typescript:",notnull"`
701701
// Inbox settings.
702702
InboxNotificationsInboxConfig`json:"inbox" typescript:",notnull"`
703+
// Push notification settings.
704+
PushNotificationsPushConfig`json:"push" typescript:",notnull"`
705+
}
706+
707+
typeNotificationsPushConfigstruct {
708+
Enabled serpent.Bool`json:"enabled" typescript:",notnull"`
703709
}
704710

705711
// Are either of the notification methods enabled?
@@ -1001,6 +1007,11 @@ func (c *DeploymentValues) Options() serpent.OptionSet {
10011007
Parent:&deploymentGroupNotifications,
10021008
YAML:"inbox",
10031009
}
1010+
deploymentGroupNotificationsPush= serpent.Group{
1011+
Name:"Push",
1012+
Parent:&deploymentGroupNotifications,
1013+
YAML:"push",
1014+
}
10041015
)
10051016

10061017
httpAddress:= serpent.Option{
@@ -2968,6 +2979,17 @@ Write out the current server config as YAML to stdout.`,
29682979
Annotations: serpent.Annotations{}.Mark(annotationFormatDuration,"true"),
29692980
Hidden:true,// Hidden because most operators should not need to modify this.
29702981
},
2982+
// Push notifications.
2983+
{
2984+
Name:"Notifications: Push: Enabled",
2985+
Description:"Enable push notifications using VAPID.",
2986+
Flag:"notifications-push-enabled",
2987+
Env:"CODER_NOTIFICATIONS_PUSH_ENABLED",
2988+
Value:&c.Notifications.Push.Enabled,
2989+
Default:"false",
2990+
Group:&deploymentGroupNotificationsPush,
2991+
YAML:"enabled",
2992+
},
29712993
}
29722994

29732995
returnopts

‎codersdk/notifications.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,19 @@ func (c *Client) DeleteNotificationPushSubscription(ctx context.Context, user st
265265
}
266266
returnnil
267267
}
268+
269+
func (c*Client)TestPushNotification(ctx context.Context)error {
270+
res,err:=c.Request(ctx,http.MethodPost,fmt.Sprintf("/api/v2/users/%s/notifications/push/test",Me),PushNotification{
271+
Title:"It's working!",
272+
Body:"You've subscribed to push notifications.",
273+
})
274+
iferr!=nil {
275+
returnerr
276+
}
277+
deferres.Body.Close()
278+
279+
ifres.StatusCode!=http.StatusNoContent {
280+
returnReadBodyAsError(res)
281+
}
282+
returnnil
283+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp