Files
gold_land_user/test/castle-exam.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

42 lines
1.8 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 { clearExamAnswers, sectionIds, unansweredCount } from '../src/modules/gold-land/castle-exam/castleState'
const questions = [
{ id: 'castle-q1', sectionId: 'basics' },
{ id: 'castle-q2', sectionId: 'basics' },
{ id: 'castle-q5', sectionId: 'market' },
{ id: 'castle-q9', sectionId: 'choices' },
]
test('sections keep answers while moving and incomplete exams do not submit', () => {
assert.deepEqual(sectionIds(questions), ['basics', 'market', 'choices'])
let answers: Record<string, string> = { 'castle-q1': 'exchange' }
answers = { ...answers, 'castle-q5': 'no' }
assert.equal(answers['castle-q1'], 'exchange')
assert.equal(unansweredCount(questions.map((question) => question.id), answers), 2)
assert.equal(unansweredCount(questions.map((question) => question.id), answers) === 0, false)
})
test('network and session failures keep or clear exam answers without applying me', async () => {
let answers: Record<string, string> = { 'castle-q1': 'exchange' }
resetMeMutationQueueForTests()
let applied = 0
bindMeMutationApply(() => {
applied += 1
return true
})
await assert.rejects(() => runMeMutation(async () => { throw new ApiNetworkError() }), ApiNetworkError)
assert.equal(answers['castle-q1'], 'exchange')
await assert.rejects(() => runMeMutation(async () => {
invalidateSession()
answers = clearExamAnswers()
return { me: { user: { coins: 1 } } }
}), StaleSessionError)
assert.equal(applied, 0)
assert.deepEqual(answers, {})
})