2026-03-07 07:50:24 +07:00

156 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
})
}
}