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/platform independence #166

Merged
merged 4 commits into from
Jan 24, 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
13 changes: 13 additions & 0 deletions components/atoms/KYCModule/KYCModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import KYC from "./kyc";

const GenericKYC = () => {
return <div className="flex flex-col gap-6 justify-center items-center w-full h-96 bg-blue-200">Generic KYC Verification</div>

Check warning on line 4 in components/atoms/KYCModule/KYCModule.js

View check run for this annotation

Codecov / codecov/patch

components/atoms/KYCModule/KYCModule.js#L4

Added line #L4 was not covered by tests
}

const KYCModule = () => {
const useAuthlogic = true;

Check warning on line 8 in components/atoms/KYCModule/KYCModule.js

View check run for this annotation

Codecov / codecov/patch

components/atoms/KYCModule/KYCModule.js#L8

Added line #L8 was not covered by tests

return useAuthlogic? <KYC /> : <GenericKYC />
}

export default KYCModule;
93 changes: 93 additions & 0 deletions components/atoms/KYCModule/kyc-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

export async function authlogic() {
try {
const Options = {
method: 'POST',
mode: 'opaque',
headers: {
'Content-Type': 'application/vnd.authologic.v1.1+json',
Accept: 'application/vnd.authologic.v1.1+json',
'Access-Control-Allow-Origin': '*',
Authorization: `Basic ${Buffer.from(
'wiiqare:WR26jWceSVW3IND0z1BLd0Hn',
).toString('base64')}`,
},
body: JSON.stringify({
userKey: 'qW8uMEUFv4Vb4XyN4RSREbzI',
returnUrl:
'https://authologic.com/tests/return/?conversation={conversationId}',
strategy: 'public:sandbox',
query: {
identity: {
requireOneOf: [['PERSON_NAME_FIRSTNAME', 'PERSON_NAME_LASTNAME']],
},
},
}),
};

const response = await fetch(
'https://sandbox.authologic.com/api/conversations',
Options,
);

console.log('response', response);
const json = response.status == 200 ? response : await response.json();

return json;
} catch (error) {
return error;
}
}

export async function setKyc(formData) {
try {
let token = formData.accessToken;

delete formData.accessToken;

const Options = {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(formData),
};

const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/payer/kyc`,
Options,
);
const json = await response.json();

return json;

Check warning on line 63 in components/atoms/KYCModule/kyc-utils.js

View check run for this annotation

Codecov / codecov/patch

components/atoms/KYCModule/kyc-utils.js#L63

Added line #L63 was not covered by tests
} catch (error) {
return error;
}
}

export async function checkKyc(formData) {
try {
let token = formData.accessToken;

delete formData.accessToken;

const Options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
};

const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/payer/check-kyc`,
Options,
);
const json = await response.json();

return json;

Check warning on line 89 in components/atoms/KYCModule/kyc-utils.js

View check run for this annotation

Codecov / codecov/patch

components/atoms/KYCModule/kyc-utils.js#L89

Added line #L89 was not covered by tests
} catch (error) {
return error;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext, useEffect, useState } from 'react';
import { FormContext } from '../../../../pages/voucher/buy';
import { FormContext } from '../../../pages/voucher/buy';
import { useRouter } from 'next/router';
import { checkKyc, setKyc } from '../../../../lib/helper';
import { checkKyc, setKyc } from './kyc-utils';
import { useSession } from 'next-auth/react';

