Skip to content
Merged
Prev Previous commit
Next Next commit
Filter delete notifications
  • Loading branch information
BrunoQuaresma committed Aug 14, 2024
commit 92c11deb5e777557e15577c48b54e5bb57343294
20 changes: 13 additions & 7 deletions coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,19 @@ func TestTemplateNotifications(t *testing.T) {
// Then: verify that the notification is sent to the correct user
// (template admin) and targets, using the appropriate labels. Note that
// the owner, being the initiator, will not receive the notification.
require.Len(t, notifyEnq.Sent, 1)
require.Contains(t, notifyEnq.Sent[0].TemplateID, notifications.TemplateTemplateDeleted)
require.Contains(t, notifyEnq.Sent[0].UserID, templateAdmin.ID)
require.Contains(t, notifyEnq.Sent[0].Targets, template.ID)
require.Contains(t, notifyEnq.Sent[0].Targets, template.OrganizationID)
require.Equal(t, notifyEnq.Sent[0].Labels["name"], template.Name)
require.Equal(t, notifyEnq.Sent[0].Labels["initiator"], coderdtest.FirstUserParams.Username)
deleteNotifications := make([]*testutil.Notification, 0)
for _, n := range notifyEnq.Sent {
if n.TemplateID == notifications.TemplateTemplateDeleted {
deleteNotifications = append(deleteNotifications, n)
}
}
require.Len(t, deleteNotifications, 1)
require.Contains(t, deleteNotifications[0].TemplateID, notifications.TemplateTemplateDeleted)
require.Contains(t, deleteNotifications[0].UserID, templateAdmin.ID)
require.Contains(t, deleteNotifications[0].Targets, template.ID)
require.Contains(t, deleteNotifications[0].Targets, template.OrganizationID)
require.Equal(t, deleteNotifications[0].Labels["name"], template.Name)
require.Equal(t, deleteNotifications[0].Labels["initiator"], coderdtest.FirstUserParams.Username)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could simplify this to show that the notification is not received at all in this test if there's only one owner.
In the other test you're checking for exactly the same thing.
Tests should validate one (or as close to one) aspect of business logic at a time, IMHO.

})

t.Run("OnlyNotifyOwnersAndTemplateAdmins", func(t *testing.T) {
Expand Down
Loading