import { UpdateCoOwnerApiRequest } from '@sky-distribution/policy-service-interfaces/lib/rpc'; import { AdditionalInsuredType } from '@sky-distribution/policy-service-interfaces/lib/core/SubmissionForm.type'; import { buildAdditionalInsuredsPartial } from '../../../../../models/Core/partials/additionalInsureds'; describe('additionalInsureds partial', () => { it('should update AdditionalInsureds data', () => { // given const existingInsureds: AdditionalInsuredType[] = []; const updatedInsureds = [{ name: 'Stefan', surname: 'Napastnik', pesel: '54051492813', }, { name: 'Piotr', surname: 'ObroĊ„ca', pesel: '54051492813', }] as UpdateCoOwnerApiRequest[]; // then expect(buildAdditionalInsuredsPartial({ existingInsureds, updatedInsureds })) .toEqual([ { policyAdditionalInsured: expect.objectContaining({ firstName: updatedInsureds[0].name, lastName: updatedInsureds[0].surname, pesel_SKY: updatedInsureds[0].pesel, }), }, { policyAdditionalInsured: expect.objectContaining({ firstName: updatedInsureds[1].name, lastName: updatedInsureds[1].surname, pesel_SKY: updatedInsureds[1].pesel, }), }, ]); }); it('should return existing ones if no new ones', () => { // given const existingInsureds: AdditionalInsuredType[] = [ { policyAdditionalInsured: { firstName: 'STEFAN', lastName: 'JAWORSKI', pesel_SKY: '54051492813', }, }, ]; const updatedInsureds = [] as UpdateCoOwnerApiRequest[]; // then expect(buildAdditionalInsuredsPartial({ existingInsureds, updatedInsureds })) .toEqual(existingInsureds); }); });