import assert from 'node:assert/strict' import test from 'node:test' import { ApiNetworkError, StaleSessionError } from '../src/api/errors' import { invalidateSession } from '../src/api/authSession' import { bindMeMutationApply, resetMeMutationQueueForTests, runMeMutation } from '../src/api/meMutationQueue' import { moneyText, setShopAnswer } from '../src/modules/gold-land/smart-shop/shopText' test('need budget and cost parts stay distinct, and unknown is not zero', () => { assert.equal(moneyText(50).includes('۵۰'), true) assert.equal(moneyText(45).includes('۴۵'), true) assert.equal(moneyText(null), 'نامشخص') assert.notEqual(moneyText(null), moneyText(0)) }) test('review can change a choice and a failed submit keeps it', async () => { let answers = setShopAnswer({}, 'notebook-choice', 'a') answers = setShopAnswer(answers, 'notebook-choice', 'b') assert.equal(answers['notebook-choice'], 'b') resetMeMutationQueueForTests() let applied = 0 bindMeMutationApply(() => { applied += 1 return true }) await assert.rejects(() => runMeMutation(async () => { throw new ApiNetworkError() }), ApiNetworkError) await assert.rejects(() => runMeMutation(async () => { invalidateSession() return { me: { user: { coins: 1 } } } }), StaleSessionError) assert.equal(applied, 0) assert.equal(answers['notebook-choice'], 'b') })