chore: add cast commands for testing purpose

This commit is contained in:
2023-04-05 15:12:51 +02:00
parent f08f645432
commit 84c8fd51f6
15 changed files with 135 additions and 22 deletions

View File

@ -19,8 +19,8 @@ func TestAppModuleWithMemoryRepository(t *testing.T) {
module.ContextModuleFactory(),
module.ConsoleModuleFactory(),
appModule.ModuleFactory(NewRepository(
func(ctx context.Context, id app.ID) (string, error) {
return fmt.Sprintf("http//%s.example.com", id), nil
func(ctx context.Context, id app.ID, from string) (string, error) {
return fmt.Sprintf("http//%s.example.com?from=%s", id, from), nil
},
&app.Manifest{
ID: "dummy1.arcad.app",

View File

@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
)
type GetURLFunc func(context.Context, app.ID) (string, error)
type GetURLFunc func(context.Context, app.ID, string) (string, error)
type Repository struct {
getURL GetURLFunc
@ -16,8 +16,8 @@ type Repository struct {
}
// GetURL implements app.Repository
func (r *Repository) GetURL(ctx context.Context, id app.ID) (string, error) {
url, err := r.getURL(ctx, id)
func (r *Repository) GetURL(ctx context.Context, id app.ID, from string) (string, error) {
url, err := r.getURL(ctx, id, from)
if err != nil {
return "", errors.WithStack(err)
}

View File

@ -86,7 +86,12 @@ func (m *Module) getURL(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
ctx := util.AssertContext(call.Argument(0), rt)
appID := assertAppID(call.Argument(1), rt)
url, err := m.repository.GetURL(ctx, appID)
var from string
if len(call.Arguments) > 2 {
from = util.AssertString(call.Argument(2), rt)
}
url, err := m.repository.GetURL(ctx, appID, from)
if err != nil {
panic(rt.ToValue(errors.WithStack(err)))
}

View File

@ -9,5 +9,5 @@ import (
type Repository interface {
List(context.Context) ([]*app.Manifest, error)
Get(context.Context, app.ID) (*app.Manifest, error)
GetURL(context.Context, app.ID) (string, error)
GetURL(context.Context, app.ID, string) (string, error)
}