new price parsing methods + tests
All checks were successful
/ Make image (push) Successful in 39s

This commit is contained in:
nquidox 2026-01-05 17:51:02 +03:00
parent ae0a07ae1b
commit 2fa14a7797
3 changed files with 156 additions and 22 deletions

View file

@ -0,0 +1,77 @@
package mandarake
import (
"context"
"testing"
)
func TestParser_processPrices(t *testing.T) {
type fields struct {
baseCtx context.Context
externalBrowser string
goroutinesNumber int
}
type args struct {
singlePrice string
rangedPrice string
}
var placeholderFields = fields{
baseCtx: context.Background(),
externalBrowser: "",
goroutinesNumber: 10,
}
//single := "18,000円 (税込 19,800円)"
//ranged := "(他15,000円16,000円もあります)"
tests := []struct {
name string
fields fields
args args
want int32
}{
//Cases
{name: "Full success", fields: placeholderFields, args: args{
singlePrice: "18,000円 (税込 19,800円)",
rangedPrice: "(他15,000円16,000円もあります)",
}, want: 16500},
{name: "Single price only success 1", fields: placeholderFields, args: args{
singlePrice: "18,000円 (税込 19,800円)",
rangedPrice: "",
}, want: 19800},
{name: "Single price only success 2", fields: placeholderFields, args: args{
singlePrice: "18,000円 (税込 19,800円)",
rangedPrice: "no numbers in this string",
}, want: 19800},
{name: "zero single price success 1", fields: placeholderFields, args: args{
singlePrice: "",
rangedPrice: "",
}, want: 0},
{name: "zero single price success 2", fields: placeholderFields, args: args{
singlePrice: "no numbers in this string",
rangedPrice: "",
}, want: 0},
{name: "zero single price success 3", fields: placeholderFields, args: args{
singlePrice: "no numbers in this string",
rangedPrice: "no numbers in this string",
}, want: 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Parser{
baseCtx: tt.fields.baseCtx,
externalBrowser: tt.fields.externalBrowser,
goroutinesNumber: tt.fields.goroutinesNumber,
}
if got := s.processPrices(tt.args.singlePrice, tt.args.rangedPrice); got != tt.want {
t.Errorf("processPrices() = %v, want %v", got, tt.want)
}
})
}
}