Skip to content

Commit

Permalink
feat(PAYMENTS-15270): form - activate & getStatus + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinKamenskiy committed Aug 16, 2023
1 parent 23d28ef commit edf95d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/features/headless-checkout/headless-checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
});
4 changes: 3 additions & 1 deletion src/features/headless-checkout/headless-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export class HeadlessCheckout {
},

getStatus: (): FormStatus => {
if (this.formSpy.formWasInit) return FormStatus.active;
if (this.formSpy.formWasInit) {
return FormStatus.active;
}

return this.formStatus === FormStatus.pending
? FormStatus.pending
Expand Down

0 comments on commit edf95d7

Please sign in to comment.