Connect native indoor standings to real season points and extend CI coverage (by Codex)
This commit is contained in:
1 parent
d30e83c0a5
commit
0842cb3458
19 files changed
+296
-20
No files matched your search
@@ -0,0 +1,107 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void check(bool v, const char *s) {
|
||||
if (!v)
|
||||
throw std::runtime_error(s);
|
||||
}
|
||||
template <class F> void rejects(F f) {
|
||||
bool yes = false;
|
||||
try {
|
||||
f();
|
||||
} catch (const std::exception &) {
|
||||
yes = true;
|
||||
}
|
||||
check(yes, "invalid indoor read accepted");
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
const Json meta = {{"contractVersion", "bmh-modern-ui@draft1"},
|
||||
{"careerId", "career:test"},
|
||||
{"worldId", "world:test"},
|
||||
{"worldRevision", "1"},
|
||||
{"stateRevision", "5"},
|
||||
{"scope",
|
||||
{{"role", "club"},
|
||||
{"managerId", "manager:one"},
|
||||
{"teamId", "club:one"}}}};
|
||||
Json b;
|
||||
for (auto *k : {"session", "desktop", "camps", "indoor-standings"})
|
||||
b[k] = {
|
||||
{"messageType", "snapshot"}, {"meta", meta}, {"data", {{"kind", k}}}};
|
||||
b["desktop"]["data"].update(
|
||||
{{"manager", {{"id", "manager:one"}}},
|
||||
{"team", {{"id", "club:one"}}},
|
||||
{"accounts",
|
||||
{{"cash", {{"minor", "0"}, {"currency", "EUR"}, {"minorUnits", 2}}}}}});
|
||||
b["camps"]["data"]["camps"] = Json::array();
|
||||
auto &d = b["indoor-standings"]["data"];
|
||||
d.update({{"teamId", "club:one"},
|
||||
{"tournaments", 0},
|
||||
{"rows", Json::array()},
|
||||
{"footer", ""},
|
||||
{"indoor", false},
|
||||
{"scoring", nullptr}});
|
||||
auto empty = engine_indoor_projection(b);
|
||||
check(empty["rows"].empty() && empty["tournaments"] == 0,
|
||||
"empty season invented results");
|
||||
d["tournaments"] = 4;
|
||||
d["footer"] = "Synthetic fourth tournament";
|
||||
d["indoor"] = true;
|
||||
d["scoring"] = {{"value", 27}, {"places", Json::array()}};
|
||||
for (int i = 1; i <= 4; ++i)
|
||||
d["scoring"]["places"].push_back({{"rank", i}, {"points", i * 27}});
|
||||
for (int i = 0; i < 16; ++i)
|
||||
d["rows"].push_back({{"rank", i + 1},
|
||||
{"points", i ? 16 - i : 0},
|
||||
{"team",
|
||||
{{"id", "club:" + std::to_string(i)},
|
||||
{"name", "Synthetic club " + std::to_string(i)}}}});
|
||||
d["rows"][15]["points"] = 0;
|
||||
const auto before = b;
|
||||
const auto p = engine_indoor_projection(b);
|
||||
check(b == before && p["rows"].size() == 16 && p["rows"][0]["points"] == 0 &&
|
||||
p["rows"][15]["rank"] == 16,
|
||||
"actual rows or zero points lost");
|
||||
check(p["footer"] == d["footer"] && p["scoring"] == d["scoring"],
|
||||
"original info changed");
|
||||
auto values = p.at("rows").get<std::vector<Json>>();
|
||||
const auto sorted =
|
||||
sort_report_rows(values, {{"key", "points"}, {"desc", true}});
|
||||
check(sorted[14].at("rank") == 1 && sorted[15].at("rank") == 16,
|
||||
"equal point sort lost original ranking order");
|
||||
for (int fault = 0; fault < 9; ++fault) {
|
||||
auto bad = b;
|
||||
auto &v = bad["indoor-standings"];
|
||||
if (fault == 0)
|
||||
v["meta"]["stateRevision"] = "6";
|
||||
if (fault == 1)
|
||||
v["data"]["teamId"] = "wrong";
|
||||
if (fault == 2)
|
||||
v["data"]["rows"][1]["team"]["id"] = "club:0";
|
||||
if (fault == 3)
|
||||
v["data"]["rows"][1]["rank"] = 1;
|
||||
if (fault == 4)
|
||||
v["data"]["rows"][0]["points"] = -1;
|
||||
if (fault == 5)
|
||||
v["data"]["rows"].erase(0);
|
||||
if (fault == 6)
|
||||
v["data"]["tournaments"] = 0;
|
||||
if (fault == 7)
|
||||
v["data"]["scoring"]["places"][0]["points"] = -1;
|
||||
if (fault == 8)
|
||||
for (auto &row : bad)
|
||||
row["meta"]["scope"]["role"] = "national";
|
||||
rejects([&] { engine_indoor_projection(bad); });
|
||||
}
|
||||
std::cout << "indoor actual rows, zero/empty, owner, context, rank and info "
|
||||
"checks passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
Reference in new issue
Block a user