Skip to content

[Create Automated Test] Workspaces - RBR: subscription error #69918

Closed

Description

@clarajones-expensify

This issue is to track the creation of automated tests to ensure that all Red Brick Road and Green Brick Road flows are working as expected. This issue covers one specific instance of where the Brick Road shows up and the criteria for it doing so.

Section: Workspaces
Type: RBR
Criteria for showing the brick road: Subscription error - bunch of reasons for this
Intentional?:
What the green/red dot links to:

Project Tracker: #66716

Activity

  1. melvin-bot commented on Sep 4, 2025

    @melvin-bot

    Auto-assigning issues to engineers is no longer supported. If you think this issue should receive engineering attention, please raise it in #whatsnext.

  2. changed the title [-][Create Automated Test] Workspaces - RBR: subscription error bunch reasons[/-] [+][Create Automated Test] Workspaces - RBR: subscription error[/+] on Sep 8, 2025
  3. added
    Internal
    Hot Pick
    on Sep 8, 2025
  4. melvin-bot commented on Sep 29, 2025

    @melvin-bot

    This issue has not been updated in over 15 days. eroding to Monthly issue.

    P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

  5. self-assigned this
    on Oct 15, 2025
  6. removed
    Hot Pick
    on Oct 15, 2025
  7. jnowakow commented on Oct 15, 2025

    @jnowakow
    Contributor

    I can't see any subscription information in Workspace section. Mentioned code leads to Subscription page on Profile. It's only used to display SubscriptionBillingBanner that in turn displays GBR or RBR:

    if (billingStatus) {
    BillingBanner = (
    <SubscriptionBillingBanner
    title={billingStatus.title}
    subtitle={billingStatus.subtitle}
    isError={billingStatus.isError}
    icon={billingStatus.icon}
    rightIcon={billingStatus.rightIcon}
    onRightIconPress={handleBillingBannerClose}
    rightIconAccessibilityLabel={translate('common.close')}
    />
    );
    }

    The logic is quite well tested:

    describe('CardSectionUtils', () => {
    afterEach(() => {
    jest.restoreAllMocks();
    });
    beforeAll(() => {
    mockGetSubscriptionStatus.mockReturnValue('');
    jest.useFakeTimers();
    // Month is zero indexed, so this is July 5th 2024
    jest.setSystemTime(new Date(2024, 6, 5));
    });
    afterAll(() => {
    jest.useRealTimers();
    });
    it('should return undefined by default', () => {
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toBeUndefined();
    });
    it('should return POLICY_OWNER_WITH_AMOUNT_OWED variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.policyOwnerAmountOwed.title',
    subtitle: 'subscription.billingBanner.policyOwnerAmountOwed.subtitle',
    isError: true,
    isRetryAvailable: true,
    });
    });
    it('should return POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE variant with isRetryAvailable true when accountData is provided', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE,
    });
    const mockPurchase = {
    message: {
    billingType: 'failed_2018',
    billableAmount: 1000,
    },
    currency: 'USD',
    created: '2023-01-01',
    amount: 1000,
    purchaseID: 12345,
    } as Purchase;
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA, purchase: mockPurchase})).toEqual({
    title: 'subscription.billingBanner.policyOwnerAmountOwedOverdue.title',
    subtitle: 'subscription.billingBanner.policyOwnerAmountOwedOverdue.subtitle',
    isError: true,
    isRetryAvailable: true,
    });
    });
    it('should return POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE variant with isRetryAvailable undefined when accountData is null', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: undefined})).toEqual({
    title: 'subscription.billingBanner.policyOwnerAmountOwedOverdue.title',
    subtitle: 'subscription.billingBanner.policyOwnerAmountOwedOverdue.subtitle',
    isError: true,
    isRetryAvailable: undefined,
    });
    });
    it('should return OWNER_OF_POLICY_UNDER_INVOICING variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.policyOwnerUnderInvoicing.title',
    subtitle: 'subscription.billingBanner.policyOwnerUnderInvoicing.subtitle',
    isError: true,
    isAddButtonDark: true,
    });
    });
    it('should return OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.policyOwnerUnderInvoicingOverdue.title',
    subtitle: 'subscription.billingBanner.policyOwnerUnderInvoicingOverdue.subtitle',
    isError: true,
    isAddButtonDark: true,
    });
    });
    it('should return BILLING_DISPUTE_PENDING variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.BILLING_DISPUTE_PENDING,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.billingDisputePending.title',
    subtitle: 'subscription.billingBanner.billingDisputePending.subtitle',
    isError: true,
    isRetryAvailable: false,
    });
    });
    it('should return CARD_AUTHENTICATION_REQUIRED variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.CARD_AUTHENTICATION_REQUIRED,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.cardAuthenticationRequired.title',
    subtitle: 'subscription.billingBanner.cardAuthenticationRequired.subtitle',
    isError: true,
    isAuthenticationRequired: true,
    });
    });
    it('should return INSUFFICIENT_FUNDS variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.INSUFFICIENT_FUNDS,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.insufficientFunds.title',
    subtitle: 'subscription.billingBanner.insufficientFunds.subtitle',
    isError: true,
    isRetryAvailable: true,
    });
    });
    it('should return CARD_EXPIRED variant with correct isRetryAvailableStatus for expired and unexpired card', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.CARD_EXPIRED,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: {...ACCOUNT_DATA, cardYear: 2023}})).toEqual({
    title: 'subscription.billingBanner.cardExpired.title',
    subtitle: 'subscription.billingBanner.cardExpired.subtitle',
    isError: true,
    isRetryAvailable: false,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.cardExpired.title',
    subtitle: 'subscription.billingBanner.cardExpired.subtitle',
    isError: true,
    isRetryAvailable: true,
    });
    });
    it('should return CARD_EXPIRE_SOON variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.CARD_EXPIRE_SOON,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.cardExpireSoon.title',
    subtitle: 'subscription.billingBanner.cardExpireSoon.subtitle',
    isError: false,
    icon: Illustrations.CreditCardEyes,
    });
    });
    it('should return RETRY_BILLING_SUCCESS variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.RETRY_BILLING_SUCCESS,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.retryBillingSuccess.title',
    subtitle: 'subscription.billingBanner.retryBillingSuccess.subtitle',
    isError: false,
    rightIcon: Expensicons.Close,
    });
    });
    it('should return RETRY_BILLING_ERROR variant', () => {
    mockGetSubscriptionStatus.mockReturnValue({
    status: PAYMENT_STATUS.RETRY_BILLING_ERROR,
    });
    expect(CardSectionUtils.getBillingStatus({translate: translateMock, stripeCustomerId, accountData: ACCOUNT_DATA})).toEqual({
    title: 'subscription.billingBanner.retryBillingError.title',
    subtitle: 'subscription.billingBanner.retryBillingError.subtitle',
    isError: true,
    isRetryAvailable: false,
    });
    });
    });

    describe('getSubscriptionStatus', () => {
    afterEach(async () => {
    await Onyx.clear();
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: null,
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: null,
    [ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING]: null,
    [ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID]: null,
    [ONYXKEYS.NVP_PRIVATE_BILLING_STATUS]: null,
    [ONYXKEYS.FUND_LIST]: null,
    [ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL]: null,
    [ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_FAILED]: null,
    });
    });
    it('should return undefined by default', () => {
    const stripeCustomerIdForDefault: Partial<OnyxEntry<StripeCustomerID>> = {};
    // @ts-expect-error - This is a test case
    expect(getSubscriptionStatus(stripeCustomerIdForDefault)).toBeUndefined();
    });
    it('should return POLICY_OWNER_WITH_AMOUNT_OWED status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: GRACE_PERIOD_DATE,
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: AMOUNT_OWED,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED,
    isError: true,
    });
    });
    it('should return POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: GRACE_PERIOD_DATE_OVERDUE,
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: AMOUNT_OWED,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.POLICY_OWNER_WITH_AMOUNT_OWED_OVERDUE,
    isError: true,
    });
    });
    it('should return OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: GRACE_PERIOD_DATE_OVERDUE,
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING_OVERDUE,
    isError: true,
    });
    });
    it('should return OWNER_OF_POLICY_UNDER_INVOICING status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: GRACE_PERIOD_DATE,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.OWNER_OF_POLICY_UNDER_INVOICING,
    isError: true,
    });
    });
    it('should return BILLING_DISPUTE_PENDING status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END]: 0,
    [ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING]: 1,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.BILLING_DISPUTE_PENDING,
    isError: true,
    });
    });
    it('should return CARD_AUTHENTICATION_REQUIRED status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0,
    [ONYXKEYS.NVP_PRIVATE_BILLING_DISPUTE_PENDING]: 0,
    [ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID]: STRIPE_CUSTOMER_ID,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.CARD_AUTHENTICATION_REQUIRED,
    isError: true,
    });
    });
    it('should return INSUFFICIENT_FUNDS status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: AMOUNT_OWED,
    [ONYXKEYS.NVP_PRIVATE_STRIPE_CUSTOMER_ID]: {},
    [ONYXKEYS.NVP_PRIVATE_BILLING_STATUS]: BILLING_STATUS_INSUFFICIENT_FUNDS,
    });
    expect(getSubscriptionStatus(stripeCustomerId)).toEqual({
    status: PAYMENT_STATUS.INSUFFICIENT_FUNDS,
    isError: true,
    });
    });
    it('should return CARD_EXPIRED status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_BILLING_STATUS]: BILLING_STATUS_EXPIRED_CARD,
    });
    const stripeCustomerIdForCardExpired: Partial<OnyxEntry<StripeCustomerID>> = {
    paymentMethodID: '1',
    intentsID: '2',
    currency: 'USD',
    };
    // @ts-expect-error - This is a test case
    expect(getSubscriptionStatus(stripeCustomerIdForCardExpired)).toEqual({
    status: PAYMENT_STATUS.CARD_EXPIRED,
    isError: true,
    });
    });
    it('should return CARD_EXPIRE_SOON status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED]: 0,
    [ONYXKEYS.NVP_PRIVATE_BILLING_STATUS]: {},
    [ONYXKEYS.FUND_LIST]: FUND_LIST,
    });
    const stripeCustomerIdForCardExpireSoon: Partial<OnyxEntry<StripeCustomerID>> = {
    paymentMethodID: '1',
    intentsID: '2',
    currency: 'USD',
    };
    // @ts-expect-error - This is a test case
    expect(getSubscriptionStatus(stripeCustomerIdForCardExpireSoon)).toEqual({
    status: PAYMENT_STATUS.CARD_EXPIRE_SOON,
    });
    });
    it('should return RETRY_BILLING_SUCCESS status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.FUND_LIST]: {},
    [ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL]: true,
    });
    const stripeCustomerIdForRetryBillingSuccess: Partial<OnyxEntry<StripeCustomerID>> = {
    paymentMethodID: '1',
    intentsID: '2',
    currency: 'USD',
    };
    // @ts-expect-error - This is a test case
    expect(getSubscriptionStatus(stripeCustomerIdForRetryBillingSuccess)).toEqual({
    status: PAYMENT_STATUS.RETRY_BILLING_SUCCESS,
    isError: false,
    });
    });
    it('should return RETRY_BILLING_ERROR status', async () => {
    await Onyx.multiSet({
    [ONYXKEYS.FUND_LIST]: {},
    [ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL]: false,
    [ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_FAILED]: true,
    });
    const stripeCustomerIdForRetryBillingError: Partial<OnyxEntry<StripeCustomerID>> = {
    paymentMethodID: '1',
    intentsID: '2',
    currency: 'USD',
    };
    // @ts-expect-error - This is a test case
    expect(getSubscriptionStatus(stripeCustomerIdForRetryBillingError)).toEqual({
    status: PAYMENT_STATUS.RETRY_BILLING_ERROR,
    isError: true,
    });
    });
    });

    So I don't think there's anything more to do here

  8. jnowakow commented on Oct 15, 2025

    @jnowakow
    Contributor
  9. jnowakow commented on Oct 20, 2025

    @jnowakow
    Contributor

    Here are all NVPs that are used to check if RBR should be shown on CardSection:

    • NVP_PRIVATE_AMOUNT_OWED
    • NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END
    • NVP_PRIVATE_BILLING_DISPUTE_PENDING
    • NVP_PRIVATE_BILLING_STATUS

    They are all returned by OpenSubscriptionPage command. It's quite simple and tests are present

    • SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL
    • SUBSCRIPTION_RETRY_BILLING_STATUS_FAILED

    SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL and SUBSCRIPTION_RETRY_BILLING_STATUS_FAILED onyx keys are only set in App:

    function clearOutstandingBalance() {
    const onyxData: OnyxData = {
    optimisticData: [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_PENDING,
    value: true,
    },
    ],
    successData: [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_PENDING,
    value: false,
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL,
    value: true,
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_FAILED,
    value: false,
    },
    ],
    failureData: [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_PENDING,
    value: false,
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_SUCCESSFUL,
    value: false,
    },
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.SUBSCRIPTION_RETRY_BILLING_STATUS_FAILED,
    value: true,
    },
    ],
    };
    API.write(WRITE_COMMANDS.CLEAR_OUTSTANDING_BALANCE, null, onyxData);
    }

  10. mountiny commented on Oct 20, 2025

    @mountiny
    Contributor

    Ok I think that should be ok as the NVPs have automated test for sending onyx update when the value changes

  11. added
    Weekly
    Awaiting Payment
    and removed on Oct 20, 2025
  12. mountiny commented on Oct 20, 2025

    @mountiny
    Contributor

    Actually we will need to pay @situchan

  13. jnowakow commented on Oct 20, 2025

    @jnowakow
    Contributor

    Actually we will need to pay @situchan

    I think you mean - #69920 🤔

  14. clarajones-expensify commented on Oct 20, 2025

    @clarajones-expensify
    ContributorAuthor

    Wait so do we need to process payment for @situchan for this issue? Or only for #69920? And should it be $250? @mountiny

  15. situchan commented on Oct 21, 2025

    @situchan
    Contributor

    This can be closed. Only for #69920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentEngineeringInternalTaskWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions