summaryrefslogtreecommitdiff
path: root/persistence/sqlite/sqlite_test.go
diff options
context:
space:
mode:
authoruvok cheetah2023-12-09 17:54:45 +0000
committeruvok cheetah2023-12-09 17:55:24 +0000
commit1045770f2beb282143e443a6e7742c9cb5e2945e (patch)
treeac1ec7b3302b83ac029635b2a661830628730440 /persistence/sqlite/sqlite_test.go
parent250ef5536d04be91e53af514c445b712dff960ef (diff)
Add test
Diffstat (limited to 'persistence/sqlite/sqlite_test.go')
-rw-r--r--persistence/sqlite/sqlite_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/persistence/sqlite/sqlite_test.go b/persistence/sqlite/sqlite_test.go
new file mode 100644
index 0000000..f6ff967
--- /dev/null
+++ b/persistence/sqlite/sqlite_test.go
@@ -0,0 +1,51 @@
+package sqlite_test
+
+import (
+ "context"
+ "os"
+ "testing"
+
+ "uvok.de/go/training_fellow/registration"
+ "uvok.de/go/training_fellow/registration/persistence/sqlite"
+)
+
+func TestSqliteFetchUnconfirmed(t *testing.T) {
+
+ testRegId := "xx-yy-01-01"
+ newRegistration := registration.Registration{
+ FirstName: "Test",
+ LastName: "User",
+ Email: "bla@foo.com",
+ Company: "ACMA Inc.",
+ TrainingCode: "xxxx0xx",
+ Date: "2023-01-01",
+ PrivacyPolicyAccepted: true,
+ Confirmed: false,
+ RegId: testRegId,
+ }
+
+ testFileName := "./registration_test.sqlite"
+ os.Remove(testFileName)
+ repo := sqlite.NewRepository(testFileName, context.Background())
+ repo.Migrate()
+
+ err := repo.SaveRegistration(&newRegistration)
+ if err != nil {
+ t.Fatalf("Saving registration failed: %v.", err)
+ }
+
+ queryReg, _ := repo.ConfirmRegistration(testRegId + "x")
+ if queryReg != nil {
+ t.Fatal("Query for wrong RegId must not return any results.")
+ }
+ queryReg, err = repo.ConfirmRegistration(testRegId)
+ // set to true so we can compare
+ newRegistration.Confirmed = true
+ if err != nil {
+ t.Fatalf("Unexpected error fetching record: %v", err)
+ } else if queryReg == nil {
+ t.Fatal("Should have found record.")
+ } else if *queryReg != newRegistration {
+ t.Error("Fetched registration doesn't match expected")
+ }
+}