package repository_test import ( "context" "testing" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository" ) func TestRefreshTokenCreate(t *testing.T) { conn, err := setupInMemoryDb() if err != nil { t.Log(err) t.FailNow() } client := repository.NewRefreshTokenRepository(conn) rows, err := client.Create(context.Background(), "tester", "BadTokenDontUse") if err != nil { t.Log(err) t.FailNow() } if rows == 0 { t.Log("expected one row to come back but got 0") } } func TestRefreshTokenGetByUsername(t *testing.T) { conn, err := setupInMemoryDb() if err != nil { t.Log(err) t.FailNow() } client := repository.NewRefreshTokenRepository(conn) rows, err := client.Create(context.Background(), "tester", "BadTokenDoNotUse") if err != nil { t.Log(err) t.FailNow() } if rows != 1 { t.Log("expected a row to be added but not the wrong value back") t.FailNow() } model, err := client.GetByUsername(context.Background(), "tester") if err != nil { t.Log(err) t.FailNow() } if model.Username != "tester" { t.Log("got the wrong user back") t.FailNow() } } func TestRefreshTokenDeleteById(t *testing.T) { conn, err := setupInMemoryDb() if err != nil { t.Log(err) t.FailNow() } client := repository.NewRefreshTokenRepository(conn) created, err := client.Create(context.Background(), "tester", "BadTokenDoNotUse") if err != nil { t.Log(err) t.FailNow() } if created != 1 { t.Log("Unexpected number back for rows created") } model, err := client.GetByUsername(context.Background(), "tester") if err != nil { t.Log(err) t.FailNow() } updated, err := client.DeleteById(context.Background(), model.ID) if err != nil { t.Log(err) t.FailNow() } if updated != 1 { t.Log("deleted the wrong number of records") t.FailNow() } }