Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.3 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import { onboardingCheckoutRequest, parseCheckoutReturn } from './checkout';

const ONBOARDING = 'https://macro.com/app/onboarding';

describe('onboardingCheckoutRequest', () => {
  it('returns both checkout legs to the onboarding flow with the plan', () => {
    expect(onboardingCheckoutRequest(ONBOARDING, 'premium', 'trial')).toEqual({
      successUrl: `${ONBOARDING}?subscriptionSuccess=true&type=premium`,
      cancelUrl: `${ONBOARDING}?subscriptionCancel=true`,
      plan: 'premium',
      onboardingTrial: true,
    });
  });

  it('uses standard paid terms for Max', () => {
    expect(
      onboardingCheckoutRequest(ONBOARDING, 'max', 'standard')
    ).toMatchObject({
      plan: 'max',
      onboardingTrial: false,
    });
  });

  it('requests the trial only for Pro', () => {
    const request = onboardingCheckoutRequest(ONBOARDING, 'max', 'trial');
    expect(request.plan).toBe('max');
    expect(request.onboardingTrial).toBe(false);
    expect(request.successUrl).toBe(
      `${ONBOARDING}?subscriptionSuccess=true&type=max`
    );
  });
});

describe('invite offers', () => {
  it('check out with paid terms so the server applies the invite promotion', () => {
    expect(
      onboardingCheckoutRequest(ONBOARDING, 'premium', 'invite-offer')
        .onboardingTrial
    ).toBe(false);
  });
});

describe('parseCheckoutReturn', () => {
  it.each([
    [{}, undefined],
    [{ subscriptionCancel: 'true' }, { t: 'cancelled' }],
    [{ subscriptionSuccess: 'true' }, { t: 'success', tier: 'premium' }],
    [
      { subscriptionSuccess: 'true', type: 'max' },
      { t: 'success', tier: 'max' },
    ],
    [
      { subscriptionSuccess: 'true', type: 'anything' },
      { t: 'success', tier: 'premium' },
    ],
  ])('%o → %o', (params, expected) => {
    expect(parseCheckoutReturn(params)).toEqual(expected);
  });

  it('round-trips the legs the request builds', () => {
    const request = onboardingCheckoutRequest(ONBOARDING, 'max', 'trial');
    const leg = (url: string) =>
      Object.fromEntries(new URL(url).searchParams.entries());
    expect(parseCheckoutReturn(leg(request.successUrl))).toEqual({
      t: 'success',
      tier: 'max',
    });
    expect(parseCheckoutReturn(leg(request.cancelUrl))).toEqual({
      t: 'cancelled',
    });
  });
});