Covered handler.go with tests

This commit is contained in:
Artyom Belousov 2021-02-06 22:27:22 +03:00
parent f0f64bd511
commit d5f9a495b7
7 changed files with 259 additions and 68 deletions

View file

@ -1,26 +0,0 @@
package cardsinfo
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestFormat(t *testing.T) {
data := []CardPrice{
&TcgCardPrice{
Name: "Green lotus",
PriceFoil: "22.8",
Link: "scg.com/1",
Edition: "alpha",
},
&TcgCardPrice{
Name: "White lotus",
Price: "3.22",
Link: "scg.com/2",
Edition: "gamma",
},
}
res := FormatCardPrices("Black Lotus", data)
ans := "Оригинальное название: Black Lotus\nРезультатов: 2\n1. alpha\nRegular: -\nFoil: $22.8\nscg.com/1\n2. gamma\nRegular: $3.22\nFoil: -\nscg.com/2\n"
assert.Equal(t, ans, res)
}

View file

@ -9,26 +9,6 @@ type CardPrice interface {
Format() string
}
type TcgCardPrice struct {
FullArt bool
Name string
Price string
PriceFoil string
Link string
Edition string
}
func (t *TcgCardPrice) Format() string {
return fmt.Sprintf("%v\nRegular: %v\nFoil: %v\n%v\n", t.Edition, formatTcgPrice(t.Price), formatTcgPrice(t.PriceFoil), t.Link)
}
func formatTcgPrice(price string) string {
if price == "" {
return "-"
}
return fmt.Sprintf("$%v", price)
}
type ScgCardPrice struct {
Price string
Edition string