chore: add cast commands for testing purpose
This commit is contained in:
@ -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",
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user