This commit is contained in:
parent
320af54b3d
commit
4666c1995f
14 changed files with 876 additions and 346 deletions
|
|
@ -107,9 +107,13 @@ int main(int argc, char** argv) {
|
|||
srv.BodyHas("/shop/fp6-pmos", "\"brand\":{\"@type\":\"Brand\",\"name\":\"Fairphone\"}",
|
||||
"product carries the hardware brand");
|
||||
|
||||
// One entry per (transit tier, price) the carrier table produces — three,
|
||||
// for the fixture's NL/DE/GB. Not a fixed property of the code any more:
|
||||
// it is whatever the carrier prices, which is the point.
|
||||
// One entry per (transit tier, price) the carrier table produces, for the
|
||||
// destinations the shop actually sells to — two, since the fixture prices
|
||||
// NL/DE/GB/CH and checkout refuses DE and GB pending their producer
|
||||
// registrations. Not a fixed property of the code: it is whatever the
|
||||
// carrier prices INTERSECTED with where the shop sells, and publishing a
|
||||
// rate to a country checkout would decline is an offer that cannot be
|
||||
// accepted.
|
||||
const Json::Value* shipping = nullptr;
|
||||
if (group) {
|
||||
if (const Json::Value* v = group->Find("hasVariant"); v && v->IsArray()
|
||||
|
|
@ -119,27 +123,33 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
}
|
||||
Check(shipping && shipping->IsArray() && shipping->array.size() == 3,
|
||||
Check(shipping && shipping->IsArray() && shipping->array.size() == 2,
|
||||
"shipping details group the carrier's rates");
|
||||
// The advertised rate IS the carrier's single-unit price, and a
|
||||
// destination the table does not cover is never advertised.
|
||||
// The advertised rate IS the carrier's single-unit price. Neither a
|
||||
// destination the table does not cover (AU) nor one the policy refuses
|
||||
// (DE, priced at €25 in the fixture) is ever advertised.
|
||||
if (shipping && shipping->IsArray()) {
|
||||
std::vector<std::string> rates;
|
||||
bool au = false;
|
||||
bool refused = false;
|
||||
for (const Json::Value& detail : shipping->array) {
|
||||
if (const Json::Value* rate = detail.Find("shippingRate")) {
|
||||
rates.emplace_back(rate->Str("value"));
|
||||
}
|
||||
if (const Json::Value* dest = detail.Find("shippingDestination")) {
|
||||
if (const Json::Value* cc = dest->Find("addressCountry"); cc && cc->IsArray()) {
|
||||
for (const Json::Value& c : cc->array) au = au || c.string == "AU";
|
||||
for (const Json::Value& c : cc->array) {
|
||||
au = au || c.string == "AU";
|
||||
refused = refused || c.string == "DE" || c.string == "GB";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::ranges::sort(rates);
|
||||
Check(rates == std::vector<std::string>{ "15.00", "25.00", "55.00" },
|
||||
Check(rates == std::vector<std::string>{ "15.00", "55.00" },
|
||||
"published shipping rates come from the carrier table");
|
||||
Check(!au, "an uncovered destination is not advertised");
|
||||
Check(!refused, "a destination the policy refuses is not advertised");
|
||||
}
|
||||
|
||||
if (srv.ShopOpen()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue