(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestCreate(t *testing.T) { |
| 29 | testCases := []struct { |
| 30 | kind string |
| 31 | }{ |
| 32 | { |
| 33 | kind: database.TokenTypeResetPassword, |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | for _, tc := range testCases { |
| 38 | t.Run(fmt.Sprintf("token type %s", tc.kind), func(t *testing.T) { |
| 39 | db := testutils.InitMemoryDB(t) |
| 40 | |
| 41 | // Set up |
| 42 | u := testutils.SetupUserData(db, "user@test.com", "password123") |
| 43 | |
| 44 | // Execute |
| 45 | tok, err := Create(db, u.ID, tc.kind) |
| 46 | if err != nil { |
| 47 | t.Fatal(errors.Wrap(err, "performing")) |
| 48 | } |
| 49 | |
| 50 | // Test |
| 51 | var count int64 |
| 52 | testutils.MustExec(t, db.Model(&database.Token{}).Count(&count), "counting token") |
| 53 | assert.Equalf(t, count, int64(1), "error mismatch") |
| 54 | |
| 55 | var tokenRecord database.Token |
| 56 | testutils.MustExec(t, db.First(&tokenRecord), "finding token") |
| 57 | assert.Equalf(t, tokenRecord.UserID, tok.UserID, "UserID mismatch") |
| 58 | assert.Equalf(t, tokenRecord.Value, tok.Value, "Value mismatch") |
| 59 | assert.Equalf(t, tokenRecord.Type, tok.Type, "Type mismatch") |
| 60 | }) |
| 61 | } |
| 62 | } |
nothing calls this directly
no test coverage detected