Skip to content
Snippets Groups Projects
Commit 76b3e39c authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'fix/PRXS-1866-AddViewField' into 'master'

Добавление полей view и order в структуру Action

See merge request perxis/perxis-go!132
parents 2a0c0154 f0e774a1
Branches
Tags
No related merge requests found
...@@ -32,6 +32,7 @@ require ( ...@@ -32,6 +32,7 @@ require (
require ( require (
cloud.google.com/go/compute v1.23.3 // indirect cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/brianvoe/gofakeit/v6 v6.26.3
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-kit/log v0.2.1 // indirect github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect
......
...@@ -93,6 +93,8 @@ type Action struct { ...@@ -93,6 +93,8 @@ type Action struct {
Extension string `mapstructure:"extension,omitempty" json:"extension,omitempty"` // Расширение Extension string `mapstructure:"extension,omitempty" json:"extension,omitempty"` // Расширение
Action string `mapstructure:"action,omitempty" json:"action"` // Идентификатор действия Action string `mapstructure:"action,omitempty" json:"action"` // Идентификатор действия
Target ActionTarget `mapstructure:"target,omitempty" json:"target"` // Отображение результата действия Target ActionTarget `mapstructure:"target,omitempty" json:"target"` // Отображение результата действия
View ActionView `mapstructure:"view,omitempty" json:"view,omitempty"` // Отображение действия в интерфейсе
Order int32 `mapstructure:"order,omitempty" json:"order,omitempty"` // Порядок отображения действия в меню
Parent string `mapstructure:"parent,omitempty" json:"parent,omitempty"` // Идентификатор родительского действия (для отображения в меню) Parent string `mapstructure:"parent,omitempty" json:"parent,omitempty"` // Идентификатор родительского действия (для отображения в меню)
Name string `mapstructure:"name,omitempty" json:"name,omitempty"` // Название действия для отображения в интерфейсе (пункт меню, кнопка). Name string `mapstructure:"name,omitempty" json:"name,omitempty"` // Название действия для отображения в интерфейсе (пункт меню, кнопка).
Description string `mapstructure:"description,omitempty" json:"description,omitempty"` // Описание действия для отображения в интерфейсе Description string `mapstructure:"description,omitempty" json:"description,omitempty"` // Описание действия для отображения в интерфейсе
...@@ -111,10 +113,18 @@ type Action struct { ...@@ -111,10 +113,18 @@ type Action struct {
} }
func ActionToMap(action *Action) map[string]interface{} { func ActionToMap(action *Action) map[string]interface{} {
if action == nil {
return nil
}
res := make(map[string]interface{}) res := make(map[string]interface{})
_ = mapstructure.Decode(action, &res) if err := mapstructure.Decode(action, &res); err != nil {
return nil
}
res["kind"] = int64(action.Kind.Number()) res["kind"] = int64(action.Kind.Number())
res["target"] = int64(action.Target.Number()) res["target"] = int64(action.Target.Number())
res["view"] = int64(action.View.Number())
return res return res
} }
...@@ -217,6 +227,8 @@ func ActionFromPB(a *pb.Action) *Action { ...@@ -217,6 +227,8 @@ func ActionFromPB(a *pb.Action) *Action {
Extension: a.Extension, Extension: a.Extension,
Action: a.Action, Action: a.Action,
Target: a.Target, Target: a.Target,
View: a.View,
Order: a.Order,
Parent: a.Parent, Parent: a.Parent,
Name: a.Name, Name: a.Name,
Description: a.Description, Description: a.Description,
...@@ -258,5 +270,7 @@ func ActionToPB(a *Action) *pb.Action { ...@@ -258,5 +270,7 @@ func ActionToPB(a *Action) *pb.Action {
NavigationRoute: a.NavigationRoute, NavigationRoute: a.NavigationRoute,
Autorun: a.Autorun, Autorun: a.Autorun,
Confirm: a.Confirm, Confirm: a.Confirm,
View: a.View,
Order: a.Order,
} }
} }
package extension
import (
"testing"
pb "git.perx.ru/perxis/perxis-go/proto/extensions"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/require"
)
func TestActionToProto(t *testing.T) {
t.Run("Filled struct", func(t *testing.T) {
var pbAction *pb.Action
err := gofakeit.Struct(&pbAction)
require.NoError(t, err)
action := ActionFromPB(pbAction)
result := ActionToPB(action)
require.Equal(t, pbAction, result)
})
t.Run("Action is nil", func(t *testing.T) {
var pbAction *pb.Action
action := ActionFromPB(pbAction)
result := ActionToPB(action)
require.Equal(t, pbAction, result)
})
}
func TestActionToMap(t *testing.T) {
t.Run("Filled struct", func(t *testing.T) {
var action *Action
err := gofakeit.Struct(&action)
require.NoError(t, err)
dict := ActionToMap(action)
result, err := ActionFromMap(dict)
require.NoError(t, err)
require.Equal(t, action, result)
})
t.Run("Action is nil", func(t *testing.T) {
var action *Action
dict := ActionToMap(action)
result, err := ActionFromMap(dict)
require.NoError(t, err)
require.Equal(t, &Action{}, result)
})
}
func TestActionRequestToProto(t *testing.T) {
t.Run("Filled struct", func(t *testing.T) {
var pbAction *pb.ActionRequest
err := gofakeit.Struct(&pbAction)
require.NoError(t, err)
action := ActionRequestFromPB(pbAction)
result := ActionRequestToPB(action)
require.Equal(t, pbAction, result)
})
t.Run("Action is nil", func(t *testing.T) {
var pbAction *pb.ActionRequest
action := ActionRequestFromPB(pbAction)
result := ActionRequestToPB(action)
require.Equal(t, pbAction, result)
})
}
func TestActionResponseToProto(t *testing.T) {
t.Run("Filled struct", func(t *testing.T) {
var pbAction *pb.ActionResponse
err := gofakeit.Struct(&pbAction)
require.NoError(t, err)
action := ActionResponseFromPB(pbAction)
result := ActionResponseToPB(action)
require.Equal(t, pbAction, result)
})
t.Run("Action is nil", func(t *testing.T) {
var pbAction *pb.ActionResponse
action := ActionResponseFromPB(pbAction)
result := ActionResponseToPB(action)
require.Equal(t, pbAction, result)
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment