-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add User Tier context to Notification Builder (#425)
* Add User Tier context to Notificatoin Builder
- Loading branch information
1 parent
2184e62
commit 6a52cb3
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,45 @@ func TestNotificationBuilder(t *testing.T) { | |
assert.Equal(t, "bar", notification.Spec.Context["foo"]) | ||
}) | ||
|
||
t.Run("success with user tier", func(t *testing.T) { | ||
tests := map[string]struct { | ||
daysInTier int | ||
expectedContext string | ||
}{ | ||
"no deactivation with zero days in tier": { | ||
daysInTier: 0, | ||
expectedContext: "(unlimited)", | ||
}, | ||
"no deactivation with negative days in tier": { | ||
daysInTier: -1, | ||
expectedContext: "(unlimited)", | ||
}, | ||
"deactivation with positive days in tier": { | ||
daysInTier: 15, | ||
expectedContext: "15", | ||
}, | ||
} | ||
for k, tc := range tests { | ||
t.Run(k, func(t *testing.T) { | ||
// given | ||
userTier := &toolchainv1alpha1.UserTier{ | ||
Spec: toolchainv1alpha1.UserTierSpec{ | ||
DeactivationTimeoutDays: tc.daysInTier, | ||
}, | ||
} | ||
|
||
// when | ||
notification, err := NewNotificationBuilder(client, test.HostOperatorNs). | ||
WithUserTierContext(userTier). | ||
Create(context.TODO(), "[email protected]") | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Equal(t, tc.expectedContext, notification.Spec.Context["DeactivationTimeoutDays"]) | ||
}) | ||
} | ||
}) | ||
|
||
t.Run("success with notification type", func(t *testing.T) { | ||
// when | ||
notification, err := NewNotificationBuilder(client, test.HostOperatorNs). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tier | ||
|
||
import ( | ||
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" | ||
"github.com/codeready-toolchain/toolchain-common/pkg/test" | ||
"github.com/google/uuid" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func WithDeactivationTimeoutDays(days int) Modifier { | ||
return func(userSignup *toolchainv1alpha1.UserTier) { | ||
userSignup.Spec.DeactivationTimeoutDays = days | ||
} | ||
} | ||
|
||
func WithName(name string) Modifier { | ||
return func(userSignup *toolchainv1alpha1.UserTier) { | ||
userSignup.Name = name | ||
} | ||
} | ||
|
||
type Modifier func(tier *toolchainv1alpha1.UserTier) | ||
|
||
func NewUserTier(modifiers ...Modifier) *toolchainv1alpha1.UserTier { | ||
t := &toolchainv1alpha1.UserTier{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: uuid.NewString(), | ||
Namespace: test.HostOperatorNs, | ||
CreationTimestamp: metav1.Now(), | ||
}, | ||
} | ||
for _, modify := range modifiers { | ||
modify(t) | ||
} | ||
return t | ||
} |