63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package priceiswrong_test
|
|
|
|
import (
|
|
"gitea/price-is-wrong/pkg/lib"
|
|
"gitea/price-is-wrong/pkg/state/priceiswrong"
|
|
"testing"
|
|
)
|
|
|
|
func TestPriceIsWrong(t *testing.T) {
|
|
ctx := lib.NewTestCtx(t)
|
|
|
|
p, err := priceiswrong.Open(ctx, "name")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := p.SetPlayers(ctx, []int{4, 5, 6}); err != nil {
|
|
t.Fatal(err)
|
|
} else if len(p.Contestants) != 3 {
|
|
t.Errorf("bad contestants: %+v", p.Contestants)
|
|
} else if p.Host < 4 || p.Host > 6 {
|
|
t.Errorf("bad host: %+v", p.Host)
|
|
}
|
|
|
|
if err := p.SetHost(ctx, 5); err != nil {
|
|
t.Fatal(err)
|
|
} else if p.Host != 5 {
|
|
t.Errorf("bad host: %+v", p.Host)
|
|
}
|
|
|
|
if err := p.Score(ctx, 4, 9); err != nil {
|
|
t.Fatal(err)
|
|
} else if p.Contestants[0].Score != 9 {
|
|
t.Errorf("players changed order or didnt give 4 its points: %+v", p.Contestants)
|
|
} else if err := p.Score(ctx, 4, 9); err != nil {
|
|
t.Fatal(err)
|
|
} else if p.Contestants[0].Score != 18 {
|
|
t.Errorf("players changed order or didnt give 4 more points: %+v", p.Contestants)
|
|
} else if p.Contestants[1].Score != 0 {
|
|
t.Errorf("gave someone else points: %+v", p.Contestants)
|
|
}
|
|
|
|
if err := p.Guess(ctx, 4, "guess"); err != nil {
|
|
t.Fatal(err)
|
|
} else if p.Contestants[0].Guess != "guess" {
|
|
t.Errorf("guess didnt persist: %+v", p.Contestants)
|
|
}
|
|
|
|
if err := p.SetItem(ctx, "a", "b", "c", "d"); err != nil {
|
|
t.Fatal(err)
|
|
} else if p.Contestants[0].Guess != "" {
|
|
t.Errorf("set item didnt clear guesses")
|
|
} else if err := p.SetItem(ctx, "imageURL", "title", "description", "d"); err != nil {
|
|
t.Fatal(err)
|
|
} else if p.Item.ImageURL != "imageURL" {
|
|
t.Errorf("wrong image url: %s", p.Item.ImageURL)
|
|
} else if p.Item.Title != "title" {
|
|
t.Errorf("wrong title: %s", p.Item.Title)
|
|
} else if p.Item.Description != "description" {
|
|
t.Errorf("wrong description: %s", p.Item.Description)
|
|
}
|
|
}
|