Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/1444 - Add ability to unamend an unmodified amendment #2136

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ describe('ReportListComponent', () => {
expect(component).toBeTruthy();
});

describe('rowActions', () => {
it('should have "Unamend" if report can_unamend', () => {
const report = testActiveReport;
report.can_unamend = false;
const action = component.rowActions.find((action) => action.label === 'Unamend');
if (action) {
expect(action.isAvailable(report)).toBeFalse();
report.can_unamend = true;
expect(action.isAvailable(report)).toBeTrue();
}
});
});

it('#getEmptyItem should return a new Report instance', () => {
const item = component['getEmptyItem']();
expect(item.id).toBe(undefined);
Expand All @@ -79,12 +92,19 @@ describe('ReportListComponent', () => {
expect(navigateSpy).toHaveBeenCalledWith('/reports/f3x/submit/status/777');
});

it('#amend should hit service', () => {
const amendSpy = spyOn(reportService, 'startAmendment').and.returnValue(of(''));
component.amendReport({ id: '999' } as Report);
it('#amend should hit service', fakeAsync(async () => {
const amendSpy = spyOn(reportService, 'startAmendment').and.returnValue(Promise.resolve(''));
await component.amendReport({ id: '999' } as Report);
expect(amendSpy).toHaveBeenCalled();
});
}));

describe('unamend', () => {
it('should hit service', fakeAsync(async () => {
const unamendSpy = spyOn(reportService, 'startUnamendment').and.returnValue(Promise.resolve(''));
await component.unamendReport({ id: '999' } as Report);
expect(unamendSpy).toHaveBeenCalled();
}));
});
it('#onActionClick should route properly', () => {
const navigateSpy = spyOn(router, 'navigateByUrl');
component.onRowActionClick(new TableAction('', component.editItem.bind(component)), {
Expand Down
24 changes: 16 additions & 8 deletions front-end/src/app/reports/report-list/report-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
import { firstValueFrom, lastValueFrom, take, takeUntil } from 'rxjs';
import { firstValueFrom, lastValueFrom } from 'rxjs';
import { ConfirmationService, MessageService } from 'primeng/api';
import { TableAction, TableListBaseComponent } from '../../shared/components/table-list-base/table-list-base.component';
import { Report, ReportStatus, ReportTypes } from '../../shared/models/report.model';
Expand Down Expand Up @@ -33,6 +33,7 @@ export class ReportListComponent extends TableListBaseComponent<Report> implemen
(report: Report) => report.report_status !== ReportStatus.IN_PROGRESS,
),
new TableAction('Delete', this.confirmDelete.bind(this), (report: Report) => report.can_delete),
new TableAction('Unamend', this.unamendReport.bind(this), (report: Report) => report.can_unamend),
new TableAction('Download as .fec', this.download.bind(this)),
];

Expand Down Expand Up @@ -98,13 +99,20 @@ export class ReportListComponent extends TableListBaseComponent<Report> implemen
}
}

public amendReport(report: Report): void {
this.itemService
.startAmendment(report)
.pipe(take(1), takeUntil(this.destroy$))
.subscribe(() => {
this.loadTableItems({});
});
async amendReport(report: Report) {
await this.itemService.startAmendment(report);
this.loadTableItems({});
}

async unamendReport(report: Report) {
await this.itemService.startUnamendment(report);
this.loadTableItems({});
this.messageService.add({
severity: 'success',
summary: 'Successful',
detail: 'Report Unamended',
life: 3000,
});
}

public confirmDelete(report: Report): void {
Expand Down
1 change: 1 addition & 0 deletions front-end/src/app/shared/models/report.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export abstract class Report extends BaseModel {
@Transform(BaseModel.dateTransform)
updated: Date | undefined;
can_delete = false;
can_unamend = false;
version_label?: string;
report_code?: string;
report_code_label?: string;
Expand Down
21 changes: 17 additions & 4 deletions front-end/src/app/shared/services/report.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { provideMockStore } from '@ngrx/store/testing';
import { testMockStore } from '../utils/unit-test.utils';
Expand Down Expand Up @@ -70,16 +70,29 @@ describe('ReportService', () => {
httpTestingController.verify();
});

it('#startAmendment() should call amend', () => {
it('#startAmendment() should call amend', fakeAsync(async () => {
const report: Form3X = Form3X.fromJSON({ id: 1 });

service.startAmendment(report).subscribe((response: string) => {
service.startAmendment(report).then((response) => {
expect(response).toEqual('amended 1');
});

const req = httpTestingController.expectOne(`${environment.apiUrl}/reports/1/amend/`);
expect(req.request.method).toEqual('POST');
req.flush('amended 1');
httpTestingController.verify();
});
}));

it('#startUnamendment() should call unamend', fakeAsync(async () => {
const report: Form3X = Form3X.fromJSON({ id: 1 });

service.startUnamendment(report).then((response) => {
expect(response).toEqual('unamended 1');
});

const req = httpTestingController.expectOne(`${environment.apiUrl}/reports/1/unamend/`);
expect(req.request.method).toEqual('POST');
req.flush('unamended 1');
httpTestingController.verify();
}));
});
8 changes: 6 additions & 2 deletions front-end/src/app/shared/services/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ export class ReportService implements TableListService<Report> {
return !uploadSubmission || fecStatus == 'REJECTED' || fecfileTaskState == 'FAILED';
}

public startAmendment(report: Report): Observable<string> {
return this.apiService.post(`${this.apiEndpoint}/${report.id}/amend/`, {});
public startAmendment(report: Report): Promise<string> {
return firstValueFrom(this.apiService.post(`${this.apiEndpoint}/${report.id}/amend/`, {}));
}

public startUnamendment(report: Report): Promise<string> {
return firstValueFrom(this.apiService.post(`${this.apiEndpoint}/${report.id}/unamend/`, {}));
}

preparePayload(item: Report): Record<string, unknown> {
Expand Down