|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
7 | 7 | "testing"
|
| 8 | + "time" |
8 | 9 | )
|
9 | 10 |
|
10 | 11 | const (
|
@@ -67,6 +68,10 @@ func Test_NewConfirmation(t *testing.T) {
|
67 | 68 | t.Fail()
|
68 | 69 | }
|
69 | 70 |
|
| 71 | + if confirmation.ExpiresAt.IsZero() { |
| 72 | + t.Errorf("expected expiresAt to be non-Zero") |
| 73 | + } |
| 74 | + |
70 | 75 | confirmation.UpdateStatus(StatusCompleted)
|
71 | 76 |
|
72 | 77 | if confirmation.Status != StatusCompleted {
|
@@ -229,6 +234,47 @@ func TestConfirmationContextCustomUnmarshaler(s *testing.T) {
|
229 | 234 | })
|
230 | 235 | }
|
231 | 236 |
|
| 237 | +func TestConfirmationCalculatesExpiresAt(t *testing.T) { |
| 238 | + for cType := range Timeouts { |
| 239 | + invite, err := NewConfirmation(cType, TemplateNamePasswordReset, USERID) |
| 240 | + if err != nil { |
| 241 | + t.Fatalf("expected nil, got %+v", err) |
| 242 | + } |
| 243 | + if invite.ExpiresAt == nil || invite.ExpiresAt.IsZero() { |
| 244 | + t.Errorf("expected non-Zero ExiresAt") |
| 245 | + } |
| 246 | + } |
| 247 | +} |
| 248 | + |
| 249 | +func TestConfirmationIsExpired(t *testing.T) { |
| 250 | + for cType := range Timeouts { |
| 251 | + invite, err := NewConfirmation(cType, TemplateNameCareteamInvite, USERID) |
| 252 | + if err != nil { |
| 253 | + t.Fatalf("expected nil error, got %s", err) |
| 254 | + } |
| 255 | + if invite.IsExpired() { |
| 256 | + t.Errorf("expected false, got true") |
| 257 | + } |
| 258 | + *invite.ExpiresAt = time.Unix(0, 0) |
| 259 | + if !invite.IsExpired() { |
| 260 | + t.Errorf("expected true, got false") |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + // These types don't have timeouts, so don't get an expires at. They're |
| 265 | + // never expired. |
| 266 | + for _, cType := range []Type{TypeClinicianInvite, TypeNoAccount} { |
| 267 | + nonExpiringInviting, err := NewConfirmation(cType, TemplateNameCareteamInvite, USERID) |
| 268 | + if err != nil { |
| 269 | + t.Fatalf("expected nil error, got %s", err) |
| 270 | + } |
| 271 | + if nonExpiringInviting.IsExpired() { |
| 272 | + t.Errorf("expected invitation type %q to never expire", cType) |
| 273 | + } |
| 274 | + } |
| 275 | + |
| 276 | +} |
| 277 | + |
232 | 278 | // buff is a helper for generating a JSON []byte representation.
|
233 | 279 | func buff(format string, args ...interface{}) *bytes.Buffer {
|
234 | 280 | return bytes.NewBufferString(fmt.Sprintf(format, args...))
|
|
0 commit comments