|
@@ -8,18 +8,18 @@
|
|
|
|
|
|
|
|
use axum::{
|
|
use axum::{
|
|
|
Router,
|
|
Router,
|
|
|
- extract::{Path, State},
|
|
|
|
|
|
|
+ extract::{Path, Query, State},
|
|
|
http::header,
|
|
http::header,
|
|
|
response::{Html, IntoResponse, Response},
|
|
response::{Html, IntoResponse, Response},
|
|
|
routing::get,
|
|
routing::get,
|
|
|
};
|
|
};
|
|
|
use kuatia_core::{AccountId, Amount};
|
|
use kuatia_core::{AccountId, Amount};
|
|
|
-use serde::Serialize;
|
|
|
|
|
|
|
+use serde::{Deserialize, Serialize};
|
|
|
use tera::{Context, Tera};
|
|
use tera::{Context, Tera};
|
|
|
|
|
|
|
|
use crate::data::{
|
|
use crate::data::{
|
|
|
- self, AccountDto, ApiError, AppState, EntryDto, EntryLineDto, EntryLineKind, EntrySide,
|
|
|
|
|
- EventDto, MetadataPairDto, MetadataValueDto, OverviewDto, PostingDto,
|
|
|
|
|
|
|
+ self, AccountDto, ApiError, AppState, EntryAssetDto, EntryDto, EntryLineDto, EntryLineKind,
|
|
|
|
|
+ EntrySide, EventDto, MetadataPairDto, MetadataValueDto, OverviewDto, PostingDto,
|
|
|
};
|
|
};
|
|
|
use crate::seed::account_label;
|
|
use crate::seed::account_label;
|
|
|
|
|
|
|
@@ -108,6 +108,82 @@ struct MoneyView {
|
|
|
negative: bool,
|
|
negative: bool,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// How much of an entry to draw.
|
|
|
|
|
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
+enum Detail {
|
|
|
|
|
+ /// The movements alone: what the entry did, without the UTXO mechanism
|
|
|
|
|
+ /// that carried it.
|
|
|
|
|
+ Movements,
|
|
|
|
|
+ /// Every posting, with the per-asset conservation totals.
|
|
|
|
|
+ All,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+impl Detail {
|
|
|
|
|
+ /// Read the mode off `?details=`. An unrecognized value falls back to the
|
|
|
|
|
+ /// default, so a mistyped URL still shows the feed.
|
|
|
|
|
+ fn from_query(params: &DetailParams) -> Self {
|
|
|
|
|
+ match params.details.as_deref() {
|
|
|
|
|
+ Some("all") => Self::All,
|
|
|
|
|
+ _ => Self::Movements,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// The query suffix that carries this mode, empty for the default.
|
|
|
|
|
+ fn suffix(self) -> &'static str {
|
|
|
|
|
+ match self {
|
|
|
|
|
+ Self::Movements => "",
|
|
|
|
|
+ Self::All => "?details=all",
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn flipped(self) -> Self {
|
|
|
|
|
+ match self {
|
|
|
|
|
+ Self::Movements => Self::All,
|
|
|
|
|
+ Self::All => Self::Movements,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn label(self) -> &'static str {
|
|
|
|
|
+ match self {
|
|
|
|
|
+ Self::Movements => "all details",
|
|
|
|
|
+ Self::All => "movements only",
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// `?details=all`. A `String` rather than a deserialized enum so an
|
|
|
|
|
+/// unrecognized value falls back to the default instead of failing the request.
|
|
|
|
|
+#[derive(Deserialize)]
|
|
|
|
|
+struct DetailParams {
|
|
|
|
|
+ details: Option<String>,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// What a feed page needs to draw its entries and keep the mode across the
|
|
|
|
|
+/// htmx poll.
|
|
|
|
|
+#[derive(Serialize)]
|
|
|
|
|
+struct DetailView {
|
|
|
|
|
+ all: bool,
|
|
|
|
|
+ /// The `/ui/*` URL htmx polls, carrying the mode so a swap does not reset
|
|
|
|
|
+ /// it.
|
|
|
|
|
+ live_url: String,
|
|
|
|
|
+ /// The same page with the mode flipped.
|
|
|
|
|
+ toggle_url: String,
|
|
|
|
|
+ toggle_label: &'static str,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+impl DetailView {
|
|
|
|
|
+ /// Build the mode's view for one page, where `page` is the full-page path
|
|
|
|
|
+ /// and `live` its `/ui/*` counterpart.
|
|
|
|
|
+ fn new(detail: Detail, page: &str, live: &str) -> Self {
|
|
|
|
|
+ Self {
|
|
|
|
|
+ all: detail == Detail::All,
|
|
|
|
|
+ live_url: format!("{live}{}", detail.suffix()),
|
|
|
|
|
+ toggle_url: format!("{page}{}", detail.flipped().suffix()),
|
|
|
|
|
+ toggle_label: detail.label(),
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#[derive(Serialize)]
|
|
#[derive(Serialize)]
|
|
|
struct BalanceView {
|
|
struct BalanceView {
|
|
|
code: String,
|
|
code: String,
|
|
@@ -123,8 +199,6 @@ struct AccountView {
|
|
|
display_id: String,
|
|
display_id: String,
|
|
|
/// Full-page detail link, keyed by the machine-format code (`/accounts/<code>`).
|
|
/// Full-page detail link, keyed by the machine-format code (`/accounts/<code>`).
|
|
|
link: String,
|
|
link: String,
|
|
|
- /// htmx partial link (`/ui/accounts/<code>`).
|
|
|
|
|
- ui_link: String,
|
|
|
|
|
name: String,
|
|
name: String,
|
|
|
version: u64,
|
|
version: u64,
|
|
|
policy_kind: &'static str,
|
|
policy_kind: &'static str,
|
|
@@ -165,14 +239,32 @@ struct EntryLineView {
|
|
|
mine: bool,
|
|
mine: bool,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// One movement: value from the payer to the owner of a payer-funded posting.
|
|
|
|
|
+/// Debits one account and credits the other by the same amount, so a movement
|
|
|
|
|
+/// view balances by construction rather than by appeal to conservation.
|
|
|
|
|
+#[derive(Serialize)]
|
|
|
|
|
+struct MovementRowView {
|
|
|
|
|
+ from: AcctRefView,
|
|
|
|
|
+ to: AcctRefView,
|
|
|
|
|
+ money: MoneyView,
|
|
|
|
|
+ /// True when the viewed account is on either side of the movement.
|
|
|
|
|
+ mine: bool,
|
|
|
|
|
+ posting_short: String,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#[derive(Serialize)]
|
|
#[derive(Serialize)]
|
|
|
struct EntryAssetView {
|
|
struct EntryAssetView {
|
|
|
code: String,
|
|
code: String,
|
|
|
|
|
+ /// What the entry did, which is the default reading. Empty for an envelope
|
|
|
|
|
+ /// that records no payer anywhere, such as a reversal.
|
|
|
|
|
+ movements: Vec<MovementRowView>,
|
|
|
debits: Vec<EntryLineView>,
|
|
debits: Vec<EntryLineView>,
|
|
|
credits: Vec<EntryLineView>,
|
|
credits: Vec<EntryLineView>,
|
|
|
debit_total: MoneyView,
|
|
debit_total: MoneyView,
|
|
|
credit_total: MoneyView,
|
|
credit_total: MoneyView,
|
|
|
moved: MoneyView,
|
|
moved: MoneyView,
|
|
|
|
|
+ /// Shown in either mode: a false is a conservation bug in the record, not
|
|
|
|
|
+ /// a property of the reading on screen.
|
|
|
balanced: bool,
|
|
balanced: bool,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -384,7 +476,6 @@ fn account_view(dto: &AccountDto) -> AccountView {
|
|
|
AccountView {
|
|
AccountView {
|
|
|
id: dto.id.id,
|
|
id: dto.id.id,
|
|
|
sub: dto.sub,
|
|
sub: dto.sub,
|
|
|
- ui_link: format!("/ui{link}"),
|
|
|
|
|
link,
|
|
link,
|
|
|
name: dto
|
|
name: dto
|
|
|
.label
|
|
.label
|
|
@@ -443,6 +534,31 @@ fn line_view(dto: &EntryLineDto, viewpoint: Option<AccountId>) -> EntryLineView
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// The movements of one asset group, each from the payer of a payer-funded
|
|
|
|
|
+/// posting to its owner.
|
|
|
|
|
+///
|
|
|
|
|
+/// Filtered by kind rather than by column: a `Receive` is a credit in practice,
|
|
|
|
|
+/// but the sign is what places a line, and this should not depend on that
|
|
|
|
|
+/// holding. A `Receive` without a payer cannot be a movement and is dropped,
|
|
|
|
|
+/// which the resolver's contract makes unreachable.
|
|
|
|
|
+fn movement_rows(dto: &EntryAssetDto, viewpoint: Option<AccountId>) -> Vec<MovementRowView> {
|
|
|
|
|
+ dto.debits
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .chain(dto.credits.iter())
|
|
|
|
|
+ .filter(|l| l.kind == EntryLineKind::Receive)
|
|
|
|
|
+ .filter_map(|l| {
|
|
|
|
|
+ let payer = l.payer?;
|
|
|
|
|
+ Some(MovementRowView {
|
|
|
|
|
+ from: acct_ref(payer, l.payer_label),
|
|
|
|
|
+ to: acct_ref(l.owner, l.label),
|
|
|
|
|
+ money: fmt_magnitude(&l.amount),
|
|
|
|
|
+ mine: viewpoint == Some(l.owner) || viewpoint == Some(payer),
|
|
|
|
|
+ posting_short: short_hex(&l.posting),
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
fn entry_view(dto: &EntryDto, viewpoint: Option<AccountId>) -> EntryView {
|
|
fn entry_view(dto: &EntryDto, viewpoint: Option<AccountId>) -> EntryView {
|
|
|
EntryView {
|
|
EntryView {
|
|
|
short_id: short_hex(&dto.id),
|
|
short_id: short_hex(&dto.id),
|
|
@@ -457,6 +573,7 @@ fn entry_view(dto: &EntryDto, viewpoint: Option<AccountId>) -> EntryView {
|
|
|
.iter()
|
|
.iter()
|
|
|
.map(|a| EntryAssetView {
|
|
.map(|a| EntryAssetView {
|
|
|
code: a.code.clone(),
|
|
code: a.code.clone(),
|
|
|
|
|
+ movements: movement_rows(a, viewpoint),
|
|
|
debits: a.debits.iter().map(|l| line_view(l, viewpoint)).collect(),
|
|
debits: a.debits.iter().map(|l| line_view(l, viewpoint)).collect(),
|
|
|
credits: a.credits.iter().map(|l| line_view(l, viewpoint)).collect(),
|
|
credits: a.credits.iter().map(|l| line_view(l, viewpoint)).collect(),
|
|
|
debit_total: fmt_magnitude(&a.debit_total),
|
|
debit_total: fmt_magnitude(&a.debit_total),
|
|
@@ -520,10 +637,15 @@ async fn accounts_ctx(state: &AppState) -> Result<Context, ApiError> {
|
|
|
Ok(ctx)
|
|
Ok(ctx)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async fn account_ctx(state: &AppState, id: AccountId) -> Result<Context, ApiError> {
|
|
|
|
|
|
|
+async fn account_ctx(state: &AppState, id: AccountId, detail: Detail) -> Result<Context, ApiError> {
|
|
|
let dto = data::account_detail(state, id).await?;
|
|
let dto = data::account_detail(state, id).await?;
|
|
|
|
|
+ let page = acct_link(id);
|
|
|
let mut ctx = Context::new();
|
|
let mut ctx = Context::new();
|
|
|
ctx.insert("nav", "accounts");
|
|
ctx.insert("nav", "accounts");
|
|
|
|
|
+ ctx.insert(
|
|
|
|
|
+ "detail",
|
|
|
|
|
+ &DetailView::new(detail, &page, &format!("/ui{page}")),
|
|
|
|
|
+ );
|
|
|
ctx.insert("account", &account_view(&dto.account));
|
|
ctx.insert("account", &account_view(&dto.account));
|
|
|
ctx.insert(
|
|
ctx.insert(
|
|
|
"subaccounts",
|
|
"subaccounts",
|
|
@@ -543,11 +665,15 @@ async fn account_ctx(state: &AppState, id: AccountId) -> Result<Context, ApiErro
|
|
|
Ok(ctx)
|
|
Ok(ctx)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async fn transfers_ctx(state: &AppState) -> Result<Context, ApiError> {
|
|
|
|
|
|
|
+async fn transfers_ctx(state: &AppState, detail: Detail) -> Result<Context, ApiError> {
|
|
|
let dtos = data::transfers(state, None).await?;
|
|
let dtos = data::transfers(state, None).await?;
|
|
|
let views: Vec<EntryView> = dtos.iter().map(|e| entry_view(e, None)).collect();
|
|
let views: Vec<EntryView> = dtos.iter().map(|e| entry_view(e, None)).collect();
|
|
|
let mut ctx = Context::new();
|
|
let mut ctx = Context::new();
|
|
|
ctx.insert("nav", "transfers");
|
|
ctx.insert("nav", "transfers");
|
|
|
|
|
+ ctx.insert(
|
|
|
|
|
+ "detail",
|
|
|
|
|
+ &DetailView::new(detail, "/transfers", "/ui/transfers"),
|
|
|
|
|
+ );
|
|
|
ctx.insert("entries", &views);
|
|
ctx.insert("entries", &views);
|
|
|
Ok(ctx)
|
|
Ok(ctx)
|
|
|
}
|
|
}
|
|
@@ -599,38 +725,50 @@ async fn accounts_partial(State(state): State<AppState>) -> Result<Html<String>,
|
|
|
async fn account_page(
|
|
async fn account_page(
|
|
|
State(state): State<AppState>,
|
|
State(state): State<AppState>,
|
|
|
Path(uuid): Path<String>,
|
|
Path(uuid): Path<String>,
|
|
|
|
|
+ Query(params): Query<DetailParams>,
|
|
|
) -> Result<Html<String>, ApiError> {
|
|
) -> Result<Html<String>, ApiError> {
|
|
|
let account = uuid.parse().map_err(ApiError::bad_request)?;
|
|
let account = uuid.parse().map_err(ApiError::bad_request)?;
|
|
|
|
|
+ let detail = Detail::from_query(¶ms);
|
|
|
render(
|
|
render(
|
|
|
&state,
|
|
&state,
|
|
|
"pages/account.html",
|
|
"pages/account.html",
|
|
|
- &account_ctx(&state, account).await?,
|
|
|
|
|
|
|
+ &account_ctx(&state, account, detail).await?,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
async fn account_partial(
|
|
async fn account_partial(
|
|
|
State(state): State<AppState>,
|
|
State(state): State<AppState>,
|
|
|
Path(uuid): Path<String>,
|
|
Path(uuid): Path<String>,
|
|
|
|
|
+ Query(params): Query<DetailParams>,
|
|
|
) -> Result<Html<String>, ApiError> {
|
|
) -> Result<Html<String>, ApiError> {
|
|
|
let account = uuid.parse().map_err(ApiError::bad_request)?;
|
|
let account = uuid.parse().map_err(ApiError::bad_request)?;
|
|
|
|
|
+ let detail = Detail::from_query(¶ms);
|
|
|
render(
|
|
render(
|
|
|
&state,
|
|
&state,
|
|
|
"partials/account.html",
|
|
"partials/account.html",
|
|
|
- &account_ctx(&state, account).await?,
|
|
|
|
|
|
|
+ &account_ctx(&state, account, detail).await?,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-async fn transfers_page(State(state): State<AppState>) -> Result<Html<String>, ApiError> {
|
|
|
|
|
|
|
+async fn transfers_page(
|
|
|
|
|
+ State(state): State<AppState>,
|
|
|
|
|
+ Query(params): Query<DetailParams>,
|
|
|
|
|
+) -> Result<Html<String>, ApiError> {
|
|
|
|
|
+ let detail = Detail::from_query(¶ms);
|
|
|
render(
|
|
render(
|
|
|
&state,
|
|
&state,
|
|
|
"pages/transfers.html",
|
|
"pages/transfers.html",
|
|
|
- &transfers_ctx(&state).await?,
|
|
|
|
|
|
|
+ &transfers_ctx(&state, detail).await?,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
-async fn transfers_partial(State(state): State<AppState>) -> Result<Html<String>, ApiError> {
|
|
|
|
|
|
|
+async fn transfers_partial(
|
|
|
|
|
+ State(state): State<AppState>,
|
|
|
|
|
+ Query(params): Query<DetailParams>,
|
|
|
|
|
+) -> Result<Html<String>, ApiError> {
|
|
|
|
|
+ let detail = Detail::from_query(¶ms);
|
|
|
render(
|
|
render(
|
|
|
&state,
|
|
&state,
|
|
|
"partials/transfers.html",
|
|
"partials/transfers.html",
|
|
|
- &transfers_ctx(&state).await?,
|
|
|
|
|
|
|
+ &transfers_ctx(&state, detail).await?,
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -678,13 +816,85 @@ mod tests {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn render_feed(entries: Vec<EntryView>) -> String {
|
|
fn render_feed(entries: Vec<EntryView>) -> String {
|
|
|
|
|
+ render_feed_at(entries, Detail::All)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn render_feed_at(entries: Vec<EntryView>, detail: Detail) -> String {
|
|
|
let tera = build_tera().expect("templates compile");
|
|
let tera = build_tera().expect("templates compile");
|
|
|
let mut ctx = Context::new();
|
|
let mut ctx = Context::new();
|
|
|
|
|
+ ctx.insert(
|
|
|
|
|
+ "detail",
|
|
|
|
|
+ &DetailView::new(detail, "/transfers", "/ui/transfers"),
|
|
|
|
|
+ );
|
|
|
ctx.insert("entries", &entries);
|
|
ctx.insert("entries", &entries);
|
|
|
tera.render("partials/transfers.html", &ctx)
|
|
tera.render("partials/transfers.html", &ctx)
|
|
|
.expect("the feed renders")
|
|
.expect("the feed renders")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ fn acct(id: i64, label: Option<&'static str>) -> AcctRefView {
|
|
|
|
|
+ acct_ref(AccountId::new(id), label)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn money(text: &str) -> MoneyView {
|
|
|
|
|
+ MoneyView {
|
|
|
|
|
+ text: text.to_string(),
|
|
|
|
|
+ negative: false,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn movement(from: &'static str, to: &'static str, amount: &str) -> MovementRowView {
|
|
|
|
|
+ MovementRowView {
|
|
|
|
|
+ from: acct(1, Some(from)),
|
|
|
|
|
+ to: acct(2, Some(to)),
|
|
|
|
|
+ money: money(amount),
|
|
|
|
|
+ mine: false,
|
|
|
|
|
+ posting_short: "9f0a\u{2026}0001".to_string(),
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn posting_line(kind: &'static str, note: &'static str, amount: &str) -> EntryLineView {
|
|
|
|
|
+ EntryLineView {
|
|
|
|
|
+ kind,
|
|
|
|
|
+ note,
|
|
|
|
|
+ posting_short: "9f0a\u{2026}0001".to_string(),
|
|
|
|
|
+ account: acct(3, Some("L59E")),
|
|
|
|
|
+ payer: None,
|
|
|
|
|
+ money: money(amount),
|
|
|
|
|
+ mine: false,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// An asset group holding both readings of the same entry, the way
|
|
|
|
|
+ /// `entry_view` builds one. `mechanism` is given as a spec so each column
|
|
|
|
|
+ /// gets its own lines without a `Clone` on the view type.
|
|
|
|
|
+ fn asset(
|
|
|
|
|
+ movements: Vec<MovementRowView>,
|
|
|
|
|
+ mechanism: &[(&'static str, &'static str, &'static str)],
|
|
|
|
|
+ ) -> EntryAssetView {
|
|
|
|
|
+ let lines = || -> Vec<EntryLineView> {
|
|
|
|
|
+ mechanism
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .map(|(kind, note, amount)| posting_line(kind, note, amount))
|
|
|
|
|
+ .collect()
|
|
|
|
|
+ };
|
|
|
|
|
+ EntryAssetView {
|
|
|
|
|
+ code: "PYG".to_string(),
|
|
|
|
|
+ movements,
|
|
|
|
|
+ debits: lines(),
|
|
|
|
|
+ credits: lines(),
|
|
|
|
|
+ debit_total: money("\u{20b2}28,075,117"),
|
|
|
|
|
+ credit_total: money("\u{20b2}28,075,117"),
|
|
|
|
|
+ moved: money("\u{20b2}429,153"),
|
|
|
|
|
+ balanced: true,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fn entry_with(assets: Vec<EntryAssetView>) -> EntryView {
|
|
|
|
|
+ let mut view = entry(Some("sale_document:7"));
|
|
|
|
|
+ view.assets = assets;
|
|
|
|
|
+ view
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#[test]
|
|
#[test]
|
|
|
fn a_reference_heads_the_entry_and_the_hash_sits_under_it() {
|
|
fn a_reference_heads_the_entry_and_the_hash_sits_under_it() {
|
|
|
let html = render_feed(vec![entry(Some("sale_document:7"))]);
|
|
let html = render_feed(vec![entry(Some("sale_document:7"))]);
|
|
@@ -737,4 +947,110 @@ mod tests {
|
|
|
|
|
|
|
|
assert_eq!(view.short.chars().count(), TEXT_DISPLAY_CHARS + 1);
|
|
assert_eq!(view.short.chars().count(), TEXT_DISPLAY_CHARS + 1);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn the_default_view_shows_movements_and_no_mechanism() {
|
|
|
|
|
+ let html = render_feed_at(
|
|
|
|
|
+ vec![entry_with(vec![asset(
|
|
|
|
|
+ vec![
|
|
|
|
|
+ movement("Treasury", "C2AU", "\u{20b2}225,455"),
|
|
|
|
|
+ movement("VNWM", "C2AU", "\u{20b2}22,545"),
|
|
|
|
|
+ movement("L59E", "IOER", "\u{20b2}181,153"),
|
|
|
|
|
+ ],
|
|
|
|
|
+ &[
|
|
|
|
|
+ ("offset", "offset", "\u{20b2}225,455"),
|
|
|
|
|
+ ("change", "change", "\u{20b2}27,645,964"),
|
|
|
|
|
+ ],
|
|
|
|
|
+ )])],
|
|
|
|
|
+ Detail::Movements,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ assert!(!html.contains("note offset"));
|
|
|
|
|
+ assert!(!html.contains("note change"));
|
|
|
|
|
+ assert!(html.contains("Treasury"));
|
|
|
|
|
+ assert!(html.contains("IOER"));
|
|
|
|
|
+ // Both columns close on what moved, not on the conservation total.
|
|
|
|
|
+ assert_eq!(html.matches("\u{20b2}429,153").count(), 3);
|
|
|
|
|
+ assert!(!html.contains("\u{20b2}28,075,117"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn all_details_shows_the_mechanism_and_the_conservation_totals() {
|
|
|
|
|
+ let html = render_feed_at(
|
|
|
|
|
+ vec![entry_with(vec![asset(
|
|
|
|
|
+ vec![movement("Treasury", "C2AU", "\u{20b2}225,455")],
|
|
|
|
|
+ &[
|
|
|
|
|
+ ("offset", "offset", "\u{20b2}225,455"),
|
|
|
|
|
+ ("change", "change", "\u{20b2}27,645,964"),
|
|
|
|
|
+ ],
|
|
|
|
|
+ )])],
|
|
|
|
|
+ Detail::All,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ assert!(html.contains("note offset"));
|
|
|
|
|
+ assert!(html.contains("note change"));
|
|
|
|
|
+ assert_eq!(html.matches("\u{20b2}28,075,117").count(), 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn an_entry_with_no_movement_falls_back_to_its_postings() {
|
|
|
|
|
+ // The reversal shape: every created posting is payer-less, so there is
|
|
|
|
|
+ // no movement to show and the default view must not render blank.
|
|
|
|
|
+ let html = render_feed_at(
|
|
|
|
|
+ vec![entry_with(vec![asset(
|
|
|
|
|
+ Vec::new(),
|
|
|
|
|
+ &[("change", "change", "\u{20b2}100")],
|
|
|
|
|
+ )])],
|
|
|
|
|
+ Detail::Movements,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ assert!(html.contains("no movement recorded"));
|
|
|
|
|
+ assert!(html.contains("note change"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn a_deposit_reads_as_two_movement_rows_rather_than_an_empty_column() {
|
|
|
|
|
+ let html = render_feed_at(
|
|
|
|
|
+ vec![entry_with(vec![asset(
|
|
|
|
|
+ vec![movement("External", "Alice", "$1,000.00")],
|
|
|
|
|
+ &[("offset", "offset", "$1,000.00")],
|
|
|
|
|
+ )])],
|
|
|
|
|
+ Detail::Movements,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ assert!(html.contains("External"));
|
|
|
|
|
+ assert!(html.contains("Alice"));
|
|
|
|
|
+ assert!(!html.contains("nothing consumed"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn the_mode_is_in_the_polled_url_so_a_swap_does_not_reset_it() {
|
|
|
|
|
+ let movements = DetailView::new(Detail::Movements, "/transfers", "/ui/transfers");
|
|
|
|
|
+ assert_eq!(movements.live_url, "/ui/transfers");
|
|
|
|
|
+ assert_eq!(movements.toggle_url, "/transfers?details=all");
|
|
|
|
|
+ assert_eq!(movements.toggle_label, "all details");
|
|
|
|
|
+ assert!(!movements.all);
|
|
|
|
|
+
|
|
|
|
|
+ let all = DetailView::new(Detail::All, "/transfers", "/ui/transfers");
|
|
|
|
|
+ assert_eq!(all.live_url, "/ui/transfers?details=all");
|
|
|
|
|
+ assert_eq!(all.toggle_url, "/transfers");
|
|
|
|
|
+ assert_eq!(all.toggle_label, "movements only");
|
|
|
|
|
+ assert!(all.all);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #[test]
|
|
|
|
|
+ fn an_unrecognized_mode_falls_back_to_the_default() {
|
|
|
|
|
+ let nonsense = DetailParams {
|
|
|
|
|
+ details: Some("nonsense".to_string()),
|
|
|
|
|
+ };
|
|
|
|
|
+ assert_eq!(Detail::from_query(&nonsense), Detail::Movements);
|
|
|
|
|
+
|
|
|
|
|
+ let absent = DetailParams { details: None };
|
|
|
|
|
+ assert_eq!(Detail::from_query(&absent), Detail::Movements);
|
|
|
|
|
+
|
|
|
|
|
+ let all = DetailParams {
|
|
|
|
|
+ details: Some("all".to_string()),
|
|
|
|
|
+ };
|
|
|
|
|
+ assert_eq!(Detail::from_query(&all), Detail::All);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|