Files
juice-shop/test/server/continueCodeSpec.ts
2025-03-23 20:54:46 +01:00

42 lines
1.3 KiB
TypeScript

/*
* Copyright (c) 2014-2025 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import sinon from 'sinon'
import chai from 'chai'
import sinonChai from 'sinon-chai'
import { challenges } from '../../data/datacache'
import { type Challenge } from 'data/types'
import { continueCode } from '../../routes/continueCode'
const expect = chai.expect
chai.use(sinonChai)
describe('continueCode', () => {
let req: any
let res: any
beforeEach(() => {
req = {}
res = { json: sinon.spy() }
})
it('should be empty when no challenges are solved', () => {
challenges.scoreBoardChallenge = { solved: false } as unknown as Challenge
challenges.adminSectionChallenge = { solved: false } as unknown as Challenge
continueCode()(req, res)
expect(res.json).to.have.been.calledWith({ continueCode: undefined })
})
it('should be hashid value of IDs of solved challenges', () => {
challenges.scoreBoardChallenge = { id: 1, solved: true } as unknown as Challenge
challenges.adminSectionChallenge = { id: 2, solved: true } as unknown as Challenge
challenges.continueCodeChallenge = { id: 3, solved: false } as unknown as Challenge
continueCode()(req, res)
expect(res.json).to.have.been.calledWith({ continueCode: 'yXjv6Z5jWJnzD6a3YvmwPRXK7roAyzHDde2Og19yEN84plqxkMBbLVQrDeoY' })
})
})