forked from mirrors/homebox
* basic currency service for loading at runtime * api endpoint for currencies * sort slice before return * remove currency validation * validate using currency service * implement selecting dynamic currency options * bump go version * fix type definition * specify explicit type * change go versions * proper types for assetId * log/return currency error * make case insensative * use ToUpper instead * feat: adding new currencies (#715) * fix: task swag (#710) Co-authored-by: Quoing <pavel.cadersky@mavenir.com> * [feat] Adding new currencies --------- Co-authored-by: quoing <quoing@users.noreply.github.com> Co-authored-by: Quoing <pavel.cadersky@mavenir.com> Co-authored-by: Bradley <41597815+userbradley@users.noreply.github.com> * remove ts file and consoldate new values into json * move flag to options namespace * add env config for currencies * basic documentaion * remove in sync test --------- Co-authored-by: quoing <quoing@users.noreply.github.com> Co-authored-by: Quoing <pavel.cadersky@mavenir.com> Co-authored-by: Bradley <41597815+userbradley@users.noreply.github.com> Former-commit-id: c4b923847a1b695dcddd1b346adcccfd3f3ce706
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/core/currencies"
|
|
"github.com/hay-kot/homebox/backend/internal/core/services/reporting/eventbus"
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
|
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
|
"github.com/hay-kot/homebox/backend/pkgs/faker"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
var (
|
|
fk = faker.NewFaker()
|
|
tbus = eventbus.New()
|
|
|
|
tCtx = Context{}
|
|
tClient *ent.Client
|
|
tRepos *repo.AllRepos
|
|
tUser repo.UserOut
|
|
tGroup repo.Group
|
|
tSvc *AllServices
|
|
)
|
|
|
|
func bootstrap() {
|
|
var (
|
|
err error
|
|
ctx = context.Background()
|
|
)
|
|
|
|
tGroup, err = tRepos.Groups.GroupCreate(ctx, "test-group")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
tUser, err = tRepos.Users.Create(ctx, repo.UserCreate{
|
|
Name: fk.Str(10),
|
|
Email: fk.Email(),
|
|
Password: fk.Str(10),
|
|
IsSuperuser: fk.Bool(),
|
|
GroupID: tGroup.ID,
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
|
if err != nil {
|
|
log.Fatalf("failed opening connection to sqlite: %v", err)
|
|
}
|
|
|
|
err = client.Schema.Create(context.Background())
|
|
if err != nil {
|
|
log.Fatalf("failed creating schema resources: %v", err)
|
|
}
|
|
|
|
tClient = client
|
|
tRepos = repo.New(tClient, tbus, os.TempDir()+"/homebox")
|
|
|
|
defaults, _ := currencies.CollectionCurrencies(
|
|
currencies.CollectDefaults(),
|
|
)
|
|
|
|
tSvc = New(tRepos, WithCurrencies(defaults))
|
|
defer func() { _ = client.Close() }()
|
|
|
|
bootstrap()
|
|
tCtx = Context{
|
|
Context: context.Background(),
|
|
GID: tGroup.ID,
|
|
UID: tUser.ID,
|
|
}
|
|
|
|
os.Exit(m.Run())
|
|
}
|