Removed results string

This commit is contained in:
Artyom Belousov 2021-06-05 10:26:46 +03:00
parent 9ca4c0ce43
commit 038ca04548
2 changed files with 9 additions and 6 deletions

View file

@ -13,10 +13,12 @@ func (f *Fetcher) GetFormattedCardPrices(name string) (string, error) {
}
func (f *Fetcher) formatCardPrices(name string, prices []scgCardPrice) string {
message := fmt.Sprintf("Оригинальное название: %v\n", name)
message += fmt.Sprintf("Результатов: %v\n", len(prices))
message := fmt.Sprintf("Оригинальное название: %v\n\n", name)
for i, v := range prices {
message += fmt.Sprintf("%v. %v", i+1, v.format())
}
if len(prices) == 0 {
message += "Цен не найдено\n"
}
return message
}

View file

@ -1,11 +1,12 @@
package cardsinfo
import (
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
"net/http"
"os"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
)
func TestFetcher_GetFormattedCardPrices_Error(t *testing.T) {
@ -25,7 +26,7 @@ func TestFetcher_GetFormattedCardPrices_Empty(t *testing.T) {
f := &Fetcher{}
msg, err := f.GetFormattedCardPrices("card")
assert.Nil(t, err)
assert.Equal(t, "Оригинальное название: card\nРезультатов: 0\n", msg)
assert.Equal(t, "Оригинальное название: card\n\nЦен не найдено\n", msg)
}
func TestFormatCardPrices(t *testing.T) {
@ -37,5 +38,5 @@ func TestFormatCardPrices(t *testing.T) {
link: "scg.com",
},
})
assert.Equal(t, "Оригинальное название: card\nРезультатов: 1\n1. ED: 1.5$\nscg.com\n", formatted)
assert.Equal(t, "Оригинальное название: card\n\n1. ED: 1.5$\nscg.com\n", formatted)
}