1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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")
}
}
|