MCPcopy Index your code
hub / github.com/dnote/dnote / TestCreate

Function TestCreate

pkg/server/token/token_test.go:28–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func 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}

Callers

nothing calls this directly

Calls 5

InitMemoryDBFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
EqualfFunction · 0.92
CreateFunction · 0.85

Tested by

no test coverage detected