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

feat: add template delete notification#14250

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 13 commits intomainfrombq/notify-template-delete
Aug 14, 2024

Conversation

BrunoQuaresma
Copy link
Collaborator

Preview:
Screenshot 2024-08-12 at 15 54 29

Related to:coder/internal#16

Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

Looking good, but we need to send to all template admins & owners.

BrunoQuaresma reacted with thumbs up emoji
Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

Almost there 👍

require.NoError(t, err)

// Then: the template owners and template admins should receive the notification
shouldBeNotified := []uuid.UUID{anotherOwner.ID, tmplAdmin.ID}
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 it'd be good to explicitly specify that the first user is not receiving the notification because they initiated it.

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 it'd also be a good idea here to create another admin but with a different role likeuser admin, and validate that they don't receive the notification either.

BrunoQuaresma reacted with thumbs up emoji
func TestNotifyDeletedTemplate(t *testing.T) {
t.Parallel()

t.Run("OnlyNotifyOwnersAndTemplateAdmins", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a separate test to validate the functionality in isolation; you can then reduce some complexity in this test and keep it nicely scoped.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Not sure if I got it. What should I separate and what complexity does it solve?

Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

Almost there! Thanks for taking the feedback onboard so well

@@ -1334,9 +1334,50 @@ func TestTemplateNotifications(t *testing.T) {
t.Run("Delete", func(t *testing.T) {
t.Parallel()

t.Run("SendNotification", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now this is a great test! Needs a little work but it's very nice.
Doesn't this feel better to read now?

BrunoQuaresma reacted with heart emoji
_, anotherOwner := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID, rbac.RoleOwner())
_, tmplAdmin := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID, rbac.RoleTemplateAdmin())
coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID, rbac.RoleMember())
coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID, rbac.RoleUserAdmin())

// When: template is deleted
// When:thetemplate is deleted by the owner
Copy link
Contributor

Choose a reason for hiding this comment

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

Which owner? You have the first user, which is performing this action, andanotherOwner.

Suggested change
// When: the template is deleted bythe owner
// When: the template is deleted byfirstUser

BrunoQuaresma reacted with thumbs up emoji
Comment on lines 1362 to 1374
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.

BrunoQuaresma reacted with thumbs up emoji
t.Run("Delete", func(t *testing.T) {
t.Parallel()

t.Run("SendNotification", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
t.Run("SendNotification",func(t*testing.T) {
t.Run("InitiatorIsNotNotified",func(t*testing.T) {

BrunoQuaresma reacted with thumbs up emoji
@BrunoQuaresmaBrunoQuaresma merged commit6f1951e intomainAug 14, 2024
27 checks passed
@BrunoQuaresmaBrunoQuaresma deleted the bq/notify-template-delete branchAugust 14, 2024 17:22
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 14, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@dannykoppingdannykoppingdannykopping approved these changes

Assignees

@BrunoQuaresmaBrunoQuaresma

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@BrunoQuaresma@dannykopping

[8]ページ先頭

©2009-2025 Movatter.jp