BlueGit

timfa questward

Fix Central Exchange cancel/expiry letter copy by order side.

Use correct grammar for returned coin escrow on buy orders and keep listed-goods wording for sell returns.

timfa Tim Falken · pushed by timfa

Authored 2026-08-28 · 2 months ago

Hash
4c807ba38b295885fa33f7278b706ed0f124dedf
Parent
b9c31cdd
2 files changed +70 −7
server/tests/marketplace.test.js +34 −1
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
3 3 import { ItemId } from "../../shared/definitions/items.js";
4 4 import { BlockType } from "../../shared/definitions/tiles.js";
5 5 import { canSellOnMarketplace, assertMarketplaceSellable } from "../../shared/items/marketplace.js";
6 import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee } from "../../shared/market/exchange.js";
6 import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee, orderCancelledLetterBody, orderExpiredLetterBody } from "../../shared/market/exchange.js";
7 7 import { formatLetterSignature, CENTRAL_EXCHANGE_ORG } from "../../shared/courier/systemLetters.js";
8 8 import { writtenOrigin, originLabel, CraftOriginVerb } from "../../shared/items/origin.js";
9 9 import { takeMarketFunds, resolveMarketSellListing } from "../../shared/market/funds.js";
@@ -79,6 +79,39 @@ test("listing fee is 3% of notional rounded up", () =>
79 79 assert.equal(marketOrderListingFee(0, 5), 0);
80 80 });
81 81
82 test("cancel and expiry letters use side-specific escrow copy", () =>
83 {
84 const buyCancel = orderCancelledLetterBody({
85 side: "buy",
86 itemName: "Flower",
87 quantity: 1,
88 escrowLabel: "coins",
89 clerkName: "Ada Ledger"
90 });
91 assert.match(buyCancel, /buy order for 1× Flower was cancelled/);
92 assert.match(buyCancel, /coins have been returned/);
93 assert.doesNotMatch(buyCancel, /coins has been returned/);
94
95 const sellCancel = orderCancelledLetterBody({
96 side: "sell",
97 itemName: "Apple",
98 quantity: 2,
99 escrowLabel: "Apple",
100 clerkName: "Ada Ledger"
101 });
102 assert.match(sellCancel, /sell order for 2× Apple was cancelled/);
103 assert.match(sellCancel, /listed goods have been returned/);
104
105 const buyExpired = orderExpiredLetterBody({
106 side: "buy",
107 itemName: "Flower",
108 quantity: 1,
109 escrowLabel: "coins",
110 clerkName: "Ada Ledger"
111 });
112 assert.match(buyExpired, /coins have been returned/);
113 });
114
82 115 test("market funds spend whole coin cheques and return change", () =>
83 116 {
84 117 const slots = emptySlots();
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
3import { ItemId } from "../../shared/definitions/items.js";
3import { ItemId } from "../../shared/definitions/items.js";
4import { BlockType } from "../../shared/definitions/tiles.js";
4import { BlockType } from "../../shared/definitions/tiles.js";
5import { canSellOnMarketplace, assertMarketplaceSellable } from "../../shared/items/marketplace.js";
5import { canSellOnMarketplace, assertMarketplaceSellable } from "../../shared/items/marketplace.js";
6import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee } from "../../shared/market/exchange.js";
6import { midpointTradePrice, MARKET_ORDER_MAX_AGE_MS, soldLetterBody, marketOrderListingFee, orderCancelledLetterBody, orderExpiredLetterBody } from "../../shared/market/exchange.js";
7import { formatLetterSignature, CENTRAL_EXCHANGE_ORG } from "../../shared/courier/systemLetters.js";
7import { formatLetterSignature, CENTRAL_EXCHANGE_ORG } from "../../shared/courier/systemLetters.js";
8import { writtenOrigin, originLabel, CraftOriginVerb } from "../../shared/items/origin.js";
8import { writtenOrigin, originLabel, CraftOriginVerb } from "../../shared/items/origin.js";
9import { takeMarketFunds, resolveMarketSellListing } from "../../shared/market/funds.js";
9import { takeMarketFunds, resolveMarketSellListing } from "../../shared/market/funds.js";
@@ -79,6 +79,39 @@ test("listing fee is 3% of notional rounded up", () =>
79 assert.equal(marketOrderListingFee(0, 5), 0);
79 assert.equal(marketOrderListingFee(0, 5), 0);
80});
80});
81
81
82test("cancel and expiry letters use side-specific escrow copy", () =>
83{
84 const buyCancel = orderCancelledLetterBody({
85 side: "buy",
86 itemName: "Flower",
87 quantity: 1,
88 escrowLabel: "coins",
89 clerkName: "Ada Ledger"
90 });
91 assert.match(buyCancel, /buy order for 1× Flower was cancelled/);
92 assert.match(buyCancel, /coins have been returned/);
93 assert.doesNotMatch(buyCancel, /coins has been returned/);
94
95 const sellCancel = orderCancelledLetterBody({
96 side: "sell",
97 itemName: "Apple",
98 quantity: 2,
99 escrowLabel: "Apple",
100 clerkName: "Ada Ledger"
101 });
102 assert.match(sellCancel, /sell order for 2× Apple was cancelled/);
103 assert.match(sellCancel, /listed goods have been returned/);
104
105 const buyExpired = orderExpiredLetterBody({
106 side: "buy",
107 itemName: "Flower",
108 quantity: 1,
109 escrowLabel: "coins",
110 clerkName: "Ada Ledger"
111 });
112 assert.match(buyExpired, /coins have been returned/);
113});
114
82test("market funds spend whole coin cheques and return change", () =>
115test("market funds spend whole coin cheques and return change", () =>
83{
116{
84 const slots = emptySlots();
117 const slots = emptySlots();
shared/market/exchange.js +36 −6
@@ -61,22 +61,52 @@ export function buyFilledLetterBody ({ itemName, quantity, unitPrice, clerkName
61 61 export function orderExpiredLetterBody ({ side, itemName, quantity, escrowLabel, clerkName })
62 62 {
63 63 void clerkName;
64 const kind = side === "buy" ? "buy" : "sell";
64 if (side === "buy")
65 {
66 return [
67 `Unfortunately your buy order for ${quantity}× ${itemName} could not be filled within one month.`,
68 "",
69 "Your reserved coins have been returned to your bank."
70 ].join("\n");
71 }
72 if (escrowLabel === "written cheque")
73 {
74 return [
75 `Unfortunately your sell order for ${quantity}× ${itemName} could not be filled within one month.`,
76 "",
77 "Your reserved written cheque has been returned to your bank."
78 ].join("\n");
79 }
65 80 return [
66 `Unfortunately your ${kind} order for ${quantity}× ${itemName} could not be filled within one month.`,
81 `Unfortunately your sell order for ${quantity}× ${itemName} could not be filled within one month.`,
67 82 "",
68 `Your reserved ${escrowLabel} has been returned to your bank.`
83 "The listed goods have been returned to your bank."
69 84 ].join("\n");
70 85 }
71 86
72 87 export function orderCancelledLetterBody ({ side, itemName, quantity, escrowLabel, clerkName })
73 88 {
74 89 void clerkName;
75 const kind = side === "buy" ? "buy" : "sell";
90 if (side === "buy")
91 {
92 return [
93 `Your buy order for ${quantity}× ${itemName} was cancelled.`,
94 "",
95 "Your reserved coins have been returned to your bank."
96 ].join("\n");
97 }
98 if (escrowLabel === "written cheque")
99 {
100 return [
101 `Your sell order for ${quantity}× ${itemName} was cancelled.`,
102 "",
103 "Your reserved written cheque has been returned to your bank."
104 ].join("\n");
105 }
76 106 return [
77 `Your ${kind} order for ${quantity}× ${itemName} was cancelled.`,
107 `Your sell order for ${quantity}× ${itemName} was cancelled.`,
78 108 "",
79 `Your reserved ${escrowLabel} has been returned to your bank.`
109 "The listed goods have been returned to your bank."
80 110 ].join("\n");
81 111 }
82 112
@@ -61,22 +61,52 @@ export function buyFilledLetterBody ({ itemName, quantity, unitPrice, clerkName
61export function orderExpiredLetterBody ({ side, itemName, quantity, escrowLabel, clerkName })
61export function orderExpiredLetterBody ({ side, itemName, quantity, escrowLabel, clerkName })
62{
62{
63 void clerkName;
63 void clerkName;
64 const kind = side === "buy" ? "buy" : "sell";
64 if (side === "buy")
65 {
66 return [
67 `Unfortunately your buy order for ${quantity}× ${itemName} could not be filled within one month.`,
68 "",
69 "Your reserved coins have been returned to your bank."
70 ].join("\n");
71 }
72 if (escrowLabel === "written cheque")
73 {
74 return [
75 `Unfortunately your sell order for ${quantity}× ${itemName} could not be filled within one month.`,
76 "",
77 "Your reserved written cheque has been returned to your bank."
78 ].join("\n");
79 }
65 return [
80 return [
66 `Unfortunately your ${kind} order for ${quantity}× ${itemName} could not be filled within one month.`,
81 `Unfortunately your sell order for ${quantity}× ${itemName} could not be filled within one month.`,
67 "",
82 "",
68 `Your reserved ${escrowLabel} has been returned to your bank.`
83 "The listed goods have been returned to your bank."
69 ].join("\n");
84 ].join("\n");
70}
85}
71
86
72export function orderCancelledLetterBody ({ side, itemName, quantity, escrowLabel, clerkName })
87export function orderCancelledLetterBody ({ side, itemName, quantity, escrowLabel, clerkName })
73{
88{
74 void clerkName;
89 void clerkName;
75 const kind = side === "buy" ? "buy" : "sell";
90 if (side === "buy")
91 {
92 return [
93 `Your buy order for ${quantity}× ${itemName} was cancelled.`,
94 "",
95 "Your reserved coins have been returned to your bank."
96 ].join("\n");
97 }
98 if (escrowLabel === "written cheque")
99 {
100 return [
101 `Your sell order for ${quantity}× ${itemName} was cancelled.`,
102 "",
103 "Your reserved written cheque has been returned to your bank."
104 ].join("\n");
105 }
76 return [
106 return [
77 `Your ${kind} order for ${quantity}× ${itemName} was cancelled.`,
107 `Your sell order for ${quantity}× ${itemName} was cancelled.`,
78 "",
108 "",
79 `Your reserved ${escrowLabel} has been returned to your bank.`
109 "The listed goods have been returned to your bank."
80 ].join("\n");
110 ].join("\n");
81}
111}
82
112