Skip to content
Snippets Groups Projects
Commit 8aab3d5f authored by ko_oler's avatar ko_oler
Browse files

Внесены правки в метод ListLocales сервиса Delivery для возвращения списка...

Внесены правки в метод ListLocales сервиса Delivery для возвращения списка только опубликованных локалей
parent 4baed953
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,17 @@ type deliveryService struct {
}
func (s deliveryService) ListLocales(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) {
return s.Locales.List(ctx, spaceId)
res, err := s.Locales.List(ctx, spaceId)
if err != nil {
return nil, err
}
for _, l := range res {
if l.NoPublish || l.Disabled {
continue
}
locales = append(locales, l)
}
return locales, nil
}
func (s deliveryService) GetEnvironment(ctx context.Context, spaceId, envId string) (env *environments.Environment, err error) {
......
package service
import (
"context"
"testing"
"git.perx.ru/perxis/perxis-go/pkg/locales"
"git.perx.ru/perxis/perxis-go/pkg/locales/mocks"
"github.com/stretchr/testify/assert"
)
func Test_deliveryService_ListLocales(t *testing.T) {
tests := []struct {
name string
mockcall func(locSvs *mocks.Locales)
wantLocales []*locales.Locale
wantErr bool
}{
{
name: "Returned locales without NoPublish and Disabled",
mockcall: func(locSvs *mocks.Locales) {
locSvs.On("List", context.Background(), "space").Return([]*locales.Locale{
{ID: "en_EN", SpaceID: "space", Name: "english", Code: "en", NoPublish: false, Disabled: false},
{ID: "de_DE", SpaceID: "space", Name: "deutsch", Code: "de", NoPublish: false, Disabled: false},
{ID: "ru_RU", SpaceID: "space", Name: "russian", Code: "ru", NoPublish: false, Disabled: false},
{ID: "by_BY", SpaceID: "space", Name: "belarus", Code: "by", NoPublish: true, Disabled: false},
{ID: "es_ES", SpaceID: "space", Name: "spain", Code: "by", NoPublish: false, Disabled: true}}, nil)
},
wantLocales: []*locales.Locale{
{ID: "en_EN", SpaceID: "space", Name: "english", Code: "en", NoPublish: false, Disabled: false},
{ID: "de_DE", SpaceID: "space", Name: "deutsch", Code: "de", NoPublish: false, Disabled: false},
{ID: "ru_RU", SpaceID: "space", Name: "russian", Code: "ru", NoPublish: false, Disabled: false},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
localesService := &mocks.Locales{}
if tt.mockcall != nil {
tt.mockcall(localesService)
}
s := deliveryService{
Locales: localesService,
}
gotLocales, err := s.ListLocales(context.Background(), "space")
if tt.wantErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.wantLocales, gotLocales)
localesService.AssertExpectations(t)
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment