Skip to content

Commit

Permalink
Merge pull request #2112 from ucfopen/dev/33-serpierite
Browse files Browse the repository at this point in the history
This has been running properly in a production environment for quite a while. Finalizing to start a new dev branch.
  • Loading branch information
FrenjaminBanklin authored May 1, 2024
2 parents e8050b0 + 435edea commit 7455481
Show file tree
Hide file tree
Showing 60 changed files with 1,115 additions and 529 deletions.
2 changes: 1 addition & 1 deletion docker/obojobo-pm2-server-src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obojobo-pm2-server-app",
"version": "17.0.0",
"version": "17.1.0",
"description": "Reference project for deploying and customizing an Obojobo Next server",
"main": "./index.js",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/**/*"
],
"version": "17.0.0",
"version": "17.1.0",
"command": {
"command": {
"run": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "obojobo-next",
"version": "17.0.0",
"version": "17.1.0",
"repository": "https://github.com/ucfopen/Obojobo.git",
"homepage": "https://ucfopen.github.io/Obojobo-Docs/",
"license": "AGPL-3.0-only",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,44 @@ describe('AssessmentStateHelpers', () => {
spy.mockRestore()
})

test('saveAttemptState returns true when good response returns', async () => {
AssessmentAPI.saveAttempt.mockResolvedValue({ status: 'ok' })

const mockState = { mockProp: 'mockVal' }

const result = await AssessmentStateHelpers.saveAttemptState(
'mockAssessmentId',
'mockAttemptId',
mockState
)

expect(AssessmentAPI.saveAttempt).toHaveBeenCalledWith({
assessmentId: 'mockAssessmentId',
attemptId: 'mockAttemptId',
draftId: 'mockDraftId',
draftContentId: 'mockDraftId',
state: mockState,
visitId: 'mockVisitId'
})
expect(result).toBe(true)
})

test('saveAttemptState throws an error when bad response returns', async () => {
AssessmentAPI.saveAttempt.mockResolvedValue({
status: 'error',
value: { message: 'mockErrorMessage' }
})

try {
await AssessmentStateHelpers.saveAttemptState('mockAssessmentId', 'mockAttemptId'),
{
mockProp: 'mockVal'
}
} catch (e) {
expect(e).toEqual(Error('mockErrorMessage'))
}
})

test('resumeAttempt calls AssessmentStateHelpers.onAttemptStarted when good response returned', async () => {
AssessmentAPI.resumeAttempt.mockResolvedValue({ status: 'ok', value: { questions: [] } })
const spy = jest.spyOn(AssessmentStateHelpers, 'onAttemptStarted').mockReturnValue(true)
Expand Down Expand Up @@ -318,7 +356,7 @@ describe('AssessmentStateHelpers', () => {
expect.assertions(1)
})

test('onAttemptStarted creates OboModels, updates nav context, rebuilds the nav menu, navigates to the assessment, runs the onStartAttempt trigger and fires the assessment:attemptStarted event', () => {
test('onAttemptStarted creates OboModels, updates nav context, rebuilds the nav menu, navigates to the assessment, runs the onStartAttempt trigger and fires the assessment:attemptStarted event (no question responses)', () => {
const res = {
value: {
assessmentId: 'mockAssessmentId',
Expand All @@ -340,11 +378,59 @@ describe('AssessmentStateHelpers', () => {
expect(navUtilSetContextSpy).toHaveBeenCalledWith('assessment:mockAssessmentId:mockAttemptId')
expect(navUtilRebuildMenuSpy).toHaveBeenCalled()
expect(navUtilGoToSpy).toHaveBeenCalledWith('mockAssessmentId')
expect(QuestionStore.getOrCreateContextState).not.toHaveBeenCalled()
expect(QuestionStore.updateStateByContext).not.toHaveBeenCalled()

navUtilSetContextSpy.mockRestore()
navUtilRebuildMenuSpy.mockRestore()
navUtilGoToSpy.mockRestore()
dispatcherTriggerSpy.mockRestore()
})

test('onAttemptStarted creates OboModels, updates nav context, rebuilds the nav menu, navigates to the assessment, runs the onStartAttempt trigger and fires the assessment:attemptStarted event (with question responses)', () => {
const res = {
value: {
assessmentId: 'mockAssessmentId',
attemptId: 'mockAttemptId',
questions: [{ id: 'question1' }, { id: 'question2' }],
questionResponses: [
{ questionId: 'question1', response: true },
{ questionId: 'question2', response: { ids: ['mockNodeId1'] } }
]
}
}

const navUtilSetContextSpy = jest.spyOn(NavUtil, 'setContext')
const navUtilRebuildMenuSpy = jest.spyOn(NavUtil, 'rebuildMenu')
const navUtilGoToSpy = jest.spyOn(NavUtil, 'goto')
const dispatcherTriggerSpy = jest.spyOn(Dispatcher, 'trigger')
const questionStoreContextStateSpy = jest
.spyOn(QuestionStore, 'getOrCreateContextState')
.mockReturnValue({
responseMetadata: {},
responses: {},
viewedQuestions: {}
})

AssessmentStateHelpers.onAttemptStarted(res)

const assessmentModel = OboModel.models.mockAssessmentId
expect(assessmentModel.children.at(1).children.reset).toHaveBeenCalled()
expect(assessmentModel.children.at(1).children.add).toHaveBeenCalledTimes(2)
expect(navUtilSetContextSpy).toHaveBeenCalledWith('assessment:mockAssessmentId:mockAttemptId')
expect(navUtilRebuildMenuSpy).toHaveBeenCalled()
expect(navUtilGoToSpy).toHaveBeenCalledWith('mockAssessmentId')
expect(QuestionStore.getOrCreateContextState).toHaveBeenCalledWith(
'assessment:mockAssessmentId:mockAttemptId'
)
// TODO: check the object specifically to make sure everything was carried over correctly?
expect(QuestionStore.updateStateByContext).toHaveBeenCalledTimes(1)

navUtilSetContextSpy.mockRestore()
navUtilRebuildMenuSpy.mockRestore()
navUtilGoToSpy.mockRestore()
dispatcherTriggerSpy.mockRestore()
questionStoreContextStateSpy.mockRestore()
})

test('getUpdatedAssessmentData returns the expected object', () => {
Expand Down
Loading

0 comments on commit 7455481

Please sign in to comment.