Render typed bilingual news and preserve historical journal scope (by Codex)
This commit is contained in:
1 parent
1eb5e99847
commit
950d79d529
16 files changed
+6858
-81
No files matched your search
@@ -0,0 +1 @@
|
||||
{"source_commit":"7dbf70f5be5505af41fa532e37dd27aced86bd76","catalogue_sha256":"e249142f2635c897803d3016eb05d3f94297a75a013316fd536f82f2ef982339","description":"Synthetic own authored catalogue events and expected HTML-contract snapshots; no original game data.","cases":[{"name":"match-win:club:de","event":{"id":"demo:match-win:8a50928da6fcf6f9","type":"match.result","variant":"win","date":"2027-07-07","scope":{"kind":"club","id":"example-nordstadt","name":"FC Nordstadt"},"data":{"competition":{"id":"example-league","name":"Regionalliga","names":{"de":"Regionalliga","en":"Regional League"},"kind":"league"},"opponent":{"id":"example-hafen","name":"SV Hafenstadt","kind":"club"},"score":{"for":2,"against":1}},"demo":true},"context":{"language":"de"},"result":{"ok":true,"article":{"schema":"bmh-news-article@1","catalogueVersion":1,"id":"evt-1f772e4a07a5042c","eventId":"demo:match-win:8a50928da6fcf6f9","eventType":"match.result","templateId":"match-win","date":"2027-07-07","kind":"fixture","tone":"positive","scope":{"id":"example-nordstadt","name":"FC Nordstadt","kind":"club"},"dedupeKey":"[\"club\",\"example-nordstadt\",\"demo:match-win:8a50928da6fcf6f9\"]","fingerprint":"47ab160ae2128b71","event":{"id":"demo:match-win:8a50928da6fcf6f9","type":"match.result","date":"2027-07-07","scope":{"id":"example-nordstadt","name":"FC Nordstadt","kind":"club"},"data":{"competition":{"id":"example-league","name":"Regionalliga","kind":"league","names":{"de":"Regionalliga","en":"Regional League"}},"opponent":{"id":"example-hafen","name":"SV Hafenstadt","kind":"club"},"score":{"for":2,"against":1}},"variant":"win","templateId":"match-win","demo":true},"language":"de","headline":"Erfolg für FC Nordstadt","body":"FC Nordstadt gewinnt gegen SV Hafenstadt mit 2:1. Die Partie gehörte zu Regionalliga.","translations":{"de":{"headline":"Erfolg für FC Nordstadt","body":"FC Nordstadt gewinnt gegen SV Hafenstadt mit 2:1. Die Partie gehörte zu Regionalliga."},"en":{"headline":"Victory for FC Nordstadt","body":"FC Nordstadt beat SV Hafenstadt 2–1. The match was part of Regional League."}},"demo":true}}},{"name":"match-win:club:en","event":{"id":"demo:match-win:8a50928da6fcf6f9","type":"match.result","variant":"win","date":"2027-07-07","scope":{"kind":"club","id":"example-nordstadt","name":"FC Nordstadt"},"data":{"competition":{"id":"example-league","name":"Regionalliga","names":{"de":"Regionalliga","en":"Regional League"},"kind":"league"},"opponent":{"id":"example-hafen","name":"SV Hafenstadt","kind":"club"},"score":{"for":2,"against":1}},"demo":true},"context":{"language":"en"},"result":{"ok":true,"article":{"schema":"bmh-news-article@1","catalogueVersion":1,"id":"evt-1f772e4a07a5042c","eventId":"demo:match-win:8a50928da6fcf6f9","eventType":"match.result","templateId":"match-win","date":"2027-07-07","kind":"fixture","tone":"positive","scope":{"id":"example-nordstadt","name":"FC Nordstadt","kind":"club"},"dedupeKey":"[\"club\",\"example-nordstadt\",\"demo:match-win:8a50928da6fcf6f9\"]","fingerprint":"47ab160ae2128b71","event":{"id":"demo:match-win:8a50928da6fcf6f9","type":"match.result","date":"2027-07-07","scope":{"id":"example-nordstadt","name":"FC Nordstadt","kind":"club"},"data":{"competition":{"id":"example-league","name":"Regionalliga","kind":"league","names":{"de":"Regionalliga","en":"Regional League"}},"opponent":{"id":"example-hafen","name":"SV Hafenstadt","kind":"club"},"score":{"for":2,"against":1}},"variant":"win","templateId":"match-win","demo":true},"language":"en","headline":"Victory for FC Nordstadt","body":"FC Nordstadt beat SV Hafenstadt 2–1. The match was part of Regional League.","translations":{"de":{"headline":"Erfolg für FC Nordstadt","body":"FC Nordstadt gewinnt gegen SV Hafenstadt mit 2:1. Die Partie gehörte zu Regionalliga."},"en":{"headline":"Victory for FC Nordstadt","body":"FC Nordstadt beat SV Hafenstadt 2–1. The match was part of Regional League."}},"demo":true}}},{"name":"match-win:national:de","event":{"id":"demo:match-win:599266f6a6d2d79b","type":"match.result","variant":"win","date":"2027-07-07","scope":{"kind":"national","id":"national-de","name":"Deutschland","names":{"de":"Deutschland","en":"Germany"}},"data":{"competition":{"id":"example-international","name":"Länderspiel","names":{"de":"Länderspiel","en":"International Match"},"kind":"competition"},"opponent":{"kind":"national","id":"national-at","name":"Österreich","names":{"de":"Österreich","en":"Austria"}},"score":{"for":2,"against":1}},"demo":true},"context":{"language":"de"},"result":{"ok":true,"article":{"schema":"bmh-news-article@1","catalogueVersion":1,"id":"evt-d149e8841f861660","eventId":"demo:match-win:599266f6a6d2d79b","eventType":"match.result","templateId":"match-win","date":"2027-07-07","kind":"fixture","tone":"positive","scope":{"id":"national-de","name":"Deutschland","kind":"national","names":{"de":"Deutschland","en":"Germany"}},"dedupeKey":"[\"national\",\"national-de\",\"demo:match-win:599266f6a6d2d79b\"]","fingerpLine truncated
|
||||
@@ -0,0 +1,237 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/news_catalog.hpp"
|
||||
#include "modern/ui/news_journal.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool yes, const std::string &message) {
|
||||
if (!yes)
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
void no(const Json &value, const std::string &code) {
|
||||
require(!value.value("ok", false) && value.at("error").at("code") == code,
|
||||
"Expected explicit " + code + ": " + value.dump());
|
||||
}
|
||||
} // namespace
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
require(argc == 3, "Catalogue and synthetic reference paths required");
|
||||
const auto catalog = NewsCatalog::load(argv[1]);
|
||||
const auto reference = Json::parse(bmh::editor::read_file(argv[2]));
|
||||
require(catalog.registry().size() == 113,
|
||||
"113 own authored templates registered");
|
||||
size_t passed = 0, mismatches = 0;
|
||||
for (const auto &test : reference.at("cases")) {
|
||||
const auto result =
|
||||
catalog.from_event(test.at("event"), test.at("context"));
|
||||
if (news_canonical(result) != news_canonical(test.at("result"))) {
|
||||
++mismatches;
|
||||
if (mismatches <= 4)
|
||||
std::cerr << "Parity mismatch: " << test.at("name")
|
||||
<< "\nActual: " << result.dump()
|
||||
<< "\nExpected: " << test.at("result").dump() << '\n';
|
||||
if (mismatches > 4)
|
||||
std::cerr << "Additional mismatch " << test.at("name") << " actual "
|
||||
<< result.value("article", Json::object())
|
||||
.value("translations", Json())
|
||||
<< "\n";
|
||||
continue;
|
||||
}
|
||||
require(catalog.validate_article(result.at("article")).value("ok", false),
|
||||
"Persisted bilingual snapshot validates");
|
||||
++passed;
|
||||
}
|
||||
require(mismatches == 0, "Own HTML/native semantic contract mismatches: " +
|
||||
std::to_string(mismatches));
|
||||
for (const auto &t : catalog.registry()) {
|
||||
auto fixture = catalog.example(t.at("id"));
|
||||
require(fixture.value("ok", false),
|
||||
"Explicit example available " + t.at("id").get<std::string>());
|
||||
require(catalog.from_event(fixture.at("event")).value("ok", false),
|
||||
"Explicit demo event validates " + t.at("id").get<std::string>());
|
||||
for (const auto &[key, schema] : t.at("parameters").items()) {
|
||||
auto absent = fixture.at("event");
|
||||
if (schema.value("source", "") == "scope")
|
||||
absent.erase("scope");
|
||||
else
|
||||
absent["data"].erase(key);
|
||||
require(!catalog.from_event(absent).value("ok", false),
|
||||
"Missing required field cannot invent facts: " + key);
|
||||
auto bad = fixture.at("event");
|
||||
if (schema.value("source", "") == "scope")
|
||||
bad["scope"]["kind"] = "unknown";
|
||||
else
|
||||
bad["data"][key] = Json::array({"invalid"});
|
||||
require(!catalog.from_event(bad).value("ok", false),
|
||||
"Typed registry rejects malformed data: " + key);
|
||||
}
|
||||
}
|
||||
auto event = catalog.example("transfer-signed").at("event");
|
||||
const auto raw_event = event;
|
||||
event["data"]["player"]["name"] = "Zoë Özdemir <img src=x> {{club}}";
|
||||
const auto de = catalog.from_event(event),
|
||||
en = catalog.from_event(event, {{"language", "en"}});
|
||||
require(de.at("article").at("id") == en.at("article").at("id") &&
|
||||
de.at("article").at("fingerprint") ==
|
||||
en.at("article").at("fingerprint"),
|
||||
"Locale cannot change occurrence identity");
|
||||
require(de.at("article").at("body").get<std::string>().find(
|
||||
"<img src=x> {{club}}") != std::string::npos,
|
||||
"Payload is literal text, never markup or a second template");
|
||||
auto detached = de.at("article");
|
||||
event["data"]["player"]["name"] = "Renamed";
|
||||
require(detached.at("body").get<std::string>().find("Zoë Özdemir") !=
|
||||
std::string::npos,
|
||||
"Article owns immutable original facts");
|
||||
event = raw_event;
|
||||
event["type"] = "unknown";
|
||||
no(catalog.from_event(event), "unknown_news_event");
|
||||
event = raw_event;
|
||||
event["data"]["unknown"] = 1;
|
||||
no(catalog.from_event(event), "unknown_news_parameter");
|
||||
event = raw_event;
|
||||
event["scope"]["kind"] = "national";
|
||||
no(catalog.from_event(event), "unsupported_news_scope");
|
||||
no(catalog.from_event(raw_event, {{"language", "xx"}}),
|
||||
"invalid_news_context");
|
||||
no(catalog.from_event(raw_event, {{"asOf", "2027-01-01"}}),
|
||||
"future_news_event");
|
||||
auto result = catalog.example("match-win").at("event");
|
||||
result["data"]["score"] = {{"for", 0}, {"against", 2}};
|
||||
no(catalog.from_event(result), "inconsistent_news_event");
|
||||
event = raw_event;
|
||||
event["data"]["fee"] = {
|
||||
{"minor", "100"}, {"currency", "EUR"}, {"minorUnits", 0}};
|
||||
no(catalog.from_event(event), "invalid_news_parameter");
|
||||
event = raw_event;
|
||||
event["data"]["player"]["name"] = std::string("bad\xc0\xaf");
|
||||
no(catalog.from_event(event), "invalid_news_parameter");
|
||||
for (const auto *id : {"transfer-fee-undisclosed", "sale-fee-undisclosed",
|
||||
"contract-basic", "loan-end-undisclosed"}) {
|
||||
event = catalog.example(id).at("event");
|
||||
event.erase("variant");
|
||||
const auto minimal = catalog.from_event(event);
|
||||
require(minimal.value("ok", false) &&
|
||||
minimal.at("article").at("templateId") == id,
|
||||
"Absent fee/wage/end uses only known facts");
|
||||
}
|
||||
std::string error;
|
||||
for (const auto &[precision, minor, expected] :
|
||||
std::vector<std::tuple<int, std::string, int64_t>>{{0, "12", 1200},
|
||||
{1, "12", 120},
|
||||
{2, "12", 12},
|
||||
{3, "120", 12},
|
||||
{4, "1200", 12}}) {
|
||||
auto money = news_money_from_dto(
|
||||
{{"minor", minor}, {"currency", "EUR"}, {"minorUnits", precision}},
|
||||
error);
|
||||
require(money && money->minor == expected && error.empty(),
|
||||
"Explicit exact DTO scaling");
|
||||
}
|
||||
for (const auto &value : Json::array(
|
||||
{Json{{"minor", "125"}, {"currency", "EUR"}, {"minorUnits", 3}},
|
||||
Json{{"minor", "-12"}, {"currency", "EUR"}, {"minorUnits", 2}},
|
||||
Json{{"minor", "12"}, {"currency", "JPY"}, {"minorUnits", 0}},
|
||||
Json{{"minor", "900000000000001"},
|
||||
{"currency", "EUR"},
|
||||
{"minorUnits", 2}},
|
||||
Json{{"minor", 12}, {"currency", "EUR"}, {"minorUnits", 2}},
|
||||
Json{{"minor", "12"}, {"currency", "EUR"}},
|
||||
Json{{"minor", "0012"}, {"currency", "EUR"}, {"minorUnits", 2}}}))
|
||||
require(!news_money_from_dto(value, error) && !error.empty(),
|
||||
"Unknown/inexact/negative DTO units never silently convert");
|
||||
static_assert(!std::is_convertible_v<int64_t, NewsMinorMoney>);
|
||||
NewsEvent typed;
|
||||
typed.id = "typed:arrival";
|
||||
typed.type = "transfer.signed";
|
||||
typed.date = "2027-07-07";
|
||||
typed.scope = {NewsScopeKind::club, {"club:typed", "FC Typed", {}}};
|
||||
typed.data = raw_event.at("data");
|
||||
require(catalog.from_event(typed).value("ok", false),
|
||||
"Typed semantic event API");
|
||||
typed.scope.kind = static_cast<NewsScopeKind>(99);
|
||||
no(catalog.from_event(typed), "invalid_news_event");
|
||||
for (int bad_case = 0; bad_case < 4; ++bad_case) {
|
||||
auto broken = catalog.data();
|
||||
if (bad_case == 0)
|
||||
broken["templates"][0]["parameters"]["score"]["type"] = "guessed";
|
||||
if (bad_case == 1)
|
||||
broken["templates"][0]["guards"] = Json::array({"unknown_rule"});
|
||||
if (bad_case == 2)
|
||||
broken["templates"][0]["de"]["headline"] = "{{undeclared}}";
|
||||
if (bad_case == 3)
|
||||
broken["templates"][1]["id"] = broken["templates"][0]["id"];
|
||||
bool rejected = false;
|
||||
try {
|
||||
NewsCatalog invalid(broken);
|
||||
} catch (...) {
|
||||
rejected = true;
|
||||
}
|
||||
require(rejected, "Malformed typed registry rejected before rendering");
|
||||
}
|
||||
auto journal = empty_news_journal();
|
||||
const auto article = catalog.from_event(raw_event).at("article");
|
||||
const auto posted = publish_news_article(journal, catalog, article);
|
||||
require(posted.value("ok", false) && !posted.at("deduped").get<bool>() &&
|
||||
valid_news_journal(journal),
|
||||
"Validated explicit publication");
|
||||
const auto initial = journal;
|
||||
require(
|
||||
publish_news_article(
|
||||
journal, catalog,
|
||||
catalog.from_event(raw_event, {{"language", "en"}}).at("article"))
|
||||
.at("deduped") == true &&
|
||||
journal == initial,
|
||||
"Locale replay cannot rewrite stored bilingual snapshot or create a "
|
||||
"row");
|
||||
require(publish_news_article(journal, catalog, article).at("deduped") ==
|
||||
true &&
|
||||
journal == initial,
|
||||
"Replay is a write-free dedupe read");
|
||||
journal["items"][0]["folder"] = "trash";
|
||||
const auto deleted = journal;
|
||||
auto restored = Json::parse(journal.dump());
|
||||
require(publish_news_article(restored, catalog, article).at("deduped") ==
|
||||
true &&
|
||||
restored == deleted,
|
||||
"Persisted deletion ledger survives reload and suppresses replay");
|
||||
require(publish_news_article(journal, catalog, article).at("deduped") ==
|
||||
true &&
|
||||
journal == deleted,
|
||||
"Delete/replay cannot resurrect or duplicate");
|
||||
auto conflict = raw_event;
|
||||
conflict["data"]["fee"]["minor"] = 1;
|
||||
no(publish_news_article(journal, catalog,
|
||||
catalog.from_event(conflict).at("article")),
|
||||
"news_event_id_conflict");
|
||||
require(journal == deleted, "Conflict has no partial publication");
|
||||
require(!news_row_visible(initial.at("items")[0],
|
||||
{{"kind", "national"}, {"id", "national-de"}}) &&
|
||||
!news_row_visible(initial.at("items")[0],
|
||||
{{"kind", "club"}, {"id", "other"}}),
|
||||
"National/other club cannot see historical club finance/personnel");
|
||||
require(news_row_text(initial.at("items")[0], "en").at("body") ==
|
||||
article.at("translations").at("en").at("body"),
|
||||
"Both immutable language snapshots are directly projected");
|
||||
auto changed = catalog.data();
|
||||
for (auto &t : changed["templates"])
|
||||
if (t.at("id") == detached.at("templateId"))
|
||||
t["de"]["headline"] = "Neue Formulierung";
|
||||
NewsCatalog newer(changed);
|
||||
require(newer.validate_article(detached).value("ok", false) &&
|
||||
newer.validate_article(detached).at("article").at("headline") ==
|
||||
detached.at("headline"),
|
||||
"Wording edits never rewrite archived snapshots");
|
||||
std::cout
|
||||
<< "native press renderer: " << passed
|
||||
<< " full parity cases plus registry/types/money/scope/dedupe passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,13 @@
|
||||
#include "modern/ui/demo_news.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
#include "modern/ui/news_catalog.hpp"
|
||||
#include "modern/ui/news_journal.hpp"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
using namespace bmh::modern_ui;
|
||||
namespace {
|
||||
void require(bool yes, const char *why) {
|
||||
@@ -89,12 +92,55 @@ void provider(Fixture &f) {
|
||||
"Current manager and club not interpolated");
|
||||
auto changed = s;
|
||||
changed["managers"][0] = {{"name", "Other Manager"}, {"club", "club:news-1"}};
|
||||
require(demo_news_view(*f.world, changed).at("items").empty() &&
|
||||
demo_news_unread(changed) == 0,
|
||||
"Other manager's club must not inherit or rename old club articles");
|
||||
changed = s;
|
||||
changed["managers"][0]["name"] = "Renamed Manager";
|
||||
require(demo_news_view(*f.world, changed)
|
||||
.at("items")[0]
|
||||
.at("body")
|
||||
.get<std::string>()
|
||||
.find("Other Manager. Synthetic Club 1") != std::string::npos,
|
||||
"Manager change retained stale template identity");
|
||||
.find("Synthetic Manager. Synthetic Club 0") !=
|
||||
std::string::npos,
|
||||
"Historical owner text must never be rewritten by the current name");
|
||||
auto national = s;
|
||||
national["career"] = {{"role", "national"}, {"surface", "outdoor"}};
|
||||
require(demo_news_view(*f.world, national).at("items").empty() &&
|
||||
demo_news_unread(national) == 0 &&
|
||||
demo_news_view(*f.world, national).at("club_name") ==
|
||||
"Deutschland",
|
||||
"National header must never expose club financial stories");
|
||||
reject(national, {{"kind", "read"}, {"id", "season"}}, *f.world);
|
||||
const auto national_before = national;
|
||||
require(edit_demo_news(national, {{"kind", "read-all"}, {"folder", "inbox"}},
|
||||
*f.world)
|
||||
.empty() &&
|
||||
national == national_before,
|
||||
"National read-all must not alter hidden club rows");
|
||||
auto legacy = s;
|
||||
Json raw = Json::array();
|
||||
for (const auto &item : s.at("news").at("items")) {
|
||||
auto row = item;
|
||||
row.erase("scope");
|
||||
row.erase("owner");
|
||||
raw.push_back(row);
|
||||
}
|
||||
raw[0]["body"] = "Hallo {{manager}}. {{club}}.";
|
||||
legacy["news"] = {{"version", 1}, {"items", raw}};
|
||||
const auto legacy_before = legacy;
|
||||
require(demo_news_view(*f.world, legacy).at("items").empty() &&
|
||||
legacy == legacy_before,
|
||||
"Reading unbound v1 cannot guess owner or mutate state");
|
||||
require(
|
||||
migrate_demo_news(legacy, *f.world) &&
|
||||
legacy.at("news").at("items").empty() &&
|
||||
legacy.at("news").at("unbound") == raw &&
|
||||
demo_news_view(*f.world, legacy).at("unbound_count") == 12,
|
||||
"Ownerless old article facts remain intact in separate unbound storage");
|
||||
const auto migrated = legacy;
|
||||
require(migrate_demo_news(legacy, *f.world) && legacy == migrated,
|
||||
"Conservative migration is idempotent");
|
||||
require(demo_news_view(*f.world, s, "inbox", "FINANZEN").at("items").size() ==
|
||||
2 &&
|
||||
demo_news_view(*f.world, s, "inbox", "VERTRAGSGESPRÄCHE")
|
||||
@@ -196,7 +242,7 @@ void provider(Fixture &f) {
|
||||
invalid["news"]["query"] = "must-be-local";
|
||||
bad.push_back(invalid);
|
||||
invalid = initial;
|
||||
for (int i = 12; i < 101; ++i) {
|
||||
for (int i = 12; i < 501; ++i) {
|
||||
auto m = invalid["news"]["items"][0];
|
||||
m["id"] = "test-" + std::to_string(i);
|
||||
invalid["news"]["items"].push_back(m);
|
||||
@@ -289,12 +335,131 @@ void source(Fixture &f) {
|
||||
base.erase("news");
|
||||
require(rest == base, "Mailbox actions modified unrelated presentation data");
|
||||
}
|
||||
void accepted_start_identity(Fixture &f) {
|
||||
DemoSource source(f.world);
|
||||
Json options = {{"duration", 5}, {"difficulty", 3}, {"players", 1},
|
||||
{"mode", 3}, {"league", true}, {"world", true}};
|
||||
Json managers = Json::array({{{"name", "FreshCoach"},
|
||||
{"club", "club:news-1"},
|
||||
{"portrait", 4},
|
||||
{"portrait_style", "painted"},
|
||||
{"strength_choice", 1}}});
|
||||
require(source
|
||||
.apply({source.snapshot().revision,
|
||||
"start",
|
||||
{{"setup", options}, {"managers", managers}}})
|
||||
.ok,
|
||||
"Actual accepted new career start");
|
||||
const auto original = source.snapshot().state.at("news");
|
||||
require(original.at("items").size() == 12,
|
||||
"Known club demo starts with existing journal fixtures");
|
||||
for (const auto &row : original.at("items"))
|
||||
require(row.at("scope").at("id") == "club:news-1" &&
|
||||
row.at("owner").at("name") == "FreshCoach" &&
|
||||
row.at("owner").at("id") == "portrait:4",
|
||||
"New start freezes accepted person and nondefault club, never "
|
||||
"fresh defaults");
|
||||
require(original.at("items")[0].at("body").get<std::string>().find(
|
||||
"FreshCoach. Synthetic Club 1") != std::string::npos,
|
||||
"Actual start story uses confirmed identity");
|
||||
managers[0]["name"] = "LaterName";
|
||||
managers.push_back({{"name", "OtherCoach"},
|
||||
{"club", "club:news-0"},
|
||||
{"portrait", 1},
|
||||
{"portrait_style", "photo"},
|
||||
{"strength_choice", 1}});
|
||||
require(source.apply({source.snapshot().revision, "managers", managers}).ok &&
|
||||
source.snapshot().state.at("news") == original,
|
||||
"Join/name updates cannot rewrite historical journal");
|
||||
require(source.apply({source.snapshot().revision,
|
||||
"career",
|
||||
{{"kind", "role"}, {"value", "national"}}})
|
||||
.ok &&
|
||||
source.snapshot().state.at("news") == original &&
|
||||
demo_news_unread(source.snapshot().state) == 0,
|
||||
"Role change retains facts but hides club journal");
|
||||
options["league"] = false;
|
||||
managers = Json::array({managers[0]});
|
||||
require(source.apply({source.snapshot().revision,
|
||||
"start",
|
||||
{{"setup", options}, {"managers", managers}}})
|
||||
.ok &&
|
||||
source.snapshot().state.at("news").at("items").empty(),
|
||||
"National-only new start must not receive fresh club stories");
|
||||
}
|
||||
void write_fixtures(Fixture &f, const fs::path &out,
|
||||
const fs::path &catalogue_path) {
|
||||
fs::create_directories(out);
|
||||
fs::copy(f.root / "world", out / "world",
|
||||
fs::copy_options::recursive | fs::copy_options::overwrite_existing);
|
||||
fs::copy_file(f.root / "manifest.json", out / "manifest.json",
|
||||
fs::copy_options::overwrite_existing);
|
||||
DemoSource source(f.world);
|
||||
auto managers = source.snapshot().state.at("managers");
|
||||
managers.push_back({{"name", "Mara König"},
|
||||
{"club", "club:news-1"},
|
||||
{"portrait", 1},
|
||||
{"portrait_style", "painted"},
|
||||
{"strength_choice", 1}});
|
||||
require(source.apply({source.snapshot().revision, "managers", managers}).ok,
|
||||
"Two-owner native scope fixture");
|
||||
auto data = source.snapshot().state;
|
||||
data["desktop"] = default_desktop();
|
||||
const auto original = data;
|
||||
const auto catalog = NewsCatalog::load(catalogue_path);
|
||||
for (const auto &[template_id, scope, id] :
|
||||
std::vector<std::tuple<std::string, Json, std::string>>{
|
||||
{"injury-recovered",
|
||||
{{"kind", "club"},
|
||||
{"id", "club:news-0"},
|
||||
{"name", "Synthetic Club 0"}},
|
||||
"native:press:own"},
|
||||
{"sponsor-signed",
|
||||
{{"kind", "club"},
|
||||
{"id", "club:news-1"},
|
||||
{"name", "Synthetic Club 1"}},
|
||||
"native:press:other"},
|
||||
{"national-squad",
|
||||
{{"kind", "national"},
|
||||
{"id", "national-de"},
|
||||
{"name", "Deutschland"},
|
||||
{"names", {{"de", "Deutschland"}, {"en", "Germany"}}}},
|
||||
"native:press:national"}}) {
|
||||
const auto example = catalog.example(
|
||||
template_id, {{"scope", scope}, {"date", data.at("date")}, {"id", id}});
|
||||
require(example.value("ok", false),
|
||||
"Explicit native catalogue demo fixture");
|
||||
const auto built = catalog.from_event(example.at("event"));
|
||||
require(built.value("ok", false), "Typed catalogue demo renders");
|
||||
require(publish_news_article(data["news"], catalog, built.at("article"))
|
||||
.value("ok", false),
|
||||
"Demo fixture publication");
|
||||
}
|
||||
require(source.load_data(data) == default_desktop(), "Native fixture layout");
|
||||
source.save(out / "scoped.json", default_desktop());
|
||||
auto legacy = original;
|
||||
legacy["news"] = {
|
||||
{"version", 1},
|
||||
{"items", Json::array({{{"id", "legacy-unknown"},
|
||||
{"date", legacy.at("date")},
|
||||
{"kind", "finance"},
|
||||
{"title", "Altbestand {{club}}"},
|
||||
{"body", "Unveränderte Meldung für {{manager}}. "
|
||||
"Historischer Besitzer unbekannt."},
|
||||
{"read", false},
|
||||
{"folder", "inbox"}}})}};
|
||||
// This intentionally old input is consumed by the normal native load path.
|
||||
bmh::editor::write_atomic(out / "legacy.json", legacy.dump(2));
|
||||
}
|
||||
} // namespace
|
||||
int main() {
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
Fixture f;
|
||||
provider(f);
|
||||
source(f);
|
||||
accepted_start_identity(f);
|
||||
if (argc == 4 && std::string(argv[1]) == "--write-fixtures")
|
||||
write_fixtures(f, argv[2], argv[3]);
|
||||
std::cout << "modern news UI tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
|
||||
Reference in new issue
Block a user