Files
gold_land_user/test/compound-interest.test.ts
safavimohadeseh78andCursor c53a67831d
Frontend CI / unit (test, type-check, build) (push) Successful in 7m21s
Frontend CI / browser E2E (frontend + pinned backend) (push) Successful in 11m38s
feat: complete the thirteen-stage learning experience and E2E journey
Play levels 7-13 in the app and pin E2E to the local thirteen-stage backend commit.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-22 19:42:04 +03:30

46 lines
1.7 KiB
TypeScript

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 { formatCoinTenths, nextShown, previousShown, revealPeriods } from '../src/modules/gold-land/lesson/growthTable'
const periods = [1000, 1100, 1210, 1331]
test('period reveal can move forward and back without changing amounts', () => {
const snapshot = periods.join(',')
let shown = 1
assert.deepEqual(revealPeriods(periods, shown), [1000])
shown = nextShown(shown, periods.length)
shown = nextShown(shown, periods.length)
shown = nextShown(shown, periods.length)
assert.deepEqual(revealPeriods(periods, shown), periods)
shown = previousShown(shown)
assert.equal(revealPeriods(periods, shown).at(-1), 1210)
assert.equal(periods.join(','), snapshot)
assert.equal(formatCoinTenths(1331), '۱۳۳٫۱')
assert.equal(formatCoinTenths(1210), '۱۲۱')
assert.equal(formatCoinTenths(1300), '۱۳۰')
})
test('review keeps the chosen answer and a failed submit does not apply me', async () => {
let answer = '120'
answer = '121'
resetMeMutationQueueForTests()
let applied = 0
bindMeMutationApply(() => {
applied += 1
return true
})
await assert.rejects(() => runMeMutation(async () => {
throw new ApiNetworkError()
}), ApiNetworkError)
assert.equal(answer, '121')
await assert.rejects(() => runMeMutation(async () => {
invalidateSession()
return { me: { user: { coins: 9 } } }
}), StaleSessionError)
assert.equal(applied, 0)
assert.equal(answer, '121')
})