createOffer = async (page, {name, tierName, offerType, amount, discountType = null, discountDuration = 3}) => {
    let offerName;
    let offerLink;
    await test.step('Create an offer', async () => {
        await page.goto('/ghost');
        await page.locator('[data-test-nav="settings"]').click();

        // Keep offer names unique & <= 40 characters
        offerName = `${name} (${new ObjectID().toHexString().slice(0, 40 - name.length - 3)})`;
        // Tiers request can take time, so waiting until there is no connections before interacting with them
        await page.waitForLoadState('networkidle');
        // ... and even so, the component updates can take a bit to trickle down, so we should verify that the Tier is fully loaded before proceeding
        await page.getByTestId('tiers').getByText('No active tiers found').waitFor({state: 'hidden'});
        await page.getByTestId('offers').getByRole('button', {name: 'Manage tiers'}).waitFor({state: 'hidden'});

        // only one of these buttons is ever available - either 'Add offer' or 'Manage offers'
        const hasExistingOffers = await page.getByTestId('offers').getByRole('button', {name: 'Manage offers'}).isVisible();
        const isCTA = await page.getByTestId('offers').getByRole('button', {name: 'Add offer'}).isVisible();

        // Archive other offers to keep the list tidy
        // We only need 1 offer to be active at a time
        // Either the list of active offers loads, or the CTA when no offers exist
        if (hasExistingOffers && !isCTA) {
            await page.getByTestId('offers').getByRole('button', {name: 'Manage offers'}).click();

            // Selector for the elements with data-testid 'offer-item'
            // const offerItemsSelector = '[data-testid="offer-item"]';
            await page.getByTestId('offer-item').nth(0).click();
            await page.getByRole('button', {name: 'Archive offer'}).click();

            const confirmModal = await page.getByTestId('confirmation-modal');
            await confirmModal.getByRole('button', {name: 'Archive'}).click();
        }

        if (isCTA) {
            await page.getByTestId('offers').getByRole('button', {name: 'Add offer'}).click();
        } else {
            // ensure the modal is open
            if (!page.getByTestId('offers-modal').isVisible()) {
                await page.getByTestId('offers').getByRole('button', {name: 'Manage offers'}).click();
            }
            await page.getByText('New offer').click();
        }

        await page.getByLabel('Offer name').fill(offerName);

        if (offerType === 'freeTrial') {
            // await page.getByRole('button', {name: 'Free trial Give free access for a limited time.'}).click();
            await page.getByText('Give free access for a limited time').click();
            await page.getByLabel('Trial duration').fill(`${amount}`);
        } else if (offerType === 'discount') {
            await page.getByLabel('Amount off').fill(`${amount}`);
            if (discountType === 'multiple-months') {
                await chooseOptionInSelect(page.getByTestId('duration-select-offers'), `Multiple-months`);
                await page.getByLabel('Duration in months').fill(discountDuration.toString());
                // await page.locator('[data-test-select="offer-duration"]').selectOption('repeating');
                // await page.locator('input#duration-months').fill(discountDuration.toString());
            }

            if (discountType === 'forever') {
                await chooseOptionInSelect(page.getByTestId('duration-select-offers'), `Forever`);
            }
        }

        await chooseOptionInSelect(page.getByTestId('tier-cadence-select-offers'), `${tierName} - Monthly`);
        await page.getByRole('button', {name: 'Publish'}).click();
        await page.waitForLoadState('networkidle');

        const offerLinkInput = await page.locator('input[name="offer-url"]');
        // sometimes offer link is not generated, and if so the rest of the test will fail
        await expect(offerLinkInput).not.toBeEmpty();
        offerLink = await offerLinkInput.inputValue();
    });

    return {offerName, offerLink};
}
Create an offer on a tier
@param {import('@playwright/test').Page} page
@param {object} options
@param {string} options.name
@param {string} options.tierName
@param {string} options.offerType
@param {string} [options.discountType]
@param {number} [options.discountDuration]
@param {number} options.amount
@returns {Promise<object>} Unique offer name