forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package consumable | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
// This file actually intends to test static/bidder-params/consumable.json | ||
// | ||
// These also validate the format of the external API: request.imp[i].ext.consumable | ||
|
||
// TestValidParams makes sure that the 33across schema accepts all imp.ext fields which we intend to support. | ||
func TestValidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json-schemas. %v", err) | ||
} | ||
|
||
for _, validParam := range validParams { | ||
if err := validator.Validate(openrtb_ext.BidderConsumable, json.RawMessage(validParam)); err != nil { | ||
t.Errorf("Schema rejected Consumable params: %s", validParam) | ||
} | ||
} | ||
} | ||
|
||
// TestInvalidParams makes sure that the Consumable schema rejects all the imp.ext fields we don't support. | ||
func TestInvalidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json-schemas. %v", err) | ||
} | ||
|
||
for _, invalidParam := range invalidParams { | ||
if err := validator.Validate(openrtb_ext.BidderConsumable, json.RawMessage(invalidParam)); err == nil { | ||
t.Errorf("Schema allowed unexpected Consumable params: %s", invalidParam) | ||
} | ||
} | ||
} | ||
|
||
var validParams = []string{ | ||
`{"networkId": 22, "siteId": 1, "unitId": 101, "unitName": "unit-1"}`, | ||
`{"networkId": 22, "siteId": 1, "unitId": 101, "unitName": "-unit-1"}`, // unitName can start with a dash | ||
} | ||
|
||
var invalidParams = []string{ | ||
`{"networkId": 22, "siteId": 1, "unitId": 101, "unitName": "--unit-1"}`, // unitName cannot start -- | ||
`{"networkId": 22, "siteId": 1, "unitId": 101, "unitName": "unit 1"}`, // unitName cannot contain spaces | ||
`{"networkId": 22, "siteId": 1, "unitId": 101, "unitName": "1unit-1"}`, // unitName cannot start with a digit | ||
`{"networkId": "22", "siteId": 1, "unitId": 101, "unitName": 11}`, // networkId must be a number | ||
`{"networkId": 22, "siteId": "1", "unitId": 101, "unitName": 11}`, // siteId must be a number | ||
`{"networkId": 22, "siteId": 1, "unitId": "101", "unitName": 11}`, // unitId must be a number | ||
`{"networkId": 22, "siteId": 1, "unitId": 101, "unitName": 11}`, // unitName must be a string | ||
`{"siteId": 1, "unitId": 101, "unitName": 11}`, // networkId must be present | ||
`{"networkId": 22, "unitId": 101, "unitName": 11}`, // siteId must be present | ||
`{"siteId": 1, "networkId": 22, "unitName": 11}`, // unitId must be present | ||
`{"networkId": 22, "siteId": 1, "unitId": 101}`, // unitName must be present | ||
} |