Skip to content

Commit

Permalink
Add ability to unamend an unmodified amendment
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha-dresden committed Aug 21, 2024
1 parent fe82ce0 commit 71cb97e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
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 @@ -85,6 +98,19 @@ describe('ReportListComponent', () => {
expect(amendSpy).toHaveBeenCalled();
});

describe('unamend', () => {
it('should call confirm', () => {
const confirmSpy = spyOn(component.confirmationService, 'confirm');
component.confirmUnamend(testActiveReport);
expect(confirmSpy).toHaveBeenCalledTimes(1);
});

it('should hit service', () => {
const unamendSpy = spyOn(reportService, 'startUnamendment').and.returnValue(of(''));
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
23 changes: 23 additions & 0 deletions front-end/src/app/reports/report-list/report-list.component.ts
Original file line number Diff line number Diff line change
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.confirmUnamend.bind(this), (report: Report) => report.can_unamend),
new TableAction('Download as .fec', this.download.bind(this)),
];

Expand Down Expand Up @@ -107,6 +108,28 @@ export class ReportListComponent extends TableListBaseComponent<Report> implemen
});
}

public confirmUnamend(report: Report): void {
this.confirmationService.confirm({
message: 'Are you sure you want to unamend this amendent? This action cannot be undone.',
header: 'Hang on...',
rejectLabel: 'Cancel',
rejectIcon: 'none',
rejectButtonStyleClass: 'p-button-secondary',
acceptLabel: 'Confirm',
acceptIcon: 'none',
accept: async () => this.unamendReport(report),
});
}

async unamendReport(report: Report) {
this.itemService
.startUnamendment(report)
.pipe(take(1), takeUntil(this.destroy$))
.subscribe(() => {
this.loadTableItems({});
});
}

public confirmDelete(report: Report): void {
this.confirmationService.confirm({
message: 'Are you sure you want to delete this report? This action cannot be undone.',
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
13 changes: 13 additions & 0 deletions front-end/src/app/shared/services/report.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ describe('ReportService', () => {
req.flush('amended 1');
httpTestingController.verify();
});

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

service.startUnamendment(report).subscribe((response: string) => {
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();
});
});
4 changes: 4 additions & 0 deletions front-end/src/app/shared/services/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export class ReportService implements TableListService<Report> {
return this.apiService.post(`${this.apiEndpoint}/${report.id}/amend/`, {});
}

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

preparePayload(item: Report): Record<string, unknown> {
const payload = item.toJson();
delete payload['schema'];
Expand Down

0 comments on commit 71cb97e

Please sign in to comment.