| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
use std::time::Duration; |
| 70 |
|
| 71 |
use makeover_layout as layout; |
| 72 |
use quasi_declare::declare; |
| 73 |
use quasi_router::{Action, Choice, Consult, Document, Node, Request, Response, RouteError}; |
| 74 |
use quasi_webview::Webview; |
| 75 |
|
| 76 |
use crate::Billing; |
| 77 |
use crate::fee_calculator::{self, Inputs, Outcome, Verdict}; |
| 78 |
use crate::tier_prices::TierPrices; |
| 79 |
|
| 80 |
|
| 81 |
pub const PATH: &str = "/pricing"; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
const COMPARE: &str = "/pricing/compare"; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
const CALCULATOR: &str = "pricing-calculator"; |
| 92 |
|
| 93 |
|
| 94 |
const PAGE: &str = "pricing-page"; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
const MEASURE: layout::Measure = layout::Measure::Contained; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
pub const RESULTS: &str = "results-panel"; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
const SETTLES: Duration = Duration::from_millis(300); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
const ITEM_PRICE: &str = "item_price"; |
| 116 |
const SALES: &str = "sales"; |
| 117 |
const TIER: &str = "tier"; |
| 118 |
const PRICE_MODE: &str = "price_mode"; |
| 119 |
const OTHER_PCT: &str = "other_pct"; |
| 120 |
const OTHER_PER_SALE: &str = "other_per_sale"; |
| 121 |
|
| 122 |
|
| 123 |
const FOUNDER: &str = "founder"; |
| 124 |
|
| 125 |
const LIST: &str = "list"; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
pub struct Pricing { |
| 134 |
|
| 135 |
|
| 136 |
pub billing: Billing, |
| 137 |
|
| 138 |
|
| 139 |
pub founder_window_open: bool, |
| 140 |
|
| 141 |
|
| 142 |
pub changelog_published: bool, |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
struct Dials { |
| 151 |
inputs: Inputs, |
| 152 |
|
| 153 |
tier: &'static str, |
| 154 |
|
| 155 |
mode: &'static str, |
| 156 |
} |
| 157 |
|
| 158 |
impl Dials { |
| 159 |
|
| 160 |
fn read(state: &Pricing, carried: &quasi_router::Params) -> Self { |
| 161 |
let prices = &state.billing.tier_prices; |
| 162 |
let number = |name: &str| { |
| 163 |
carried |
| 164 |
.get(name) |
| 165 |
.map(str::trim) |
| 166 |
.and_then(|v| v.parse::<f64>().ok()) |
| 167 |
}; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
let mode = match (state.founder_window_open, carried.get(PRICE_MODE)) { |
| 173 |
(false, _) => LIST, |
| 174 |
(true, Some(LIST)) => LIST, |
| 175 |
(true, _) => FOUNDER, |
| 176 |
}; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
let (tier, tier_cost) = match carried.get(TIER) { |
| 182 |
Some(raw) => match raw.trim().parse::<f64>() { |
| 183 |
Ok(dollars) if dollars >= 0.0 => (Tier::BASIC.key, dollars), |
| 184 |
_ => { |
| 185 |
let tier = Tier::named(raw).unwrap_or(Tier::BASIC); |
| 186 |
(tier.key, f64::from(tier.price(prices, mode))) |
| 187 |
} |
| 188 |
}, |
| 189 |
None => (Tier::BASIC.key, f64::from(Tier::BASIC.price(prices, mode))), |
| 190 |
}; |
| 191 |
|
| 192 |
let mut inputs = state |
| 193 |
.billing |
| 194 |
.fee_calculator |
| 195 |
.default_inputs(f64::from(prices.basic_std)); |
| 196 |
if let Some(v) = number(ITEM_PRICE) { |
| 197 |
inputs.item_price = v; |
| 198 |
} |
| 199 |
if let Some(v) = number(SALES) { |
| 200 |
inputs.sales_per_month = v; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
if let Some(v) = number(OTHER_PCT) { |
| 206 |
inputs.other_pct = v / 100.0; |
| 207 |
} |
| 208 |
if let Some(v) = number(OTHER_PER_SALE) { |
| 209 |
inputs.other_per_sale = v; |
| 210 |
} |
| 211 |
inputs.tier_cost = tier_cost; |
| 212 |
|
| 213 |
Self { |
| 214 |
inputs: state.billing.fee_calculator.sanitize(inputs), |
| 215 |
tier, |
| 216 |
mode, |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
fn outcome(&self, state: &Pricing) -> Outcome { |
| 222 |
state.billing.fee_calculator.compute(self.inputs) |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
struct Tier { |
| 232 |
|
| 233 |
key: &'static str, |
| 234 |
|
| 235 |
label: &'static str, |
| 236 |
|
| 237 |
|
| 238 |
fits: &'static str, |
| 239 |
} |
| 240 |
|
| 241 |
impl Tier { |
| 242 |
const BASIC: Self = Self { |
| 243 |
key: "basic", |
| 244 |
label: "Basic", |
| 245 |
fits: "Fits text, blogs, newsletters.", |
| 246 |
}; |
| 247 |
const SMALL_FILES: Self = Self { |
| 248 |
key: "small_files", |
| 249 |
label: "Small Files", |
| 250 |
fits: "Fits audio, plugins, binaries.", |
| 251 |
}; |
| 252 |
const BIG_FILES: Self = Self { |
| 253 |
key: "big_files", |
| 254 |
label: "Big Files", |
| 255 |
fits: "Fits video, games, large software.", |
| 256 |
}; |
| 257 |
const EVERYTHING: Self = Self { |
| 258 |
key: "everything", |
| 259 |
label: "Everything", |
| 260 |
fits: "Big Files envelope plus first access to high-cost features as they ship.", |
| 261 |
}; |
| 262 |
|
| 263 |
|
| 264 |
const ALL: [Self; 4] = [ |
| 265 |
Self::BASIC, |
| 266 |
Self::SMALL_FILES, |
| 267 |
Self::BIG_FILES, |
| 268 |
Self::EVERYTHING, |
| 269 |
]; |
| 270 |
|
| 271 |
|
| 272 |
fn named(key: &str) -> Option<Self> { |
| 273 |
Self::ALL.into_iter().find(|tier| tier.key == key) |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
fn price(&self, prices: &TierPrices, mode: &str) -> i32 { |
| 278 |
let founder = mode == FOUNDER; |
| 279 |
match self.key { |
| 280 |
"small_files" => { |
| 281 |
if founder { |
| 282 |
prices.small_files_founder |
| 283 |
} else { |
| 284 |
prices.small_files_std |
| 285 |
} |
| 286 |
} |
| 287 |
"big_files" => { |
| 288 |
if founder { |
| 289 |
prices.big_files_founder |
| 290 |
} else { |
| 291 |
prices.big_files_std |
| 292 |
} |
| 293 |
} |
| 294 |
"everything" => { |
| 295 |
if founder { |
| 296 |
prices.everything_founder |
| 297 |
} else { |
| 298 |
prices.everything_std |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
_ => { |
| 304 |
if founder { |
| 305 |
prices.basic_founder |
| 306 |
} else { |
| 307 |
prices.basic_std |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
fn detail(&self, prices: &TierPrices, mode: &str) -> String { |
| 316 |
let price = self.price(prices, mode); |
| 317 |
match self.key { |
| 318 |
"small_files" => format!( |
| 319 |
"${price}/mo. {}/file, {} total. {}", |
| 320 |
prices.small_files_per_file, prices.small_files_total, self.fits |
| 321 |
), |
| 322 |
"big_files" => format!( |
| 323 |
"${price}/mo. {}/file, {} total. {}", |
| 324 |
prices.big_files_per_file, prices.big_files_total, self.fits |
| 325 |
), |
| 326 |
|
| 327 |
|
| 328 |
"everything" => format!("${price}/mo. {}", self.fits), |
| 329 |
_ => format!( |
| 330 |
"${price}/mo. {}/file, {} total. {}", |
| 331 |
prices.basic_per_file, prices.basic_total, self.fits |
| 332 |
), |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
pub fn screen(state: &Pricing, request: Request) -> Result<Response, RouteError> { |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
let carried = request.carried; |
| 343 |
let dials = Dials::read(state, &carried); |
| 344 |
Ok(page(state, &dials).into()) |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
pub fn compare(state: &Pricing, request: Request) -> Result<Response, RouteError> { |
| 352 |
let carried = request.carried; |
| 353 |
let dials = Dials::read(state, &carried); |
| 354 |
Ok(Response::fragment( |
| 355 |
RESULTS, |
| 356 |
Node::Region(results(&dials.outcome(state))), |
| 357 |
)) |
| 358 |
} |
| 359 |
|
| 360 |
declare! { |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
shape page(state: &Pricing, dials: &Dials) -> Screen; |
| 374 |
|
| 375 |
screen list_detail "Pricing Calculator - Makenotwork" false { |
| 376 |
measured MEASURE; |
| 377 |
documented Document::default().classed(crate::shell::body_class(MEASURE, &[])); |
| 378 |
summarised "Work out what you keep on every sale here, against whatever the \ |
| 379 |
platform you sell on now deducts. 0% platform fee, only the \ |
| 380 |
payment processor's ~3%."; |
| 381 |
|
| 382 |
region PAGE as Pane { |
| 383 |
page "Pricing Calculator"; |
| 384 |
text "See what you keep on every sale."; |
| 385 |
include calculator(state, dials); |
| 386 |
act "Join the Alpha" to get "/join"; |
| 387 |
list { |
| 388 |
row "Home" { |
| 389 |
activate to get "/"; |
| 390 |
} |
| 391 |
row "Browse as guest" { |
| 392 |
activate to get "/discover"; |
| 393 |
} |
| 394 |
} |
| 395 |
include footer(state); |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
declare! { |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
shape calculator(state: &Pricing, dials: &Dials) -> Slot; |
| 412 |
|
| 413 |
region CALCULATOR as Group { |
| 414 |
consulting Consult::new(Action::get(COMPARE).replacing(RESULTS)).after(SETTLES); |
| 415 |
|
| 416 |
section "What you sell"; |
| 417 |
include dial( |
| 418 |
ITEM_PRICE, |
| 419 |
"Price per item", |
| 420 |
dials.inputs.item_price, |
| 421 |
fee_calculator::MAX_ITEM_PRICE, |
| 422 |
"1", |
| 423 |
"USD" |
| 424 |
); |
| 425 |
include dial( |
| 426 |
SALES, |
| 427 |
"Sales per month", |
| 428 |
dials.inputs.sales_per_month, |
| 429 |
fee_calculator::MAX_SALES, |
| 430 |
"1", |
| 431 |
"/mo" |
| 432 |
); |
| 433 |
|
| 434 |
|
| 435 |
banner layout::Tone::Success |
| 436 |
"Founder pricing open. Half off creator tiers, locked for life. The \ |
| 437 |
calculator is using founder prices." |
| 438 |
when state.founder_window_open; |
| 439 |
|
| 440 |
section "Your content tier"; |
| 441 |
text "Every tier is the complete platform: profile, project pages, forum, \ |
| 442 |
discovery, memberships, analytics, full data export. The tier picks \ |
| 443 |
the file-size envelope, not the feature set."; |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
field Radio PRICE_MODE "Calculate with" when state.founder_window_open { |
| 449 |
option Choice::new(FOUNDER, "Founder price"); |
| 450 |
option Choice::new(LIST, "List price"); |
| 451 |
value dials.mode; |
| 452 |
} |
| 453 |
|
| 454 |
field Radio TIER "Content tier" { |
| 455 |
for tier in Tier::ALL.iter() { |
| 456 |
option Choice::new(tier.key, tier.label) |
| 457 |
.detailing(tier.detail(&state.billing.tier_prices, dials.mode)); |
| 458 |
} |
| 459 |
value dials.tier; |
| 460 |
} |
| 461 |
|
| 462 |
section "Wherever else you sell"; |
| 463 |
text "Fill in what the other platform takes. Use its total deduction, its \ |
| 464 |
own cut plus any payment processing it adds, which is the figure you \ |
| 465 |
can read off a payout. We hold no rates for anyone but ourselves, so \ |
| 466 |
nothing here can go stale or be picked to flatter us."; |
| 467 |
include dial( |
| 468 |
OTHER_PCT, |
| 469 |
"Their cut", |
| 470 |
other_pct_shown(dials), |
| 471 |
other_pct_max(), |
| 472 |
"0.1", |
| 473 |
"%" |
| 474 |
); |
| 475 |
include dial( |
| 476 |
OTHER_PER_SALE, |
| 477 |
"Their fee per sale", |
| 478 |
dials.inputs.other_per_sale, |
| 479 |
fee_calculator::MAX_OTHER_PER_SALE, |
| 480 |
"0.05", |
| 481 |
"USD" |
| 482 |
); |
| 483 |
|
| 484 |
include results(&dials.outcome(state)); |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
fn other_pct_shown(dials: &Dials) -> f64 { |
| 495 |
dials.inputs.other_pct * 100.0 |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
fn other_pct_max() -> f64 { |
| 500 |
fee_calculator::MAX_OTHER_PCT * 100.0 |
| 501 |
} |
| 502 |
|
| 503 |
declare! { |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
shape dial( |
| 513 |
name: &'static str, |
| 514 |
label: &'static str, |
| 515 |
value: f64, |
| 516 |
max: f64, |
| 517 |
step: &'static str, |
| 518 |
unit: &'static str, |
| 519 |
) -> Field; |
| 520 |
|
| 521 |
field Number name label { |
| 522 |
value fmt_dial(value); |
| 523 |
step step; |
| 524 |
unit unit; |
| 525 |
within "0" fmt_dial(max); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
declare! { |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
shape results(outcome: &Outcome) -> Slot; |
| 541 |
|
| 542 |
region RESULTS as Pane { |
| 543 |
banner verdict_tone(outcome.verdict) &outcome.headline; |
| 544 |
|
| 545 |
table { |
| 546 |
column "Monthly" { |
| 547 |
width Fill; |
| 548 |
priority Essential; |
| 549 |
} |
| 550 |
column "Here" { |
| 551 |
width Content; |
| 552 |
priority Essential; |
| 553 |
} |
| 554 |
column "The other platform" { |
| 555 |
width Content; |
| 556 |
priority Essential; |
| 557 |
} |
| 558 |
|
| 559 |
cells { |
| 560 |
cell "You sell"; |
| 561 |
cell outcome.gross.clone(); |
| 562 |
cell outcome.gross.clone(); |
| 563 |
} |
| 564 |
cells { |
| 565 |
cell "You keep"; |
| 566 |
cell outcome.mnw_keep.clone(); |
| 567 |
cell outcome.other_keep.clone(); |
| 568 |
} |
| 569 |
cells { |
| 570 |
cell "Total fees"; |
| 571 |
cell outcome.mnw_rate.clone(); |
| 572 |
cell outcome.other_rate.clone(); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
for crossover in outcome.crossover.iter() { |
| 582 |
section "Where each one wins"; |
| 583 |
proportion crossover.sales crossover.at { |
| 584 |
label "sales a month to the crossover"; |
| 585 |
tone verdict_tone(outcome.verdict); |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
for note in outcome.crossover_note.iter() { |
| 590 |
text note; |
| 591 |
} |
| 592 |
|
| 593 |
text "Our side of this uses the payment processor's published US card rates. \ |
| 594 |
Yours is whatever you type in, so check it against a real payout rather \ |
| 595 |
than a pricing page: some platforms quote their cut before processing \ |
| 596 |
and some after."; |
| 597 |
text "Selling small-ticket items? Payment processors charge a fixed fee per \ |
| 598 |
sale (~$0.30) that hits harder on $1-5 items. That is an industry-wide \ |
| 599 |
constraint and it applies wherever you sell. Bundling items into \ |
| 600 |
collections lets fans buy in groups at a single transaction cost \ |
| 601 |
instead of paying per-item processing."; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
const fn verdict_tone(verdict: Verdict) -> layout::Tone { |
| 614 |
match verdict { |
| 615 |
Verdict::MnwAhead => layout::Tone::Success, |
| 616 |
Verdict::Even => layout::Tone::Neutral, |
| 617 |
Verdict::OtherAheadForNow | Verdict::OtherAhead => layout::Tone::Warning, |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
declare! { |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
shape footer(state: &Pricing) -> Slot; |
| 628 |
|
| 629 |
region "site-footer" as Pane { |
| 630 |
list { |
| 631 |
row "Pricing" { |
| 632 |
activate to get "/pricing"; |
| 633 |
} |
| 634 |
row "Creators" { |
| 635 |
activate to get "/creators"; |
| 636 |
} |
| 637 |
row "Docs" { |
| 638 |
activate to get "/docs"; |
| 639 |
} |
| 640 |
row "Legal" { |
| 641 |
activate to get "/policy"; |
| 642 |
} |
| 643 |
row "Credits" { |
| 644 |
activate to get "/docs/credits"; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
row "Changelog" when state.changelog_published { |
| 649 |
activate to get "/changelog"; |
| 650 |
} |
| 651 |
row "Contact" { |
| 652 |
activate to external "mailto:info@makenot.work"; |
| 653 |
} |
| 654 |
row "Status" { |
| 655 |
activate to get "/health"; |
| 656 |
} |
| 657 |
} |
| 658 |
text "(c) 2026 Make Creative, LLC"; |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
fn fmt_dial(v: f64) -> String { |
| 667 |
let s = format!("{v:.2}"); |
| 668 |
s.trim_end_matches('0').trim_end_matches('.').to_string() |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
#[must_use] |
| 691 |
pub fn renderer() -> Webview { |
| 692 |
let shell = crate::shell::described() |
| 693 |
.with_body_first(crate::shell::skip_link(PAGE)) |
| 694 |
.with_body_last(crate::shell::body_last()) |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
.with_chrome(crate::quasi::shortcuts::chrome()); |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
Webview::new().with_shell(shell) |
| 713 |
} |
| 714 |
|
| 715 |
#[cfg(test)] |
| 716 |
mod tests { |
| 717 |
use super::*; |
| 718 |
use quasi_router::Slot; |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
fn state(founder_window_open: bool) -> Pricing { |
| 726 |
crate::tier_prices::TierPrices::install_test_default(); |
| 727 |
Pricing { |
| 728 |
billing: Billing { |
| 729 |
payments: None, |
| 730 |
payment_caps: crate::payments::PaymentCapabilities::default(), |
| 731 |
tier_prices: crate::tier_prices::TierPrices::global().clone(), |
| 732 |
runway_config: crate::tier_prices::RunwayConfig { |
| 733 |
quarters: 0, |
| 734 |
last_updated_iso: String::new(), |
| 735 |
}, |
| 736 |
fee_calculator: crate::fee_calculator::FeeCalculator::load( |
| 737 |
"docs/business/assumptions.toml", |
| 738 |
), |
| 739 |
}, |
| 740 |
founder_window_open, |
| 741 |
changelog_published: false, |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
fn carrying(pairs: &[(&str, &str)]) -> quasi_router::Params { |
| 746 |
pairs.iter().copied().collect() |
| 747 |
} |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
fn approx(got: f64, want: f64, what: &str) { |
| 752 |
assert!((got - want).abs() < 1e-9, "{what}: got {got}, want {want}"); |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
#[test] |
| 761 |
fn the_region_asks_and_nothing_names_a_dial() { |
| 762 |
let state = state(true); |
| 763 |
let screen = page(&state, &Dials::read(&state, &carrying(&[]))); |
| 764 |
|
| 765 |
let asking = screen.consulting(); |
| 766 |
assert_eq!(asking.len(), 1, "one panel recomputes, not several"); |
| 767 |
let consult = &asking[0].consults[0]; |
| 768 |
assert_eq!(consult.action.route(), Some(COMPARE)); |
| 769 |
assert_eq!(consult.after, SETTLES); |
| 770 |
assert!( |
| 771 |
consult.sends.is_empty(), |
| 772 |
"a dial inside the region rides along by containment, so nothing \ |
| 773 |
should be named: {:?}", |
| 774 |
consult.sends |
| 775 |
); |
| 776 |
} |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
#[test] |
| 782 |
fn the_region_contains_every_dial_the_route_reads() { |
| 783 |
let state = state(true); |
| 784 |
let screen = page(&state, &Dials::read(&state, &carrying(&[]))); |
| 785 |
let names: Vec<&str> = screen.consulting()[0] |
| 786 |
.questions() |
| 787 |
.iter() |
| 788 |
.map(|field| field.name.as_str()) |
| 789 |
.collect(); |
| 790 |
|
| 791 |
assert_eq!( |
| 792 |
names, |
| 793 |
[ |
| 794 |
ITEM_PRICE, |
| 795 |
SALES, |
| 796 |
PRICE_MODE, |
| 797 |
TIER, |
| 798 |
OTHER_PCT, |
| 799 |
OTHER_PER_SALE |
| 800 |
] |
| 801 |
); |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
#[test] |
| 807 |
fn the_mode_is_not_asked_once_the_window_shuts() { |
| 808 |
let state = state(false); |
| 809 |
let screen = page(&state, &Dials::read(&state, &carrying(&[]))); |
| 810 |
let names: Vec<&str> = screen.consulting()[0] |
| 811 |
.questions() |
| 812 |
.iter() |
| 813 |
.map(|field| field.name.as_str()) |
| 814 |
.collect(); |
| 815 |
|
| 816 |
assert!(!names.contains(&PRICE_MODE), "{names:?}"); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
#[test] |
| 822 |
fn the_mode_picks_which_rate_the_tier_costs() { |
| 823 |
let state = state(true); |
| 824 |
let prices = &state.billing.tier_prices; |
| 825 |
assert_ne!( |
| 826 |
prices.basic_founder, prices.basic_std, |
| 827 |
"the assumptions make this vacuous if the two rates are equal" |
| 828 |
); |
| 829 |
|
| 830 |
let founder = Dials::read(&state, &carrying(&[(TIER, "basic")])); |
| 831 |
let list = Dials::read(&state, &carrying(&[(TIER, "basic"), (PRICE_MODE, LIST)])); |
| 832 |
|
| 833 |
approx( |
| 834 |
founder.inputs.tier_cost, |
| 835 |
f64::from(prices.basic_founder), |
| 836 |
"founder rate", |
| 837 |
); |
| 838 |
approx( |
| 839 |
list.inputs.tier_cost, |
| 840 |
f64::from(prices.basic_std), |
| 841 |
"list rate", |
| 842 |
); |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
#[test] |
| 848 |
fn a_link_cannot_price_a_window_that_has_closed() { |
| 849 |
let state = state(false); |
| 850 |
let dials = Dials::read(&state, &carrying(&[(TIER, "basic"), (PRICE_MODE, FOUNDER)])); |
| 851 |
|
| 852 |
assert_eq!(dials.mode, LIST); |
| 853 |
approx( |
| 854 |
dials.inputs.tier_cost, |
| 855 |
f64::from(state.billing.tier_prices.basic_std), |
| 856 |
"a shut window prices at list", |
| 857 |
); |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
#[test] |
| 863 |
fn an_older_link_carrying_a_price_is_read_as_dollars() { |
| 864 |
let state = state(true); |
| 865 |
let dials = Dials::read(&state, &carrying(&[(TIER, "24"), (SALES, "100")])); |
| 866 |
|
| 867 |
approx(dials.inputs.tier_cost, 24.0, "the price the link carried"); |
| 868 |
approx(dials.inputs.sales_per_month, 100.0, "sales"); |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
#[test] |
| 874 |
fn the_cut_is_typed_whole_and_held_as_a_fraction() { |
| 875 |
let state = state(false); |
| 876 |
let dials = Dials::read(&state, &carrying(&[(OTHER_PCT, "12.6")])); |
| 877 |
|
| 878 |
approx(dials.inputs.other_pct, 0.126, "12.6% as a fraction"); |
| 879 |
} |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
#[test] |
| 889 |
fn the_document_carries_the_class_the_template_carried() { |
| 890 |
let screen = page(&state(false), &Dials::read(&state(false), &carrying(&[]))); |
| 891 |
|
| 892 |
assert_eq!( |
| 893 |
screen.document.body_class.as_deref(), |
| 894 |
Some(crate::shell::body_class(MEASURE, &[]).as_str()) |
| 895 |
); |
| 896 |
assert_eq!(screen.document.body_class.as_deref(), Some("centered-page")); |
| 897 |
|
| 898 |
use quasi_axum::Serves as _; |
| 899 |
|
| 900 |
let rendered = Webview::new().screen(&page( |
| 901 |
&state(false), |
| 902 |
&Dials::read(&state(false), &carrying(&[])), |
| 903 |
)); |
| 904 |
assert!(rendered.contains("class=\"centered-page\""), "{rendered}"); |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
#[test] |
| 910 |
fn the_page_spells_no_spinner() { |
| 911 |
use quasi_axum::Serves as _; |
| 912 |
|
| 913 |
let rendered = Webview::new().screen(&page( |
| 914 |
&state(false), |
| 915 |
&Dials::read(&state(false), &carrying(&[])), |
| 916 |
)); |
| 917 |
|
| 918 |
for spelling in ["htmx-indicator", "spinner", "loading-text", "loading-state"] { |
| 919 |
assert!( |
| 920 |
!rendered.contains(spelling), |
| 921 |
"{spelling} survives in {rendered}" |
| 922 |
); |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
#[test] |
| 929 |
fn the_panel_meters_the_crossover_only_when_there_is_one() { |
| 930 |
let state = state(false); |
| 931 |
let calculator = &state.billing.fee_calculator; |
| 932 |
|
| 933 |
let ahead = calculator.compute(Inputs { |
| 934 |
item_price: 25.0, |
| 935 |
sales_per_month: 40.0, |
| 936 |
tier_cost: 16.0, |
| 937 |
other_pct: 0.126, |
| 938 |
other_per_sale: 0.30, |
| 939 |
}); |
| 940 |
assert!(has_meter(&results(&ahead)), "a crossover with no meter"); |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
let never = calculator.compute(Inputs { |
| 945 |
item_price: 5.0, |
| 946 |
sales_per_month: 500.0, |
| 947 |
tier_cost: 16.0, |
| 948 |
other_pct: 0.01, |
| 949 |
other_per_sale: 0.0, |
| 950 |
}); |
| 951 |
assert!(!has_meter(&results(&never)), "metered against nothing"); |
| 952 |
} |
| 953 |
|
| 954 |
fn has_meter(slot: &Slot) -> bool { |
| 955 |
slot.body |
| 956 |
.iter() |
| 957 |
.any(|placed| matches!(placed.node, Node::Meter(_))) |
| 958 |
} |
| 959 |
} |
| 960 |
|