function KYC() {
Expand Down
88 changes: 88 additions & 0 deletions components/atoms/KYCModule/kyc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import KYC from './kyc';
import { authlogic, checkKyc, setKyc } from './kyc-utils';
import { FormContext } from '../../../pages/voucher/buy';
import { SessionProvider } from 'next-auth/react';
require('jest-fetch-mock').enableMocks();

jest.mock('next/router', () => ({
useRouter: jest.fn().mockReturnValue({
query: {
'payment-intent': 'pi_1J4JrjGswQjYFZwX0Z1Z1Z1Z',
},
}),
}));

describe('KYC', () => {
let component;

beforeEach(() => {
const res = render(
<SessionProvider session={{ user: { data: { userId: 'random123' } } }}>
<FormContext.Provider value={{ activeStepIndex: 0 }}>
<KYC />
</FormContext.Provider>
</SessionProvider>
);
component = res.container;
});

it('should render the component', () => {
expect(component).toMatchSnapshot();
});
});

describe('Helper functions', () => {
beforeEach(() => {
console.log = jest.fn();
fetch = jest.fn().mockResolvedValueOnce({
status: 200,
json: jest.fn().mockResolvedValueOnce({
hello: 'world',
}),
});
});

it('authlogic', async () => {
fetch = jest.fn().mockResolvedValueOnce({
status: 200,
hello: 'world',
});
const response = await authlogic({ test: 'payload' });

expect(response).toEqual({ status: 200, hello: 'world' });
});
});

describe('Helper functions errors', () => {
beforeEach(() => {
jest.clearAllMocks();
console.log = jest.fn();
fetch = jest.fn().mockResolvedValueOnce({
json: jest.fn().mockRejectedValueOnce(new Error('test')),
});
});



it('authlogic', async () => {
fetch = jest.fn().mockRejectedValueOnce(new Error('test'));

const response = await authlogic({ test: 'payload' });

expect(response).toEqual(new Error('test'));
});

it('setKyc', async () => {
const response = await setKyc({ test: 'payload', accessToken: 'test' });

expect(response).toEqual(new Error('test'));
});

it('checkKyc', async () => {
const response = await checkKyc({ test: 'payload', accessToken: 'test' });

expect(response).toEqual(new Error('test'));
});
});
2 changes: 2 additions & 0 deletions components/atoms/Stepper/Forms/identity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('Identity2', () => {
});

it('should fill the form', async () => {
jest.setTimeout(10000)

const user = userEvent.setup({ delay: null });

const addBeneficiary = screen.getByText('Ajouter un bénéficiaire');
Expand Down
32 changes: 0 additions & 32 deletions components/atoms/Stepper/Forms/kyc.test.js

This file was deleted.

13 changes: 6 additions & 7 deletions components/atoms/Stepper/Forms/payment2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { FormContext } from '../../../../pages/voucher/buy';
import { HiArrowSmLeft, HiOutlineInformationCircle } from 'react-icons/hi';
import * as yup from 'yup';
import StripePayment from '../../../molecules/Stripe';

import { useSession } from 'next-auth/react';
import { FcCurrencyExchange } from 'react-icons/fc';
import { CgArrowsExchangeAltV } from 'react-icons/cg';
Expand All @@ -13,7 +13,8 @@
import { countries } from 'country-data';
import { setPatientDispatch } from '../../../../redux/reducer';
import Image from 'next/image';
import KYC from './kyc';
import KYCModule from './../../KYCModule/KYCModule';
import PaymentForm from '../../../molecules/PaymentForm/PaymentForm';

function Payment2() {
const {
Expand Down Expand Up @@ -234,15 +235,13 @@
activeStepIndex={activeStepIndex}
/>
) : !kycTest ? (
<StripePayment
amount={amount}
<PaymentForm amount={amount}
senderId={data.user.data.userId}
patientId={patient.id}
email={data.user.data.email}
setAmount={setAmount}
/>
setAmount={setAmount} />
) : (
<KYC />
<KYCModule />

Check warning on line 244 in components/atoms/Stepper/Forms/payment2.js

View check run for this annotation

Codecov / codecov/patch

components/atoms/Stepper/Forms/payment2.js#L244

Added line #L244 was not covered by tests
)}
</>
);
Expand Down
27 changes: 27 additions & 0 deletions components/molecules/PaymentForm/PaymentForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useContext, useState, useEffect } from 'react';
import StripePayment from './../Stripe';
// import PaymentStub from './../PaymentStub'
abhiShandy marked this conversation as resolved.
Show resolved Hide resolved

export const useStripeLib = false;

const PaymentForm = ({ amount, senderId, patientId, email, setAmount }) => {

return (<>
<StripePayment
amount={amount}
senderId={senderId}
patientId={patientId}
email={email}
setAmount={setAmount}
/>
{/* <PaymentStub
amount={amount}
senderId={senderId}
patientId={patientId}
email={email}
setAmount={setAmount}
/> */}
</>)
}

export default PaymentForm;
Loading