This commit is contained in:
parent
ae0a07ae1b
commit
2fa14a7797
3 changed files with 156 additions and 22 deletions
77
internal/parsers/mandarake/service_test.go
Normal file
77
internal/parsers/mandarake/service_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue