task-processor/internal/parsers/mandarake/service_test.go
nquidox 2fa14a7797
All checks were successful
/ Make image (push) Successful in 39s
new price parsing methods + tests
2026-01-05 17:51:02 +03:00

77 lines
2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
})
}
}