-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1830 from bcgov/develop
Deployment PR - 1287
- Loading branch information
Showing
33 changed files
with
1,008 additions
and
74 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
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
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
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
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
14 changes: 14 additions & 0 deletions
14
alcs-frontend/src/app/services/incoming-file/incomig-file.dto.ts
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,14 @@ | ||
import { CardType } from '../../shared/card/card.component'; | ||
import { AssigneeDto } from '../user/user.dto'; | ||
|
||
export type IncomingFileDto = { | ||
fileNumber: string; | ||
applicant: string; | ||
boardCode: string; | ||
assignee: AssigneeDto | null; | ||
type: CardType; | ||
highPriority: boolean; | ||
activeDays: number; | ||
}; | ||
|
||
export type IncomingFileBoardMapDto = Record<string, IncomingFileDto[]>; |
114 changes: 114 additions & 0 deletions
114
alcs-frontend/src/app/services/incoming-file/incoming-file.service.spec.ts
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,114 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MatSnackBarModule } from '@angular/material/snack-bar'; | ||
import { IncomingFileService } from './incoming-file.service'; | ||
import { IncomingFileBoardMapDto } from './incomig-file.dto'; | ||
import { CardType } from '../../shared/card/card.component'; | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { ToastService } from '../toast/toast.service'; | ||
import { of } from 'rxjs'; | ||
|
||
describe('ApplicationIncomingFileService', () => { | ||
let service: IncomingFileService; | ||
let httpClient: DeepMocked<HttpClient>; | ||
let toastService: DeepMocked<ToastService>; | ||
|
||
beforeEach(() => { | ||
httpClient = createMock(); | ||
toastService = createMock(); | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule, MatSnackBarModule], | ||
providers: [ | ||
{ provide: HttpClient, useValue: httpClient }, | ||
{ provide: ToastService, useValue: toastService }, | ||
], | ||
}); | ||
service = TestBed.inject(IncomingFileService); | ||
}); | ||
|
||
let unsortedFiles: IncomingFileBoardMapDto = { | ||
'board-1': [ | ||
{ | ||
fileNumber: '1', | ||
applicant: 'applicant', | ||
boardCode: 'board-1', | ||
type: CardType.APP, | ||
assignee: null, | ||
highPriority: false, | ||
activeDays: 10, | ||
}, | ||
{ | ||
fileNumber: '2', | ||
applicant: 'applicant', | ||
boardCode: 'board-1', | ||
type: CardType.PLAN, | ||
assignee: null, | ||
highPriority: true, | ||
activeDays: 12, | ||
}, | ||
{ | ||
fileNumber: '3', | ||
applicant: 'applicant', | ||
boardCode: 'board-1', | ||
type: CardType.APP, | ||
assignee: null, | ||
highPriority: true, | ||
activeDays: 30, | ||
}, | ||
], | ||
}; | ||
|
||
let expectedSortedFiles: IncomingFileBoardMapDto = { | ||
'board-1': [ | ||
{ | ||
fileNumber: '3', | ||
applicant: 'applicant', | ||
boardCode: 'board-1', | ||
type: CardType.APP, | ||
assignee: null, | ||
highPriority: true, | ||
activeDays: 30, | ||
}, | ||
{ | ||
fileNumber: '2', | ||
applicant: 'applicant', | ||
boardCode: 'board-1', | ||
type: CardType.PLAN, | ||
assignee: null, | ||
highPriority: true, | ||
activeDays: 12, | ||
}, | ||
{ | ||
fileNumber: '1', | ||
applicant: 'applicant', | ||
boardCode: 'board-1', | ||
type: CardType.APP, | ||
assignee: null, | ||
highPriority: false, | ||
activeDays: 10, | ||
}, | ||
], | ||
}; | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should call get for fetchingTypes', async () => { | ||
httpClient.get.mockReturnValue(of(unsortedFiles)); | ||
|
||
const res = await service.fetch(); | ||
expect(httpClient.get).toHaveBeenCalledTimes(1); | ||
expect(Object.keys(res!).length).toEqual(1); | ||
}); | ||
|
||
it('should sort the incoming data based on priority and active days', async () => { | ||
httpClient.get.mockReturnValue(of(unsortedFiles)); | ||
|
||
const res = await service.fetchAndSort(); | ||
expect(httpClient.get).toHaveBeenCalledTimes(1); | ||
expect(res).toEqual(expectedSortedFiles); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
alcs-frontend/src/app/services/incoming-file/incoming-file.service.ts
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,46 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { environment } from '../../../environments/environment'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { ToastService } from '../toast/toast.service'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { IncomingFileBoardMapDto } from './incomig-file.dto'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class IncomingFileService { | ||
private url = `${environment.apiUrl}/incoming-files`; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private toastService: ToastService, | ||
) {} | ||
|
||
async fetch() { | ||
try { | ||
return await firstValueFrom(this.http.get<IncomingFileBoardMapDto>(`${this.url}`)); | ||
} catch (err) { | ||
this.toastService.showErrorToast('Failed to fetch incoming files'); | ||
} | ||
return; | ||
} | ||
|
||
async fetchAndSort() { | ||
const incomingFiles = await this.fetch(); | ||
|
||
if (incomingFiles) { | ||
Object.keys(incomingFiles!).forEach((board) => { | ||
incomingFiles![board].sort((fileOne, fileTwo) => { | ||
if (fileOne.highPriority !== fileTwo.highPriority) { | ||
return fileOne.highPriority ? -1 : 1; | ||
} | ||
return fileTwo.activeDays - fileOne.activeDays; | ||
}); | ||
}); | ||
|
||
return incomingFiles; | ||
} | ||
|
||
return; | ||
} | ||
} |
Oops, something went wrong.