|
| 1 | +import { paypalSubscriptionButtonAllowed } from './Subscription'; |
| 2 | + |
| 3 | +const baseData = ( overrides = {} ) => ( { |
| 4 | + locations_with_subscription_product: { cart: true }, |
| 5 | + user: { is_logged: true }, |
| 6 | + context: 'cart', |
| 7 | + is_free_trial_cart: false, |
| 8 | + can_save_vault_token: false, |
| 9 | + subscription_product_allowed: false, |
| 10 | + data_client_id: { |
| 11 | + has_subscriptions: false, |
| 12 | + paypal_subscriptions_enabled: false, |
| 13 | + }, |
| 14 | + ...overrides, |
| 15 | +} ); |
| 16 | + |
| 17 | +describe( 'paypalSubscriptionButtonAllowed', () => { |
| 18 | + it( 'allows a cart without subscription products', () => { |
| 19 | + const data = baseData( { |
| 20 | + locations_with_subscription_product: { cart: false }, |
| 21 | + } ); |
| 22 | + expect( paypalSubscriptionButtonAllowed( data ) ).toBe( true ); |
| 23 | + } ); |
| 24 | + |
| 25 | + it( 'hides for a guest with a free trial on the block cart', () => { |
| 26 | + const data = baseData( { |
| 27 | + user: { is_logged: false }, |
| 28 | + context: 'cart-block', |
| 29 | + is_free_trial_cart: true, |
| 30 | + subscription_button_allowed: true, |
| 31 | + } ); |
| 32 | + expect( paypalSubscriptionButtonAllowed( data ) ).toBe( false ); |
| 33 | + } ); |
| 34 | + |
| 35 | + it( 'prefers the server subscription_button_allowed flag when present', () => { |
| 36 | + expect( |
| 37 | + paypalSubscriptionButtonAllowed( |
| 38 | + baseData( { subscription_button_allowed: false } ) |
| 39 | + ) |
| 40 | + ).toBe( false ); |
| 41 | + expect( |
| 42 | + paypalSubscriptionButtonAllowed( |
| 43 | + baseData( { subscription_button_allowed: true } ) |
| 44 | + ) |
| 45 | + ).toBe( true ); |
| 46 | + } ); |
| 47 | + |
| 48 | + it( 'falls back to hide in vaulting mode when vaulting is disabled', () => { |
| 49 | + const data = baseData( { can_save_vault_token: false } ); |
| 50 | + expect( paypalSubscriptionButtonAllowed( data ) ).toBe( false ); |
| 51 | + } ); |
| 52 | + |
| 53 | + it( 'falls back to show in vaulting mode when vaulting is enabled', () => { |
| 54 | + const data = baseData( { can_save_vault_token: true } ); |
| 55 | + expect( paypalSubscriptionButtonAllowed( data ) ).toBe( true ); |
| 56 | + } ); |
| 57 | + |
| 58 | + it( 'falls back to hide in subscriptions mode when the product is not allowed', () => { |
| 59 | + const data = baseData( { |
| 60 | + data_client_id: { |
| 61 | + has_subscriptions: true, |
| 62 | + paypal_subscriptions_enabled: true, |
| 63 | + }, |
| 64 | + subscription_product_allowed: false, |
| 65 | + } ); |
| 66 | + expect( paypalSubscriptionButtonAllowed( data ) ).toBe( false ); |
| 67 | + } ); |
| 68 | + |
| 69 | + it( 'falls back to show in subscriptions mode when the product is allowed', () => { |
| 70 | + const data = baseData( { |
| 71 | + data_client_id: { |
| 72 | + has_subscriptions: true, |
| 73 | + paypal_subscriptions_enabled: true, |
| 74 | + }, |
| 75 | + subscription_product_allowed: true, |
| 76 | + } ); |
| 77 | + expect( paypalSubscriptionButtonAllowed( data ) ).toBe( true ); |
| 78 | + } ); |
| 79 | +} ); |
0 commit comments