MCPcopy Index your code
hub / github.com/coder/coder / TestDeleteWebpushSubscription

Function TestDeleteWebpushSubscription

coderd/webpush_test.go:219–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

217}
218
219func TestDeleteWebpushSubscription(t *testing.T) {
220 t.Parallel()
221
222 t.Run("database error returns 500", func(t *testing.T) {
223 t.Parallel()
224
225 ctx := testutil.Context(t, testutil.WaitMedium)
226
227 store, ps := dbtestutil.NewDB(t)
228 wrappedStore := &testWebpushErrorStore{Store: store}
229
230 client := coderdtest.New(t, &coderdtest.Options{
231 Database: wrappedStore,
232 Pubsub: ps,
233 })
234 owner := coderdtest.CreateFirstUser(t, client)
235 memberClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
236
237 // Inject a database error into
238 // GetWebpushSubscriptionsByUserID. The handler should
239 // return 500, not mask the error as 404.
240 dbErr := xerrors.New("database is unavailable")
241 wrappedStore.getWebpushSubscriptionsErr.Store(&dbErr)
242
243 err := memberClient.DeleteWebpushSubscription(ctx, "me", codersdk.DeleteWebpushSubscription{
244 Endpoint: "https://push.example.com/test",
245 })
246 var sdkError *codersdk.Error
247 require.Error(t, err)
248 require.ErrorAsf(t, err, &sdkError, "error should be of type *codersdk.Error")
249 require.Equal(t, http.StatusInternalServerError, sdkError.StatusCode(), "database errors should return 500, not be masked as 404")
250 })
251}

Callers

nothing calls this directly

Calls 12

StatusCodeMethod · 0.95
ContextFunction · 0.92
NewDBFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RunMethod · 0.65
NewMethod · 0.65
StoreMethod · 0.45
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected