Skip to content

Commit

Permalink
Add unit tests for AlignmentService
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Apr 11, 2024
1 parent 3688bec commit eea750a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions frontend/src/app/shared/services/alignment.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TestBed } from '@angular/core/testing';
import { AlignmentService } from './alignment.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClient } from '@angular/common/http';
import { of } from 'rxjs';
import { alignmentLists } from '../testData';

const httpClient = {
get: jest.fn(),
Expand All @@ -22,4 +24,42 @@ describe('AlignmentService', () => {
it('should be created', () => {
expect(service).toBeTruthy();
});

it('should set params of filter correctly without objectiveQuery', (done) => {
jest.spyOn(httpClient, 'get').mockReturnValue(of(alignmentLists));
service.getAlignmentByFilter(2, [4, 5], '').subscribe((alignmentLists) => {
alignmentLists.alignmentObjectDtoList.forEach((object) => {
expect(object.objectType).toEqual('objective');
expect(object.objectTeamName).toEqual('Example Team');
});
alignmentLists.alignmentConnectionDtoList.forEach((connection) => {
expect(connection.targetKeyResultId).toEqual(null);
expect(connection.alignedObjectiveId).toEqual(1);
expect(connection.targetObjectiveId).toEqual(2);
});
done();
});
expect(httpClient.get).toHaveBeenCalledWith('/api/v2/alignments/alignmentLists', {
params: { quarterFilter: 2, teamFilter: [4, 5] },
});
});

it('should set params of filter correctly with objectiveQuery', (done) => {
jest.spyOn(httpClient, 'get').mockReturnValue(of(alignmentLists));
service.getAlignmentByFilter(2, [4, 5], 'objective').subscribe((alignmentLists) => {
alignmentLists.alignmentObjectDtoList.forEach((object) => {
expect(object.objectType).toEqual('objective');
expect(object.objectTeamName).toEqual('Example Team');
});
alignmentLists.alignmentConnectionDtoList.forEach((connection) => {
expect(connection.targetKeyResultId).toEqual(null);
expect(connection.alignedObjectiveId).toEqual(1);
expect(connection.targetObjectiveId).toEqual(2);
});
done();
});
expect(httpClient.get).toHaveBeenCalledWith('/api/v2/alignments/alignmentLists', {
params: { objectiveQuery: 'objective', quarterFilter: 2, teamFilter: [4, 5] },
});
});
});

0 comments on commit eea750a

Please sign in to comment.