Skip to content

Commit

Permalink
feat(marusia): Add NewLink
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud committed Jun 1, 2021
1 parent 306d0ad commit a41fd2d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
21 changes: 20 additions & 1 deletion marusia/skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ const (

// Карточка vk miniapp'а.
MiniApp CardType = "MiniApp"

// Стилизованная ссылка.
Link CardType = "Link"
)

// CardItem элемент карточки.
Expand All @@ -375,10 +378,15 @@ type Card struct {
// Тип карточки.
Type CardType `json:"type"`

// Заголовок изображения.
// Заголовок изображения или ссылки.
Title string `json:"title,omitempty"`

// Описание ссылки.
Text string `json:"text,omitempty"`

// Описание изображения.
//
// Deprecated: исчезло из документации.
Description string `json:"description,omitempty"`

// ID изображения из раздела "Медиа-файлы" в настройках скилла
Expand Down Expand Up @@ -429,6 +437,17 @@ func NewMiniApp(url string) *Card {
}
}

// NewLink возвращает карточку с стилизованной ссылкой.
func NewLink(url, title, text string, imageID int) *Card {
return &Card{
Type: Link,
URL: url,
Title: title,
Text: text,
ImageID: imageID,
}
}

// Response данные для ответа пользователю.
type Response struct {
// Текст, который следует показать и сказать пользователю. Максимум 1024
Expand Down
22 changes: 22 additions & 0 deletions marusia/skill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ func TestNewMiniApp(t *testing.T) {
)
}

func TestNewLink(t *testing.T) {
t.Parallel()

f := func(url, title, text string, imageID int, actual *marusia.Card) {
t.Helper()

card := marusia.NewLink(url, title, text, imageID)

assert.Equal(t, card, actual)
}

f("url", "title", "text", 1234,
&marusia.Card{
Type: marusia.Link,
URL: "url",
Title: "title",
Text: "text",
ImageID: 1234,
},
)
}

func TestNewImageList(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit a41fd2d

Please sign in to comment.