Skip to content

Commit

Permalink
Remove appendActCodesToActNames function and references in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sggerard committed Jun 12, 2024
1 parent a897b5b commit 9c1c1da
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,34 @@ import { of } from 'rxjs';
import { ActivatedRouteSnapshot } from '@angular/router';
import { TableObject } from 'nrpti-angular-components';
import { EpicProjectIds } from '../../../../common/src/app/utils/record-constants';
import { RecordUtils } from './utils/record-utils';

describe('RecordsResolver', () => {
const spyFactoryService = jasmine.createSpyObj<FactoryService>('FactoryService', ['getRecords']);
const spyTableTemplateUtils = jasmine.createSpyObj<TableTemplateUtils>('TableTemplateUtils', [
'updateTableObjectWithUrlParams'
]);
const spyRecordUtils = jasmine.createSpyObj<RecordUtils>('RecordUtils', ['appendActCodesToActNames']);

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{ provide: FactoryService, useValue: spyFactoryService },
{ provide: TableTemplateUtils, useValue: spyTableTemplateUtils },
{ provide: RecordUtils, useValue: spyRecordUtils }
{ provide: TableTemplateUtils, useValue: spyTableTemplateUtils }
]
}).compileComponents();
});

it('should create', async(() => {
const factoryService = TestBed.get(FactoryService);
const tableTemplateUtils = TestBed.get(TableTemplateUtils);
const recordUtils = TestBed.get(RecordUtils);

const recordsResolver = new RecordsResolver(factoryService, tableTemplateUtils, recordUtils);
const recordsResolver = new RecordsResolver(factoryService, tableTemplateUtils);

expect(recordsResolver).toBeTruthy();
}));

