forked from doubtfire-lms/doubtfire-web
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the spec test basic version for numbas-lms service Added by Daniel
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { NumbasLmsService } from '../numbas-lms.service'; | ||
import { TaskService } from '../task.service'; | ||
import { UserService } from '../user.service'; | ||
import { of } from 'rxjs'; | ||
|
||
describe('NumbasLmsService', () => { | ||
let service: NumbasLmsService; | ||
let httpTestingController: HttpTestingController; | ||
let mockUserService: Partial<UserService>; | ||
let mockTaskService: Partial<TaskService>; | ||
|
||
const mockUserData = { | ||
currentUser: { studentId: '12345' } | ||
}; | ||
|
||
beforeEach(() => { | ||
mockUserService = { | ||
currentUser: mockUserData.currentUser | ||
}; | ||
|
||
mockTaskService = { | ||
// you can add mocked methods if needed for the TaskService | ||
}; | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [ | ||
NumbasLmsService, | ||
{ provide: UserService, useValue: mockUserService }, | ||
{ provide: TaskService, useValue: mockTaskService } | ||
] | ||
}); | ||
|
||
service = TestBed.inject(NumbasLmsService); | ||
httpTestingController = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
httpTestingController.verify(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should initialize with default values', () => { | ||
expect(service.GetValue('cmi.completion_status')).toBe('not attempted'); | ||
expect(service.GetValue('cmi.entry')).toBe('ab-initio'); | ||
}); | ||
|
||
describe('Initialize function', () => { | ||
|
||
it('should handle review mode and get latest completed test result', () => { | ||
const mockResponse = { | ||
data: { | ||
exam_data: JSON.stringify({ someData: 'value' }) | ||
} | ||
}; | ||
|
||
service.Initialize('review'); | ||
const req = httpTestingController.expectOne(`${service['apiBaseUrl']}/completed-latest`); | ||
expect(req.request.method).toEqual('GET'); | ||
req.flush(mockResponse); | ||
|
||
expect(service.GetValue('cmi.suspend_data')).toEqual(JSON.stringify({ someData: 'value' })); | ||
}); | ||
|
||
it('should handle attempt mode and get latest test result', () => { | ||
const mockResponse = { | ||
data: { | ||
id: 1, | ||
cmi_entry: 'ab-initio', | ||
attempt_number: 2 | ||
} | ||
}; | ||
|
||
service.Initialize('attempt'); | ||
const req = httpTestingController.expectOne(`${service['apiBaseUrl']}/latest`); | ||
expect(req.request.method).toEqual('GET'); | ||
req.flush(mockResponse); | ||
|
||
expect(service.GetValue('cmi.learner_id')).toBe('12345'); | ||
}); | ||
}); | ||
|
||
}); |
45ee07c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ontrack - Build Spec test for LMS service.