Skip to content

Commit

Permalink
Show Release Status in NOI Release Decision Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haselhan committed Sep 13, 2023
1 parent 8cd95f1 commit a766884
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { BehaviorSubject } from 'rxjs';
import { ApplicationService } from '../../../../../services/application/application.service';
import { ApplicationDecisionV2Service } from '../../../../../services/application/decision/application-decision-v2/application-decision-v2.service';
import { NoticeOfIntentDecisionV2Service } from '../../../../../services/notice-of-intent/decision-v2/notice-of-intent-decision-v2.service';
import { NoticeOfIntentDecisionDto } from '../../../../../services/notice-of-intent/decision/notice-of-intent-decision.dto';
import { NoticeOfIntentService } from '../../../../../services/notice-of-intent/notice-of-intent.service';
import { NoticeOfIntentSubmissionStatusService } from '../../../../../services/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-submission-status.service';
import { ReleaseDialogComponent } from './release-dialog.component';

describe('ReleaseDialogComponent', () => {
let component: ReleaseDialogComponent;
let fixture: ComponentFixture<ReleaseDialogComponent>;
let mockNOIService: DeepMocked<NoticeOfIntentService>;
let mockNOISubmissionStatusService: DeepMocked<NoticeOfIntentSubmissionStatusService>;
let mockNOIDecisionV2Service: DeepMocked<NoticeOfIntentDecisionV2Service>;

beforeEach(async () => {
mockNOIService = createMock();
mockNOISubmissionStatusService = createMock();
mockNOIDecisionV2Service = createMock();
mockNOIDecisionV2Service.$decision = new BehaviorSubject<NoticeOfIntentDecisionDto | undefined>(undefined);

await TestBed.configureTestingModule({
declarations: [ReleaseDialogComponent],
providers: [
{
provide: NoticeOfIntentService,
useValue: mockNOIService,
provide: NoticeOfIntentSubmissionStatusService,
useValue: mockNOISubmissionStatusService,
},
{
provide: NoticeOfIntentDecisionV2Service,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Subject, takeUntil } from 'rxjs';
import { NoticeOfIntentDecisionV2Service } from '../../../../../services/notice-of-intent/decision-v2/notice-of-intent-decision-v2.service';
import { NoticeOfIntentService } from '../../../../../services/notice-of-intent/notice-of-intent.service';
import { NoticeOfIntentSubmissionStatusService } from '../../../../../services/notice-of-intent/notice-of-intent-submission-status/notice-of-intent-submission-status.service';
import { NOI_SUBMISSION_STATUS } from '../../../../../services/notice-of-intent/notice-of-intent.dto';
import { ApplicationPill } from '../../../../../shared/application-type-pill/application-type-pill.component';

@Component({
Expand All @@ -16,33 +17,35 @@ export class ReleaseDialogComponent implements OnInit, OnDestroy {
wasReleased = false;

constructor(
private noticeOfIntentService: NoticeOfIntentService,
private noticeOfIntentSubmissionStatusService: NoticeOfIntentSubmissionStatusService,
private decisionService: NoticeOfIntentDecisionV2Service,
public matDialogRef: MatDialogRef<ReleaseDialogComponent>,
@Inject(MAT_DIALOG_DATA) data: any
) {}

ngOnInit(): void {
// this.applicationService.$applicationStatuses.pipe(takeUntil(this.$destroy)).subscribe((statuses) => {
// if (statuses) {
// const releasedStatus = statuses.find((status) => status.code === SUBMISSION_STATUS.ALC_DECISION);
// if (releasedStatus) {
// this.mappedType = {
// label: releasedStatus.label,
// backgroundColor: releasedStatus.alcsBackgroundColor,
// borderColor: releasedStatus.alcsBackgroundColor,
// textColor: releasedStatus.alcsColor,
// shortLabel: releasedStatus.label,
// };
// }
// }
// });

this.decisionService.$decision.pipe(takeUntil(this.$destroy)).subscribe((decision) => {
if (decision) {
this.wasReleased = decision.wasReleased;
}
});
this.loadStatuses();
}

private async loadStatuses() {
const statuses = await this.noticeOfIntentSubmissionStatusService.listStatuses();
if (statuses) {
const releasedStatus = statuses.find((status) => status.code === NOI_SUBMISSION_STATUS.ALC_DECISION);
if (releasedStatus) {
this.mappedType = {
label: releasedStatus.label,
backgroundColor: releasedStatus.alcsBackgroundColor,
borderColor: releasedStatus.alcsBackgroundColor,
textColor: releasedStatus.alcsColor,
shortLabel: releasedStatus.label,
};
}
}
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ describe('NoticeOfIntentSubmissionStatusService', () => {
expect(service).toBeTruthy();
});

it('should call get for list all statuses', async () => {
mockHttpClient.get.mockReturnValue(
of([
{
code: 'fake',
},
])
);

const res = await service.listStatuses();

expect(mockHttpClient.get).toHaveBeenCalledTimes(1);
expect(res.length).toEqual(1);
expect(res[0].code).toEqual('fake');
});

it('should fetch statuses by fileNumber', async () => {
mockHttpClient.get.mockReturnValue(
of([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { Injectable } from '@angular/core';
import { firstValueFrom } from 'rxjs';
import { environment } from '../../../../environments/environment';
import { ToastService } from '../../toast/toast.service';
import { NoticeOfIntentSubmissionToSubmissionStatusDto } from './notice-of-intent-submission-status.dto';
import {
NoticeOfIntentStatusDto,
NoticeOfIntentSubmissionToSubmissionStatusDto,
} from './notice-of-intent-submission-status.dto';

@Injectable({
providedIn: 'root',
Expand All @@ -13,6 +16,15 @@ export class NoticeOfIntentSubmissionStatusService {

constructor(private http: HttpClient, private toastService: ToastService) {}

async listStatuses(): Promise<NoticeOfIntentStatusDto[]> {
try {
return await firstValueFrom(this.http.get<NoticeOfIntentStatusDto[]>(`${this.baseUrl}`));
} catch (e) {
this.toastService.showErrorToast('Failed to fetch NOI Statuses');
throw e;
}
}

async fetchSubmissionStatusesByFileNumber(
fileNumber: string,
showErrorToast = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ describe('NoticeOfIntentSubmissionStatusController', () => {
expect(controller).toBeDefined();
});

it('should call the service for list statuses', async () => {
mockNoticeOfIntentSubmissionStatusService.listStatuses.mockResolvedValue(
[],
);

await controller.listStatuses();
expect(
mockNoticeOfIntentSubmissionStatusService.listStatuses,
).toHaveBeenCalledTimes(1);
});

it('should call service to get statuses by file number', async () => {
const fakeFileNumber = 'fake';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { InjectMapper } from '@automapper/nestjs';
import { Controller, Get, Param } from '@nestjs/common';
import { ANY_AUTH_ROLE } from '../../../common/authorization/roles';
import { UserRoles } from '../../../common/authorization/roles.decorator';
import { NoticeOfIntentSubmissionToSubmissionStatusDto } from './notice-of-intent-status.dto';
import { NoticeOfIntentSubmissionStatusType } from './notice-of-intent-status-type.entity';
import {
NoticeOfIntentStatusDto,
NoticeOfIntentSubmissionToSubmissionStatusDto,
} from './notice-of-intent-status.dto';
import { NoticeOfIntentSubmissionToSubmissionStatus } from './notice-of-intent-status.entity';
import { NoticeOfIntentSubmissionStatusService } from './notice-of-intent-submission-status.service';

Expand All @@ -15,6 +19,18 @@ export class NoticeOfIntentSubmissionStatusController {
@InjectMapper() private mapper: Mapper,
) {}

@Get('')
async listStatuses() {
const statuses =
await this.noticeOfIntentSubmissionStatusService.listStatuses();

return this.mapper.mapArrayAsync(
statuses,
NoticeOfIntentSubmissionStatusType,
NoticeOfIntentStatusDto,
);
}

@Get('/:fileNumber')
async getStatusesByFileNumber(@Param('fileNumber') fileNumber) {
const statuses =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ describe('NoticeOfIntentSubmissionStatusService', () => {
expect(service).toBeDefined();
});

it('should load all statuses from the repo', async () => {
mockSubmissionStatusTypeRepository.find.mockResolvedValue([]);

await service.listStatuses();
expect(mockSubmissionStatusTypeRepository.find).toHaveBeenCalledTimes(1);
});

it('should successfully set initial statuses', async () => {
mockSubmissionStatusTypeRepository.find.mockResolvedValue([
new NoticeOfIntentSubmissionStatusType({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export class NoticeOfIntentSubmissionStatusService {
private noticeOfIntentSubmissionRepository: Repository<NoticeOfIntentSubmission>,
) {}

async listStatuses() {
return this.submissionStatusTypeRepository.find();
}

async setInitialStatuses(submissionUuid: string, persist = true) {
const statuses = await this.submissionStatusTypeRepository.find();
const newStatuses: NoticeOfIntentSubmissionToSubmissionStatus[] = [];
Expand Down

0 comments on commit a766884

Please sign in to comment.