This commit is contained in:
2026-03-07 07:50:24 +07:00
parent 795edad998
commit 83868cc778
7 changed files with 222 additions and 7 deletions
+155
View File
@@ -0,0 +1,155 @@
package services
import (
"evening_detective/internal/models"
"evening_detective/internal/modules/cleaner"
"evening_detective/internal/modules/formatter"
"evening_detective/internal/services/story_service"
"evening_detective/internal/services/story_storage"
"testing"
"github.com/stretchr/testify/assert"
)
func TestServices_getPlaces(t *testing.T) {
tests := []struct {
name string
story *story_service.Story
actions []*models.Action
want []*story_service.Place
}{
// {
// name: "Нельзя открыть скрытую точку",
// story: &story_service.Story{
// Places: []*story_service.Place{
// {
// Code: "Ы",
// Name: "Название",
// Text: "Текст",
// Hidden: true,
// },
// },
// },
// actions: []*models.Action{
// {
// Place: "Ы",
// },
// },
// want: []*story_service.Place{
// {
// Code: "Ы",
// Name: "Не найдено",
// Text: "Такой точки не существует.",
// },
// },
// },
// {
// name: "Нельзя открыть скрытую точку",
// story: &story_service.Story{
// Places: []*story_service.Place{
// {
// Code: "Ы-1",
// Name: "Название",
// Text: "Текст",
// },
// {
// Code: "Ы-2",
// Name: "Название",
// Text: "Текст",
// Hidden: true,
// },
// },
// },
// actions: []*models.Action{
// {
// Place: "Ы-1",
// },
// {
// Place: "Ы-2",
// },
// },
// want: []*story_service.Place{
// {
// Code: "Ы-1",
// Name: "Название",
// Text: "Текст",
// Applications: []*story_service.Application{},
// },
// {
// Code: "Ы-2",
// Name: "Не найдено",
// Text: "Такой точки не существует.",
// },
// },
// },
{
name: "Нельзя открыть скрытую точку",
story: &story_service.Story{
Places: []*story_service.Place{
{
Code: "Ы-1",
Name: "Название",
Text: "Текст",
Applications: []*story_service.Application{},
Doors: []*story_service.Door{
{
Code: "Ы-2",
Name: "Название",
},
},
},
{
Code: "Ы-2",
Name: "Название",
Text: "Текст",
Applications: []*story_service.Application{},
Hidden: true,
},
},
},
actions: []*models.Action{
{
Place: "Ы-1",
},
{
Place: "Ы-2",
},
},
want: []*story_service.Place{
{
Code: "Ы-1",
Name: "Название",
Text: "Текст",
Applications: []*story_service.Application{},
Doors: []*story_service.Door{
{
Code: "Ы-2",
Name: "Название",
},
},
},
{
Code: "Ы-2",
Name: "Название",
Text: "Текст",
Applications: []*story_service.Application{},
Hidden: true,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
storyService, err := story_service.NewStoryService(
cleaner.NewCleaner(),
formatter.NewFormatter(),
story_storage.NewVarStoryStorage(tt.story),
)
assert.Nil(t, err)
s := NewServices(nil, storyService, nil, nil, nil, "")
got := s.getPlaces(tt.actions)
assert.Equal(t, got, tt.want)
})
}
}