diff --git a/src/core/status/form-status.enum.ts b/src/core/status/form-status.enum.ts new file mode 100644 index 0000000..5d3c048 --- /dev/null +++ b/src/core/status/form-status.enum.ts @@ -0,0 +1,5 @@ +export enum FormStatus { + undefined = 'undefined', + pending = 'pending', + active = 'active', +} diff --git a/src/features/headless-checkout/headless-checkout.spec.ts b/src/features/headless-checkout/headless-checkout.spec.ts index 69d8bb4..6ef246e 100644 --- a/src/features/headless-checkout/headless-checkout.spec.ts +++ b/src/features/headless-checkout/headless-checkout.spec.ts @@ -6,6 +6,7 @@ import { Message } from '../../core/message.interface'; import { Handler } from '../../core/post-messages-client/handler.type'; import { LocalizeService } from '../../core/i18n/localize.service'; import { getFinanceDetailsHandler } from './post-messages-handlers/get-finance-details.handler'; +import { FormStatus } from '../../core/status/form-status.enum'; const mockMessage: Message = { name: EventName.initPayment, @@ -189,4 +190,24 @@ describe('HeadlessCheckout', () => { await headlessCheckout.getUserBalance(); expect(spy).toHaveBeenCalled(); }); + + it('Should have correct form status', async () => { + expect(headlessCheckout.form.getStatus()).toEqual(FormStatus.undefined); + + spyOn(postMessagesClient, 'send').and.callFake(async (msg, callback) => { + await Promise.resolve().then(() => callback(msg)); + return Promise.resolve(undefined); + }); + + const formInitPromise = headlessCheckout.form.init({ + paymentMethodId: 1380, + returnUrl: '', + }); + + expect(headlessCheckout.form.getStatus()).toEqual(FormStatus.pending); + + await formInitPromise.then(); + + expect(headlessCheckout.form.getStatus()).toEqual(FormStatus.active); + }); }); diff --git a/src/features/headless-checkout/headless-checkout.ts b/src/features/headless-checkout/headless-checkout.ts index 3787733..c22ba90 100644 --- a/src/features/headless-checkout/headless-checkout.ts +++ b/src/features/headless-checkout/headless-checkout.ts @@ -27,6 +27,7 @@ import { getPaymentStatusHandler } from './post-messages-handlers/get-payment-st import { headlessCheckoutAppUrl } from './environment'; import { FinanceDetails } from '../../core/finance-details/finance-details.interface'; import { getFinanceDetailsHandler } from './post-messages-handlers/get-finance-details.handler'; +import { FormStatus } from '../../core/status/form-status.enum'; @singleton() export class HeadlessCheckout { @@ -64,6 +65,8 @@ export class HeadlessCheckout { * @returns {Form} form details */ init: async (configuration: FormConfiguration): Promise