Modern UI contract: advertising read, advertising.accept and budget.commit
The advertising read lists boards, shirt and TV rights with their contract and open offers, the three budgets and the finance preview. advertising.accept takes an offer by id, budget.commit sets a budget, both through the desk's own checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f71f072774
commit
4372e6b78a
3 files changed
+109
-1
No files matched your search
@@ -260,6 +260,32 @@ int main(int argc, char** argv) {
|
||||
"code")) == "stale_quote" && rev == before + 2, "a used quote is gone");
|
||||
}
|
||||
}
|
||||
// advertising: the first acceptable offer, a budget
|
||||
{
|
||||
const J ads = session.ui_read(O{{"kind", "advertising"}}, rev);
|
||||
check(s(at(ads, "messageType")) == "snapshot" && at(at(ads, "data"), "boards").array() &&
|
||||
at(at(ads, "data"), "boards").array()->size() == 14, "advertising read");
|
||||
std::string offer;
|
||||
const auto pick = [&](const J& place) {
|
||||
if (const auto* list = at(place, "offers").array())
|
||||
for (const auto& o : *list)
|
||||
if (offer.empty() && truth(at(o, "allowed"))) offer = s(at(o, "id"));
|
||||
};
|
||||
pick(at(at(ads, "data"), "shirt"));
|
||||
pick(at(at(ads, "data"), "television"));
|
||||
if (const auto* boards = at(at(ads, "data"), "boards").array())
|
||||
for (const auto& b : *boards) pick(b);
|
||||
const uint64_t before = rev;
|
||||
if (!offer.empty()) {
|
||||
const J done = session.ui_command(cmd("request:w1", "advertising.accept", O{{"offerId", offer}}), rev);
|
||||
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "advertising: %s\n", cli::dump_json(done).c_str());
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "advertising offer accepted");
|
||||
}
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
check(s(at(session.ui_command(cmd("request:w2", "advertising.accept", O{{"offerId", "offer:ad-3-99"}}), rev), "code")) ==
|
||||
"unknown_offer" && modern::save_stream(session.state()) == kept, "unknown offer refused");
|
||||
std::printf("(advertising offer %s)\n", offer.empty() ? "none" : offer.c_str());
|
||||
}
|
||||
// session.advance: three kickoffs, each one revision, the date moves on
|
||||
{
|
||||
const std::string date_before = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));
|
||||
|
||||
Reference in new issue
Block a user