describe('resolve', () => {
let factoryServiceSpy: jasmine.SpyObj<FactoryService>;
let tableTemplateUtilsSpy: jasmine.SpyObj<TableTemplateUtils>;
let recordUtilsSpy: jasmine.SpyObj<RecordUtils>;

describe('with empty/null route parameters', () => {
const activatedRouteSnapshot: ActivatedRouteSnapshot = {
Expand All @@ -62,13 +57,12 @@ describe('RecordsResolver', () => {
beforeAll(async(() => {
factoryServiceSpy = TestBed.get(FactoryService);
tableTemplateUtilsSpy = TestBed.get(TableTemplateUtils);
recordUtilsSpy = TestBed.get(RecordUtils);

factoryServiceSpy.getRecords.calls.reset();
factoryServiceSpy.getRecords.and.returnValue(of({}));
tableTemplateUtilsSpy.updateTableObjectWithUrlParams.and.returnValue({ currentPage: 1, pageSize: 25 });

const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy, recordUtilsSpy);
const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy);

recordsResolver.resolve(activatedRouteSnapshot);
}));
Expand Down Expand Up @@ -139,13 +133,12 @@ describe('RecordsResolver', () => {
beforeAll(async(() => {
factoryServiceSpy = TestBed.get(FactoryService);
tableTemplateUtilsSpy = TestBed.get(TableTemplateUtils);
recordUtilsSpy = TestBed.get(RecordUtils);

factoryServiceSpy.getRecords.calls.reset();
factoryServiceSpy.getRecords.and.returnValue(of({}));
tableTemplateUtilsSpy.updateTableObjectWithUrlParams.and.returnValue({ currentPage: 1, pageSize: 25 });

const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy, recordUtilsSpy);
const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy);

recordsResolver.resolve(activatedRouteSnapshot);
}));
Expand Down Expand Up @@ -216,13 +209,12 @@ describe('RecordsResolver', () => {
beforeAll(async(() => {
factoryServiceSpy = TestBed.get(FactoryService);
tableTemplateUtilsSpy = TestBed.get(TableTemplateUtils);
recordUtilsSpy = TestBed.get(RecordUtils);

factoryServiceSpy.getRecords.calls.reset();
factoryServiceSpy.getRecords.and.returnValue(of({}));
tableTemplateUtilsSpy.updateTableObjectWithUrlParams.and.returnValue({ currentPage: 1, pageSize: 25 });

const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy, recordUtilsSpy);
const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy);

recordsResolver.resolve(activatedRouteSnapshot);
}));
Expand Down Expand Up @@ -293,13 +285,12 @@ describe('RecordsResolver', () => {
beforeAll(async(() => {
factoryServiceSpy = TestBed.get(FactoryService);
tableTemplateUtilsSpy = TestBed.get(TableTemplateUtils);
recordUtilsSpy = TestBed.get(RecordUtils);

factoryServiceSpy.getRecords.calls.reset();
factoryServiceSpy.getRecords.and.returnValue(of({}));
tableTemplateUtilsSpy.updateTableObjectWithUrlParams.and.returnValue({ currentPage: 1, pageSize: 25 });

const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy, recordUtilsSpy);
const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy);

recordsResolver.resolve(activatedRouteSnapshot);
}));
Expand Down Expand Up @@ -370,13 +361,12 @@ describe('RecordsResolver', () => {
beforeAll(async(() => {
factoryServiceSpy = TestBed.get(FactoryService);
tableTemplateUtilsSpy = TestBed.get(TableTemplateUtils);
recordUtilsSpy = TestBed.get(RecordUtils);

factoryServiceSpy.getRecords.calls.reset();
factoryServiceSpy.getRecords.and.returnValue(of({}));
tableTemplateUtilsSpy.updateTableObjectWithUrlParams.and.returnValue({ currentPage: 1, pageSize: 25 });

const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy, recordUtilsSpy);
const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy);

recordsResolver.resolve(activatedRouteSnapshot);
}));
Expand Down Expand Up @@ -447,13 +437,12 @@ describe('RecordsResolver', () => {
beforeAll(async(() => {
factoryServiceSpy = TestBed.get(FactoryService);
tableTemplateUtilsSpy = TestBed.get(TableTemplateUtils);
recordUtilsSpy = TestBed.get(RecordUtils);

factoryServiceSpy.getRecords.calls.reset();
factoryServiceSpy.getRecords.and.returnValue(of({}));
tableTemplateUtilsSpy.updateTableObjectWithUrlParams.and.returnValue({ currentPage: 1, pageSize: 25 });

const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy, recordUtilsSpy);
const recordsResolver = new RecordsResolver(factoryServiceSpy, tableTemplateUtilsSpy);

recordsResolver.resolve(activatedRouteSnapshot);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Observable } from 'rxjs/Observable';
import { TableTemplateUtils, TableObject } from 'nrpti-angular-components';
import { FactoryService } from '../services/factory.service';
import { EpicProjectIds, SchemaLists } from '../../../../common/src/app/utils/record-constants';
import { RecordUtils } from './utils/record-utils';

@Injectable()
export class RecordsResolver implements Resolve<Observable<object>> {
constructor(
private factoryService: FactoryService,
private tableTemplateUtils: TableTemplateUtils,
private recordUtils: RecordUtils
private tableTemplateUtils: TableTemplateUtils
) {}

resolve(route: ActivatedRouteSnapshot): Observable<object> {
Expand Down Expand Up @@ -59,7 +57,7 @@ export class RecordsResolver implements Resolve<Observable<object>> {
}

if (params.act) {
or['legislation.act'] = this.recordUtils.appendActCodesToActNames(params.act, this.factoryService);
or['legislation.act'] = params.act;
}

if (params.regulation) {
Expand Down
18 changes: 0 additions & 18 deletions angular/projects/admin-nrpti/src/app/records/utils/record-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,6 @@ export class RecordUtils {
record.legislation[0].act = actCode;
}

/**
* Adds the act code to a list of act names for a search query
* @param {Object} actsSTring - a string of comma-seperated act names.
* @param {ServiceFactory} factoryService - The service factory used to create data service instances.
* @returns {string} a string with comma-serparated act names followed by comma sperated act codes
*/
appendActCodesToActNames(actsString, factoryService) {
const dataservice = new ActDataServiceNRPTI(factoryService);
const actList = actsString.split(',');
actList.forEach(actName => {
const actCode = dataservice.getCodeFromTitle(actName);
if (actCode) {
actsString += ',' + actCode;
}
});
return actsString;
}

/**
* Replaces the 'act' value in the given record object with a corresponding act code.
* @param {string} actCode - an intermediate code mapped to a title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { CourtConvictionDetailComponent } from '../court-convictions/court-convi
import { Penalty } from '../../../../../common/src/app/models/master/common-models/penalty';
import { AgencyDataService } from '../../../../../global/src/lib/utils/agency-data-service-nrced';
import { FactoryService } from '../../services/factory.service';
import { ActDataServiceNRCED } from '../../../../../global/src/lib/utils/act-data-service-nrced';
export class RecordUtils {
/**
* Given a record type, return the matching detail component type, or null if no matching component found.
Expand Down Expand Up @@ -190,23 +189,6 @@ export class RecordUtils {
download(`nrced-export-${moment().format('YYYY-MM-DD')}.csv`, output);
}

/**
* Adds the act code to a list of act names for a search query
* @param {Object} actsSTring - a string of comma-seperated act names.
* @param {ServiceFactory} factoryService - The service factory used to create data service instances.
* @returns {string} a string with comma-serparated act names followed by comma sperated act codes
*/
static appendActCodesToActNames(actsString, factoryService) {
const dataservice = new ActDataServiceNRCED(factoryService);
const actList = actsString.split(',');
actList.forEach(actName => {
const actCode = dataservice.getCodeFromTitle(actName);
if (actCode) {
actsString += ',' + actCode;
}
});
return actsString;
}
}

/**
Expand Down

0 comments on commit 9c1c1da

Please sign in to comment.