Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caebr committed Oct 28, 2020
1 parent 7175468 commit abba28e
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { buildTestModuleMetadata } from 'src/spec-helpers';
import { StudentProfileApprenticeshipCompanyComponent } from './student-profile-apprenticeship-company.component';
import { buildApprenticeshipContract, buildPerson } from 'src/spec-builders';
import {
buildApprenticeshipContract,
buildApprenticeshipManager,
buildJobTrainer,
} from 'src/spec-builders';

describe('StudentProfileApprenticeshipCompanyComponent', () => {
let component: StudentProfileApprenticeshipCompanyComponent;
Expand All @@ -23,8 +27,8 @@ describe('StudentProfileApprenticeshipCompanyComponent', () => {
component = fixture.componentInstance;
component.company = {
apprenticeshipContract: buildApprenticeshipContract(123, 10, 20),
jobTrainerPerson: buildPerson(10),
apprenticeshipManagerPerson: buildPerson(20),
jobTrainer: buildJobTrainer(10),
apprenticeshipManager: buildApprenticeshipManager(20),
};
fixture.detectChanges();
});
Expand Down
80 changes: 61 additions & 19 deletions src/app/shared/services/student-profile.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import {
buildPerson,
buildStudent,
buildPersonWithEmails,
buildJobTrainerWithEmails,
buildApprenticeshipManagerWithEmails,
} from 'src/spec-builders';
import { buildTestModuleMetadata } from 'src/spec-helpers';
import {
StudentProfileService,
Profile,
} from '../../shared/services/student-profile.service';
import { ApprenticeshipManager } from '../models/apprenticeship-manager.model';
import { DropDownItem } from '../models/drop-down-item.model';
import { JobTrainer } from '../models/job-trainer.model';

describe('StudentProfileService', () => {
let httpTestingController: HttpTestingController;
Expand All @@ -28,8 +32,8 @@ describe('StudentProfileService', () => {
let myself: Person;
let legalRepresentatives: LegalRepresentative[];
let apprenticeshipContract: ApprenticeshipContract;
let jobTrainer: Person;
let apprenticeshipManager: Person;
let jobTrainer: JobTrainer;
let apprenticeshipManager: ApprenticeshipManager;
let legalRepresentative1: Person;
let legalRepresentative2: Person;
let persons: Person[];
Expand Down Expand Up @@ -64,19 +68,13 @@ describe('StudentProfileService', () => {
legalRepresentatives[1].RepresentativeId,
'display@email.ch'
);
jobTrainer = buildPersonWithEmails(35468, undefined, 'email1@email.ch');
apprenticeshipManager = buildPersonWithEmails(
jobTrainer = buildJobTrainerWithEmails(35468, 'email1@email.ch');
apprenticeshipManager = buildApprenticeshipManagerWithEmails(
38223,
undefined,
'email1@email.ch',
'email2@email.ch'
);
persons = [
legalRepresentative1,
legalRepresentative2,
jobTrainer,
apprenticeshipManager,
];
persons = [legalRepresentative1, legalRepresentative2];

dropDownItems = [{ Key: myself.StayPermit, Value: 'Permit Value' }];
});
Expand All @@ -100,8 +98,8 @@ describe('StudentProfileService', () => {
apprenticeshipCompanies: [
{
apprenticeshipContract,
jobTrainerPerson: jobTrainer,
apprenticeshipManagerPerson: apprenticeshipManager,
jobTrainer,
apprenticeshipManager,
},
],
});
Expand All @@ -110,6 +108,12 @@ describe('StudentProfileService', () => {
expectLegalRepresentativesRequest(student.Id);
expectApprenticeshipContractRequest(student.Id);
expectPersonsRequest(persons.map((person) => person.Id));
expectApprenticeshipManagerRequest(
apprenticeshipContract.ApprenticeshipManagerId
);
if (apprenticeshipContract.JobTrainer) {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});

it('returns the profile without legal representatives for adult student', () => {
Expand All @@ -123,7 +127,12 @@ describe('StudentProfileService', () => {
expectStudentRequest(student.Id);
expectLegalRepresentativesRequest(student.Id);
expectApprenticeshipContractRequest(student.Id);
expectPersonsRequest(persons.map((person) => person.Id));
expectApprenticeshipManagerRequest(
apprenticeshipContract.ApprenticeshipManagerId
);
if (apprenticeshipContract.JobTrainer) {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});

it('returns the profile only with legal representatives with flag for adult student', () => {
Expand All @@ -140,7 +149,13 @@ describe('StudentProfileService', () => {
expectStudentRequest(student.Id);
expectLegalRepresentativesRequest(student.Id);
expectApprenticeshipContractRequest(student.Id);
expectPersonsRequest(persons.map((person) => person.Id));
expectPersonsRequest([legalRepresentatives[0].RepresentativeId]);
expectApprenticeshipManagerRequest(
apprenticeshipContract.ApprenticeshipManagerId
);
if (apprenticeshipContract.JobTrainer) {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});
});

Expand All @@ -157,8 +172,8 @@ describe('StudentProfileService', () => {
apprenticeshipCompanies: [
{
apprenticeshipContract,
jobTrainerPerson: jobTrainer,
apprenticeshipManagerPerson: apprenticeshipManager,
jobTrainer,
apprenticeshipManager,
},
],
});
Expand All @@ -168,6 +183,12 @@ describe('StudentProfileService', () => {
expectApprenticeshipContractRequest(myself.Id);
expectLoadStayPermitValueRequest();
expectPersonsRequest(persons.map((person) => person.Id));
expectApprenticeshipManagerRequest(
apprenticeshipContract.ApprenticeshipManagerId
);
if (apprenticeshipContract.JobTrainer) {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});

it('returns the profile without legal representatives for adult user', () => {
Expand All @@ -180,7 +201,12 @@ describe('StudentProfileService', () => {
expectLegalRepresentativesRequest(myself.Id);
expectApprenticeshipContractRequest(myself.Id);
expectLoadStayPermitValueRequest();
expectPersonsRequest(persons.map((person) => person.Id));
expectApprenticeshipManagerRequest(
apprenticeshipContract.ApprenticeshipManagerId
);
if (apprenticeshipContract.JobTrainer) {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});

it('returns the profile only with legal representatives with flag for adult', () => {
Expand All @@ -196,7 +222,13 @@ describe('StudentProfileService', () => {
expectLegalRepresentativesRequest(myself.Id);
expectApprenticeshipContractRequest(myself.Id);
expectLoadStayPermitValueRequest();
expectPersonsRequest(persons.map((person) => person.Id));
expectPersonsRequest([legalRepresentatives[0].RepresentativeId]);
expectApprenticeshipManagerRequest(
apprenticeshipContract.ApprenticeshipManagerId
);
if (apprenticeshipContract.JobTrainer) {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});
});

Expand Down Expand Up @@ -225,6 +257,16 @@ describe('StudentProfileService', () => {
httpTestingController.expectOne(url).flush([apprenticeshipContract]);
}

function expectApprenticeshipManagerRequest(id: number): void {
const url = `https://eventotest.api/ApprenticeshipManagers/${id}`;
httpTestingController.expectOne(url).flush(apprenticeshipManager);
}

function expectJobTrainerRequest(id: number): void {
const url = `https://eventotest.api/JobTrainers/${id}`;
httpTestingController.expectOne(url).flush(jobTrainer);
}

function expectPersonsRequest(personIds: number[], response = persons): void {
const url = `https://eventotest.api/Persons/?filter.Id=;${personIds.join(
';'
Expand Down
74 changes: 74 additions & 0 deletions src/spec-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ApprenticeshipContract } from './app/shared/models/apprenticeship-contr
import { LegalRepresentative } from './app/shared/models/legal-representative.model';
import { Person } from './app/shared/models/person.model';
import { LessonPresenceStatistic } from './app/shared/models/lesson-presence-statistic';
import { ApprenticeshipManager } from './app/shared/models/apprenticeship-manager.model';
import { JobTrainer } from './app/shared/models/job-trainer.model';
/*import { TokenPayload } from './app/shared/models/token-payload.model';*/

export function buildReference(id = 123, href?: string): Reference {
Expand Down Expand Up @@ -189,6 +191,56 @@ export function buildLegalRepresentative(
};
}

export function buildApprenticeshipManager(id: number): ApprenticeshipManager {
return {
// HRef: '',
Email: '',
Email2: null,
PhoneBusiness: '',
// PhoneMobile: null,
CompanyName: '',
// CompanyNameAddition: null,
Firstname: null,
// MiddleName: null,
Lastname: null,
// FormOfAddress: null,
// Gender: 'X',
AddressLine1: '',
AddressLine2: undefined,
PostalCode: '',
Location: '',
// Country: null,
// CountryId: '',
// CorrespondenceAddress: null,
// CorrespondencePersonId: 0,
Id: id,
};
}

export function buildJobTrainer(id: number): JobTrainer {
return {
// HRef: '',
Email: null,
Email2: null,
PhoneBusiness: null,
PhoneMobile: null,
Firstname: '',
// MiddleName: null,
Lastname: '',
// FormOfAddress: null,
// Gender: 'X',
// AddressLine1: undefined,
// AddressLine2: undefined,
// PostalCode: null,
// Location: null,
// Country: null,
// CountryId: '',
// CorrespondenceAddress: null,
// CorrespondencePersonId: 0,
Id: id,
};
}

/*
export function buildPayLoad(): TokenPayload {
return {
Expand Down Expand Up @@ -253,3 +305,25 @@ export function buildPersonWithEmails(
person.Email2 = email2;
return person;
}

export function buildJobTrainerWithEmails(
id: number,
email: string,
email2: Option<string> = null
): JobTrainer {
const trainer = buildJobTrainer(id);
trainer.Email = email;
trainer.Email2 = email2;
return trainer;
}

export function buildApprenticeshipManagerWithEmails(
id: number,
email: string,
email2: Option<string> = null
): ApprenticeshipManager {
const manager = buildApprenticeshipManager(id);
manager.Email = email;
manager.Email2 = email2;
return manager;
}

0 comments on commit abba28e

Please sign in to comment.