PSQL CreateAccount
This commit is contained in:
@@ -10,14 +10,18 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewPostgresqlStorage(t *testing.T) {
|
||||
cfg := viper.New()
|
||||
var cfg *viper.Viper
|
||||
|
||||
func init() {
|
||||
cfg = viper.New()
|
||||
cfg.Set("storage.db.psql.host", "localhost")
|
||||
cfg.Set("storage.db.psql.port", "5432")
|
||||
cfg.Set("storage.db.psql.user", "postgres")
|
||||
cfg.Set("storage.db.psql.password", "postgres")
|
||||
cfg.Set("storage.db.psql.dbname", "mobilityaccounts")
|
||||
}
|
||||
|
||||
func TestNewPostgresqlStorage(t *testing.T) {
|
||||
storage, err := NewPostgresqlStorage(cfg)
|
||||
if err != nil {
|
||||
t.Errorf("error creating new PostgreSQL storage: %v", err)
|
||||
@@ -35,14 +39,9 @@ func generateUUIDv4() string {
|
||||
uuid[8] = (uuid[8] & 0xbf) | 0x80
|
||||
return hex.EncodeToString(uuid[:4]) + "-" + hex.EncodeToString(uuid[4:6]) + "-" + hex.EncodeToString(uuid[6:8]) + "-" + hex.EncodeToString(uuid[8:10]) + "-" + hex.EncodeToString(uuid[10:])
|
||||
}
|
||||
|
||||
func TestGetAccount(t *testing.T) {
|
||||
// Open a database connection
|
||||
cfg := viper.New()
|
||||
cfg.Set("storage.db.psql.host", "localhost")
|
||||
cfg.Set("storage.db.psql.port", "5432")
|
||||
cfg.Set("storage.db.psql.user", "postgres")
|
||||
cfg.Set("storage.db.psql.password", "postgres")
|
||||
cfg.Set("storage.db.psql.dbname", "mobilityaccounts")
|
||||
db, err := NewPostgresqlStorage(cfg)
|
||||
Id := generateUUIDv4()
|
||||
if err != nil {
|
||||
@@ -116,3 +115,45 @@ func TestGetAccount(t *testing.T) {
|
||||
t.Errorf("The received account is not the same as expected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgresqlStorage_CreateAccount(t *testing.T) {
|
||||
db, err := NewPostgresqlStorage(cfg)
|
||||
Id := generateUUIDv4()
|
||||
if err != nil {
|
||||
t.Errorf("failed to create new psql connection")
|
||||
}
|
||||
emailValidation := Validation{
|
||||
Validated: true,
|
||||
ValidationCode: "code",
|
||||
}
|
||||
localAuth := LocalAuth{
|
||||
Username: "salim",
|
||||
Password: "testpassword",
|
||||
Email: "test@test.com",
|
||||
EmailValidation: emailValidation,
|
||||
PhoneNumber: "1234567890",
|
||||
PhoneNumberValidation: emailValidation,
|
||||
}
|
||||
accountData := map[string]any{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
}
|
||||
accountMetadata := map[string]any{
|
||||
"key1": "value1",
|
||||
"key2": "value2",
|
||||
}
|
||||
account := Account{
|
||||
ID: Id,
|
||||
Namespace: "test_namespace",
|
||||
Authentication: AccountAuth{
|
||||
Local: localAuth,
|
||||
},
|
||||
Data: accountData,
|
||||
Metadata: accountMetadata,
|
||||
}
|
||||
err = db.CreateAccount(account)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
t.Errorf("Failed to create account")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user