Skip to content

Test database business logic #14098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use PUT since this endpoint is idempotent
Signed-off-by: Danny Kopping <danny@coder.com>
  • Loading branch information
dannykopping committed Aug 1, 2024
commit 44a700b06240b48c1e6af7d1c15e5099c8707e8b
2 changes: 1 addition & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ func New(options *Options) *API {
r.Get("/settings", api.notificationsSettings)
r.Put("/settings", api.putNotificationsSettings)
r.Route("/templates", func(r chi.Router) {
r.Get("/system", api.getSystemNotificationTemplates)
r.Get("/system", api.systemNotificationTemplates)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion coderd/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
// @Tags Notifications
// @Success 200 {array} codersdk.NotificationTemplate
// @Router /notifications/templates/system [get]
func (api *API) getSystemNotificationTemplates(rw http.ResponseWriter, r *http.Request) {
func (api *API) systemNotificationTemplates(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

templates, err := api.Database.GetNotificationTemplatesByKind(ctx, database.NotificationTemplateKindSystem)
Expand Down
2 changes: 1 addition & 1 deletion codersdk/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Client) PutNotificationsSettings(ctx context.Context, settings Notifica
// UpdateNotificationTemplateMethod modifies a notification template to use a specific notification method, overriding
// the method set in the deployment configuration.
func (c *Client) UpdateNotificationTemplateMethod(ctx context.Context, notificationTemplateId uuid.UUID, method string) error {
res, err := c.Request(ctx, http.MethodPost,
res, err := c.Request(ctx, http.MethodPut,
fmt.Sprintf("/api/v2/notifications/templates/%s/method", notificationTemplateId),
UpdateNotificationTemplateMethod{Method: method},
)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/enterprise.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
apiKeyMiddleware,
httpmw.RequireExperiment(api.AGPL.Experiments, codersdk.ExperimentNotifications),
httpmw.ExtractNotificationTemplateParam(options.Database),
).Post("/notifications/templates/{notification_template}/method", api.updateNotificationTemplateMethod)
).Put("/notifications/templates/{notification_template}/method", api.updateNotificationTemplateMethod)
})

if len(options.SCIMAPIKey) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// @Produce json
// @Tags Enterprise
// @Success 200
// @Router /notifications/templates/{notification_template}/method [post]
// @Router /notifications/templates/{notification_template}/method [put]
func (api *API) updateNotificationTemplateMethod(rw http.ResponseWriter, r *http.Request) {
// TODO: authorization (restrict to admin/template admin?)
var (
Expand Down
55 changes: 0 additions & 55 deletions enterprise/coderd/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,61 +148,6 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
require.NotNil(t, template)
require.Equal(t, method, template.Method)
})

// t.Run("Settings modified", func(t *testing.T) {
// t.Parallel()
//
// client := coderdtest.New(t, nil)
// _ = coderdtest.CreateFirstUser(t, client)
//
// // given
// expected := codersdk.NotificationsSettings{
// NotifierPaused: true,
// }
//
// ctx := testutil.Context(t, testutil.WaitShort)
//
// // when
// err := client.PutNotificationsSettings(ctx, expected)
// require.NoError(t, err)
//
// // then
// actual, err := client.GetNotificationsSettings(ctx)
// require.NoError(t, err)
// require.Equal(t, expected, actual)
// })
//
// t.Run("Settings not modified", func(t *testing.T) {
// t.Parallel()
//
// // Empty state: notifications Settings are undefined now (default).
// client := coderdtest.New(t, nil)
// _ = coderdtest.CreateFirstUser(t, client)
// ctx := testutil.Context(t, testutil.WaitShort)
//
// // Change the state: pause notifications
// err := client.PutNotificationsSettings(ctx, codersdk.NotificationsSettings{
// NotifierPaused: true,
// })
// require.NoError(t, err)
//
// // Verify the state: notifications are paused.
// actual, err := client.GetNotificationsSettings(ctx)
// require.NoError(t, err)
// require.True(t, actual.NotifierPaused)
//
// // Change the stage again: notifications are paused.
// expected := actual
// err = client.PutNotificationsSettings(ctx, codersdk.NotificationsSettings{
// NotifierPaused: true,
// })
// require.NoError(t, err)
//
// // Verify the state: notifications are still paused, and there is no error returned.
// actual, err = client.GetNotificationsSettings(ctx)
// require.NoError(t, err)
// require.Equal(t, expected.NotifierPaused, actual.NotifierPaused)
// })
}

func getTemplateById(t *testing.T, ctx context.Context, api *codersdk.Client, id uuid.UUID) (*codersdk.NotificationTemplate, error) {
Expand Down