Skip to content

Commit

Permalink
Api tests for update contact info
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben <vandervalk@geoit.nl>
  • Loading branch information
Ruben authored and RubenGeo committed Dec 23, 2024
1 parent e0f93b3 commit 8378662
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { HttpStatus } from '@nestjs/common';

import { SeedScript } from '@121-service/src/scripts/seed-script.enum';
import {
programIdVisa,
registrationVisa,
} from '@121-service/src/seed-data/mock/visa-card.data';
import { waitFor } from '@121-service/src/utils/waitFor.helper';
import {
seedPaidRegistrations,
updateRegistration,
} from '@121-service/test/helpers/registration.helper';
import {
getAccessToken,
resetDB,
} from '@121-service/test/helpers/utility.helper';

describe('Should update contact information', () => {
let accessToken: string;

beforeEach(async () => {
await resetDB(SeedScript.nlrcMultiple);
accessToken = await getAccessToken();
await waitFor(2_000);
});

it('should update contact information', async () => {
// Arrange
await seedPaidRegistrations([registrationVisa], programIdVisa);

// Act
const responseUpdateBeforeFspChange = await updateRegistration(
programIdVisa,
registrationVisa.referenceId,
{
phoneNumber: '123456789',
},
'test',
accessToken,
);

await updateRegistration(
programIdVisa,
registrationVisa.referenceId,
{
programFinancialServiceProviderConfigurationName:
'Intersolve-voucher-whatsapp',
},
'test',
accessToken,
);

const responseUpdateAfterFspChange = await updateRegistration(
programIdVisa,
registrationVisa.referenceId,
{
phoneNumber: '987654321',
},
'test',
accessToken,
);

// Assert
expect(responseUpdateBeforeFspChange.status).toBe(HttpStatus.OK);
expect(responseUpdateAfterFspChange.status).toBe(HttpStatus.OK);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ export class IntersolveVisaMockController {
@ApiOperation({ summary: 'Update customer phonenumber' })
@Put('/customer/v1/customers/:holderId/contact-info/phone-numbers')
public updateCustomerPhoneNumber(
@Body() _payload: Record<string, unknown>,
@Body() payload: Record<string, string>,
@Param('holderId') _holderId: string,
): { status: number } {
return this.intersolveVisaMockService.updateCustomerPhoneNumber();
return this.intersolveVisaMockService.updateCustomerPhoneNumber(payload);
}

@ApiOperation({ summary: 'Update customer address' })
@Put('/customer/v1/customers/:holderId/contact-info/addresses')
public updateCustomerAddress(
@Body() _payload: Record<string, unknown>,
@Body() payload: Record<string, string>,
@Param('holderId') _holderId: string,
): { status: number } {
return this.intersolveVisaMockService.updateCustomerAddress();
return this.intersolveVisaMockService.updateCustomerAddress(payload);
}

@ApiOperation({ summary: 'Link token' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,62 @@ export class IntersolveVisaMockService {
return response;
}

public updateCustomerPhoneNumber(): { status: number } {
public updateCustomerPhoneNumber(
payload: Record<string, string>,
): IntersolveVisaMockResponseDto {
if (!payload.value || payload.value.includes('undefined')) {
return {
status: HttpStatus.BAD_REQUEST,
statusText: 'Bad Request',
data: {
success: false,
errors: [
{
code: 'INVALID_PARAMETERS',
field: 'value',
description: 'The field value is required.',
},
],
},
};
}
return {
status: HttpStatus.OK,
statusText: 'OK',
data: {
success: true,
},
};
}

public updateCustomerAddress(): { status: number } {
public updateCustomerAddress(
payload: Record<string, string>,
): IntersolveVisaMockResponseDto {
const addresKeys = ['addressLine1', 'city', 'postalCode', 'country'];
for (const key of addresKeys) {
if (!payload[key] || payload[key].includes('undefined')) {
return {
status: HttpStatus.BAD_REQUEST,
statusText: 'Bad Request',
data: {
success: false,
errors: [
{
code: 'INVALID_PARAMETERS',
field: key,
description: `The ${key} field is required.`,
},
],
},
};
}
}
return {
status: HttpStatus.OK,
statusText: 'OK',
data: {
success: true,
},
};
}

Expand Down

0 comments on commit 8378662

Please sign in to comment.