price scrapper

This commit is contained in:
nquidox 2026-04-03 20:54:10 +03:00
parent d19f5f7621
commit 8922b8a4f0
7 changed files with 426 additions and 0 deletions

View file

@ -0,0 +1,76 @@
package scrapper
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 := &Scrapper{
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)
}
})
}
}