From 99f17511e48e3505c6b7b707b4a872e5fba5393c Mon Sep 17 00:00:00 2001 From: Daniel Krol Date: Fri, 24 Jun 2022 13:26:21 -0400 Subject: [PATCH] Test GetUserId --- store/store_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/store/store_test.go b/store/store_test.go index 3f6f64d..284f1c6 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -499,6 +499,24 @@ func TestStoreCreateAccount(t *testing.T) { expectAccountNotExists(t, &s, email, newPassword) } +// Test GetUserId, using CreateAccount as a helper +// Try GetUserId before creating an account (fail), and after (succeed) func TestStoreGetUserId(t *testing.T) { - t.Fatalf("Test me: User ID get success and failures") + s, sqliteTmpFile := StoreTestInit(t) + defer StoreTestCleanup(sqliteTmpFile) + + email, password := auth.Email("abc@example.com"), auth.Password("123") + + // Check that there's no user id for email and password first + if userId, err := s.GetUserId(email, password); err != ErrNoUId || userId != 0 { + t.Fatalf(`CreateAccount err: wanted "%+v", got "%+v. userId: %v"`, ErrNoUId, err, userId) + } + + // Create the account + _ = s.CreateAccount(email, password) + + // Check that there's now a user id for the email and password + if userId, err := s.GetUserId(email, password); err != nil || userId == 0 { + t.Fatalf("Unexpected error in GetUserId: err: %+v userId: %v", err, userId) + } }