From 6a3febafba584cddad42a411e803048cbf44b1a2 Mon Sep 17 00:00:00 2001 From: Yinka Metrics <115735904+YinkaMetrics@users.noreply.github.com> Date: Fri, 14 Aug 2026 20:58:18 +0100 Subject: [PATCH] refactor(organization): use formatArrayDate helper --- .../offices/office-form.component.spec.ts | 6 ++++-- .../organization/offices/office-form.component.ts | 7 +++---- .../organization/staff/staff-form.component.spec.ts | 12 ++++++++++++ .../organization/staff/staff-form.component.ts | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/app/features/organization/offices/office-form.component.spec.ts b/src/app/features/organization/offices/office-form.component.spec.ts index 802ec53d1..9b91954d4 100644 --- a/src/app/features/organization/offices/office-form.component.spec.ts +++ b/src/app/features/organization/offices/office-form.component.spec.ts @@ -36,6 +36,7 @@ describe('OfficeFormComponent', () => { const OFFICES_PATH = '/organization/offices'; const NEW_OFFICE = 'New Office'; const TEST_OFFICE = 'Test Office'; + const TEST_OPENING_DATE = '2026-06-16'; beforeEach(async () => { officesServiceSpy = jasmine.createSpyObj('OfficesService', [ @@ -197,16 +198,17 @@ describe('OfficeFormComponent', () => { expect(component.officeId).toBe(12); expect(officesServiceSpy.getOfficesOfficeId).toHaveBeenCalledWith(12); expect(component.office().name).toBe(TEST_OFFICE); + expect(component.openingDate()).toBe(TEST_OPENING_DATE); officesServiceSpy.putOfficesOfficeId.and.returnValue(of({}) as unknown as Observable); - component.openingDate.set('2026-06-16'); + component.openingDate.set(TEST_OPENING_DATE); component.onSubmit(); expect(officesServiceSpy.putOfficesOfficeId).toHaveBeenCalledWith( 12, jasmine.objectContaining({ name: TEST_OFFICE, - openingDate: '2026-06-16', + openingDate: TEST_OPENING_DATE, }), ); }); diff --git a/src/app/features/organization/offices/office-form.component.ts b/src/app/features/organization/offices/office-form.component.ts index f4943703e..f5eb18a6e 100644 --- a/src/app/features/organization/offices/office-form.component.ts +++ b/src/app/features/organization/offices/office-form.component.ts @@ -38,7 +38,7 @@ import { IonSelectOption, IonSpinner, } from '@ionic/angular/standalone'; -import { toIsoDate } from '../../../core/utils/date-formatter'; +import { formatArrayDate, toIsoDate } from '../../../core/utils/date-formatter'; import { TooltipDirective } from '../../../shared/directives/tooltip.directive'; import { OfficesService, @@ -217,9 +217,8 @@ export class OfficeFormComponent implements OnInit { loadOfficeData() { if (!this.officeId) return; this.officesService.getOfficesOfficeId(this.officeId).subscribe((data) => { - const dateArray = data.openingDate as unknown as number[]; - if (dateArray) { - this.openingDate.set(toIsoDate(new Date(dateArray[0], dateArray[1] - 1, dateArray[2]))); + if (data.openingDate) { + this.openingDate.set(formatArrayDate(data.openingDate)); } this.office.set({ name: data.name, diff --git a/src/app/features/organization/staff/staff-form.component.spec.ts b/src/app/features/organization/staff/staff-form.component.spec.ts index a77a47359..774aaf555 100644 --- a/src/app/features/organization/staff/staff-form.component.spec.ts +++ b/src/app/features/organization/staff/staff-form.component.spec.ts @@ -74,6 +74,18 @@ describe('StaffFormComponent', () => { expect(officesServiceSpy.getOffices).toHaveBeenCalled(); }); + it('should format the joining date returned by the API', () => { + staffServiceSpy.getStaffStaffId.and.returnValue( + of({ joiningDate: [2026, 1, 5] }) as unknown as ReturnType, + ); + component.staffId = 7; + + component.loadStaffData(); + + expect(staffServiceSpy.getStaffStaffId).toHaveBeenCalledWith(7); + expect(component.joiningDate()).toBe('2026-01-05'); + }); + it('should create staff with a StaffCreateRequest payload on submit', () => { staffServiceSpy.postStaff.and.returnValue( of({}) as unknown as ReturnType, diff --git a/src/app/features/organization/staff/staff-form.component.ts b/src/app/features/organization/staff/staff-form.component.ts index a0dcfb5e3..6df85cedc 100644 --- a/src/app/features/organization/staff/staff-form.component.ts +++ b/src/app/features/organization/staff/staff-form.component.ts @@ -46,6 +46,7 @@ import { GetOfficesResponse, } from '../../../api'; import { + formatArrayDate, formatDateToFineract, FINERACT_DATE_FORMAT, FINERACT_LOCALE, @@ -301,8 +302,7 @@ export class StaffFormComponent implements OnInit { emailAddress: (data as Record)['emailAddress'] as string | undefined, }); if (data.joiningDate) { - const jd = data.joiningDate as unknown as number[]; - this.joiningDate.set(toIsoDate(new Date(jd[0], jd[1] - 1, jd[2]))); + this.joiningDate.set(formatArrayDate(data.joiningDate)); } }); }