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>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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, {})
|
||||
})
|
||||
Reference in New Issue
Block a user