package com.cottondb.moneyimport com.cottondb.money.faces.MoneyReadingimport kotlinx.serialization.json.Jsonimport kotlinx.serialization.json.JsonObjectimport kotlinx.serialization.json.jsonObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertNullimport org.junit.Test/** How Money's faces read a card the core dealt: synthetic cards only, shaped as `shell.deck` answers them. */classMoneyReadingTest {privatefun card(json: String): JsonObject = Json.parseToJsonElement(json).jsonObject/** RULE: the balances before and after are the card's two facts in the view's order; any other count says none. */ @Test fun theBalancesAreTheTwoFactsInOrder() {val spend = card("""{"id":"0f6c2a4e-91d3-4b7a-8c55-3e2b17a04217","slots":{"facts":[{"label":"Balance before","said":"₹1,26,840"},{"label":"Balance after","said":"₹1,24,500"}]}}""") assertEquals("₹1,26,840" to "₹1,24,500", MoneyReading.balances(spend))val one = card("""{"slots":{"facts":[{"label":"Balance after","said":"₹1,24,500"}]}}""") assertEquals(null to null, MoneyReading.balances(one)) }/** RULE: a cheque's serial is the record id's last six letters and figures, in capitals; a card of no record has none. */ @Test fun theSerialIsTheIdsLastSix() { assertEquals("A04217", MoneyReading.serial(card("""{"id":"0f6c2a4e-91d3-4b7a-8c55-3e2b17a04217"}"""))) assertNull(MoneyReading.serial(card("""{"slots":{}}"""))) }/** RULE: what a transaction was for is its description, else its category; blank words are none. */ @Test fun thePurposeIsTheSubtitleElseTheBody() { assertEquals("Groceries", MoneyReading.purpose(card("""{"slots":{"subtitle":"Groceries","body":"Weekly"}}"""))) assertEquals("Weekly", MoneyReading.purpose(card("""{"slots":{"subtitle":" ","body":"Weekly"}}"""))) assertNull(MoneyReading.purpose(card("""{"slots":{}}"""))) }}