@@ -130,6 +130,95 @@ func TestEntitlements(t *testing.T) {
130
130
"Your license expires in 2 days." ,
131
131
)
132
132
})
133
+
134
+ t .Run ("Expiration warning for license expiring in 1 day" , func (t * testing.T ) {
135
+ t .Parallel ()
136
+ db := dbfake .New ()
137
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
138
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
139
+ Features : license.Features {
140
+ codersdk .FeatureUserLimit : 100 ,
141
+ codersdk .FeatureAuditLog : 1 ,
142
+ },
143
+
144
+ GraceAt : time .Now ().AddDate (0 , 0 , 1 ),
145
+ ExpiresAt : time .Now ().AddDate (0 , 0 , 5 ),
146
+ }),
147
+ Exp : time .Now ().AddDate (0 , 0 , 5 ),
148
+ })
149
+
150
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
151
+
152
+ require .NoError (t , err )
153
+ require .True (t , entitlements .HasLicense )
154
+ require .False (t , entitlements .Trial )
155
+
156
+ require .Equal (t , codersdk .EntitlementEntitled , entitlements .Features [codersdk .FeatureAuditLog ].Entitlement )
157
+ require .Contains (
158
+ t , entitlements .Warnings ,
159
+ "Your license expires in 1 day." ,
160
+ )
161
+ })
162
+
163
+ t .Run ("Expiration warning for trials" , func (t * testing.T ) {
164
+ t .Parallel ()
165
+ db := dbfake .New ()
166
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
167
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
168
+ Features : license.Features {
169
+ codersdk .FeatureUserLimit : 100 ,
170
+ codersdk .FeatureAuditLog : 1 ,
171
+ },
172
+
173
+ Trial : true ,
174
+ GraceAt : time .Now ().AddDate (0 , 0 , 8 ),
175
+ ExpiresAt : time .Now ().AddDate (0 , 0 , 5 ),
176
+ }),
177
+ Exp : time .Now ().AddDate (0 , 0 , 5 ),
178
+ })
179
+
180
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
181
+
182
+ require .NoError (t , err )
183
+ require .True (t , entitlements .HasLicense )
184
+ require .True (t , entitlements .Trial )
185
+
186
+ require .Equal (t , codersdk .EntitlementEntitled , entitlements .Features [codersdk .FeatureAuditLog ].Entitlement )
187
+ require .NotContains ( // it should not contain a warning since it is a trial license
188
+ t , entitlements .Warnings ,
189
+ "Your license expires in 8 days." ,
190
+ )
191
+ })
192
+
193
+ t .Run ("Expiration warning for non trials" , func (t * testing.T ) {
194
+ t .Parallel ()
195
+ db := dbfake .New ()
196
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
197
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
198
+ Features : license.Features {
199
+ codersdk .FeatureUserLimit : 100 ,
200
+ codersdk .FeatureAuditLog : 1 ,
201
+ },
202
+
203
+ GraceAt : time .Now ().AddDate (0 , 0 , 30 ),
204
+ ExpiresAt : time .Now ().AddDate (0 , 0 , 5 ),
205
+ }),
206
+ Exp : time .Now ().AddDate (0 , 0 , 5 ),
207
+ })
208
+
209
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
210
+
211
+ require .NoError (t , err )
212
+ require .True (t , entitlements .HasLicense )
213
+ require .False (t , entitlements .Trial )
214
+
215
+ require .Equal (t , codersdk .EntitlementEntitled , entitlements .Features [codersdk .FeatureAuditLog ].Entitlement )
216
+ require .NotContains ( // it should not contain a warning since it is a trial license
217
+ t , entitlements .Warnings ,
218
+ "Your license expires in 30 days." ,
219
+ )
220
+ })
221
+
133
222
t .Run ("SingleLicenseNotEntitled" , func (t * testing.T ) {
134
223
t .Parallel ()
135
224
db := dbfake .New ()
0 commit comments