fix codes

This commit is contained in:
2026-07-28 23:19:48 +07:00
parent cb1f31480c
commit 11798bd4fa
5 changed files with 43 additions and 12 deletions
@@ -0,0 +1,5 @@
package storytelling
type ICleaner interface {
ClearCode(code string) string
}
+11 -5
View File
@@ -1,9 +1,15 @@
package storytelling
type story struct{}
type story struct {
cleaner ICleaner
}
func NewStory() IStory {
return &story{}
func NewStory(
cleaner ICleaner,
) IStory {
return &story{
cleaner: cleaner,
}
}
func (s *story) GetStory(
@@ -69,7 +75,7 @@ func (s *story) findPlace(
code string,
) (*Place, bool) {
for _, place := range scenario.Places {
if place.Code == code {
if s.cleaner.ClearCode(place.Code) == s.cleaner.ClearCode(code) {
return place, true
}
}
@@ -95,7 +101,7 @@ func (s *story) findResultPlace(
}
}
for _, place := range scenario.Places {
if place.Code == code {
if s.cleaner.ClearCode(place.Code) == s.cleaner.ClearCode(code) {
if place.Hidden && !open {
return nil, false
}
+24 -1
View File
@@ -1,6 +1,7 @@
package storytelling
import (
"evening_detective_server/internal/modules/cleaner"
"testing"
"github.com/stretchr/testify/assert"
@@ -49,6 +50,28 @@ func Test_story_GetStory(t *testing.T) {
},
},
},
{
name: "Получение точки проверка регистра",
scenario: &Story{
Places: []*Place{
{
Code: "Ы-1",
Name: "Название точки",
Text: "Текст точки.",
},
},
},
codes: []string{"ы1"},
want: &Story{
Places: []*Place{
{
Code: "Ы-1",
Name: "Название точки",
Text: "Текст точки.",
},
},
},
},
{
name: "Получение 2 точек",
scenario: &Story{
@@ -709,7 +732,7 @@ func Test_story_GetStory(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := NewStory().GetStory(tt.scenario, tt.codes)
got := NewStory(cleaner.NewCleaner()).GetStory(tt.scenario, tt.codes)
assert.Equal(t, got, tt.want)
})
}