CargoLabs Docs

Testing

Exercise the whole flow without charging anyone.

Use a test key

Every pk_test_ key opens the flow in test mode. The modal shows a Test mode badge and every purchase reports testMode: true in the onComplete sale. Payments go to Stripe test mode, so use Stripe's test cards:

Card numberResult
4242 4242 4242 4242Succeeds
4000 0000 0000 9995Declined, insufficient funds
4000 0025 0000 3155Requires 3-D Secure authentication

Any future expiry date and any three-digit CVC work.

Checklist

  • The button renders (or your own button is wired) on every page that should sell insurance.
  • Clicking it opens the modal and the Test mode badge is visible.
  • onComplete fires after a test purchase and your backend records the purchaseId.
  • onClose fires when the buyer dismisses the modal, and your UI recovers.
  • Nothing in your onComplete handler treats a testMode: true sale as revenue.
  • The modal works on a phone-sized viewport.
  • Your Content Security Policy allows https://buy.coverport.io in frame-src and, if you use the script tag, https://unpkg.com in script-src.

Automated tests

The SDK exports plain functions, so unit tests can mock the DOM:

import { mount } from '@coverport/js';

test('mount renders a button into an empty target', () => {
  document.body.innerHTML = '<div id="t"></div>';
  const handle = mount('#t', { key: 'pk_test_abc' });
  expect(document.querySelector('#t button')?.textContent).toBe('Get insurance quote');
  handle.destroy();
  expect(document.querySelector('#t button')).toBeNull();
});

For end-to-end tests, drive the iframe like any other cross-origin frame. In Playwright, page.frameLocator('iframe[title="CoverPort insurance quote"]') reaches the flow.

Going live

Swap the key. Then make one real purchase of your cheapest product and refund it from the CoverPort seller console, so you have seen the live path end to end.

On this page