forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.go
116 lines (110 loc) · 3.34 KB
/
validation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package currency
import (
"testing"
"github.com/prebid/prebid-server/v3/errortypes"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/stretchr/testify/assert"
)
func TestValidateCustomRates(t *testing.T) {
boolTrue := true
boolFalse := false
testCases := []struct {
desc string
inBidReqCurrencies *openrtb_ext.ExtRequestCurrency
outCurrencyError error
}{
{
desc: "nil input, no errors expected",
inBidReqCurrencies: nil,
outCurrencyError: nil,
},
{
desc: "empty custom currency rates but UsePBSRates is set to false, we don't return error nor warning",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{},
UsePBSRates: &boolFalse,
},
outCurrencyError: nil,
},
{
desc: "empty custom currency rates but UsePBSRates is set to true, no need to return error because we can use PBS rates",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{},
UsePBSRates: &boolTrue,
},
outCurrencyError: nil,
},
{
desc: "UsePBSRates is nil and defaults to true, bidExt fromCurrency is invalid, expect bad input error",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{
"FOO": {
"GBP": 1.2,
"MXN": 0.05,
"JPY": 0.95,
},
},
},
outCurrencyError: &errortypes.BadInput{Message: "currency code FOO is not recognized or malformed"},
},
{
desc: "UsePBSRates set to false, bidExt fromCurrency is invalid, expect bad input error",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{
"FOO": {
"GBP": 1.2,
"MXN": 0.05,
"JPY": 0.95,
},
},
UsePBSRates: &boolFalse,
},
outCurrencyError: &errortypes.BadInput{Message: "currency code FOO is not recognized or malformed"},
},
{
desc: "UsePBSRates set to false, some of the bidExt 'to' Currencies are invalid, expect bad input error when parsing the first invalid currency code",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{
"USD": {
"FOO": 10.0,
"MXN": 0.05,
},
},
UsePBSRates: &boolFalse,
},
outCurrencyError: &errortypes.BadInput{Message: "currency code FOO is not recognized or malformed"},
},
{
desc: "UsePBSRates set to false, some of the bidExt 'from' and 'to' currencies are invalid, expect bad input error when parsing the first invalid currency code",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{
"FOO": {
"MXN": 0.05,
"CAD": 0.95,
},
},
UsePBSRates: &boolFalse,
},
outCurrencyError: &errortypes.BadInput{Message: "currency code FOO is not recognized or malformed"},
},
{
desc: "All 3-digit currency codes exist, expect no error",
inBidReqCurrencies: &openrtb_ext.ExtRequestCurrency{
ConversionRates: map[string]map[string]float64{
"USD": {
"MXN": 0.05,
},
"MXN": {
"JPY": 10.0,
"EUR": 10.95,
},
},
UsePBSRates: &boolFalse,
},
},
}
for _, tc := range testCases {
actualErr := ValidateCustomRates(tc.inBidReqCurrencies)
assert.Equal(t, tc.outCurrencyError, actualErr, tc.desc)
}
}