Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/group service spec #91

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/app/api/services/spec/group.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { Group, Unit } from 'src/app/api/models/doubtfire-model';
import { GroupService } from '../group.service';
import { HttpRequest } from '@angular/common/http';

describe('GroupService', () => {
let groupService: GroupService;
let httpMock: HttpTestingController;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [GroupService]
});

groupService = TestBed.inject(GroupService);
httpMock = TestBed.inject(HttpTestingController);
});

afterEach(() => {
httpMock.verify();
});

it('should return expected group (HttpClient called once)', fakeAsync(() => {
const dummyUnit = new Unit();
const g = new Group(dummyUnit);

g.id = 1;
g.name = 'Group 1';
g.capacityAdjustment = 10;
g.locked = false;
g.studentCount = 15;

const expectedGroups: Group[] = [g];

const mockUnitId = 1;
const mockGroupSetId = 2;
groupService
.query({ unitId: mockUnitId, groupSetId: mockGroupSetId })
.subscribe(groups => expect(groups).toEqual(expectedGroups, 'expected groups'));

const req = httpMock.expectOne((request: HttpRequest<any>): boolean => {
expect(request.url).toEqual(`http://localhost:3000/api/units/${mockUnitId}/group_sets/${mockGroupSetId}/groups/`);
expect(request.method).toBe('GET');
return true;
});

req.flush([g]);

tick();
}));
});
Loading