mirror of
https://github.com/KeygraphHQ/juice-shop.git
synced 2026-11-10 02:31:39 -10:00
42 lines
1.3 KiB
TypeScript
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' })
|
|
})
|
|
})
|