Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RRM Phase 2 transition #10403

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ PublicationUnavailable.args = {

registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( publications[ 2 ] );
// eslint-disable-next-line sitekit/acronym-case
.setPublicationID( publications[ 2 ].publicationId );
},
};

Expand Down
43 changes: 20 additions & 23 deletions assets/js/modules/reader-revenue-manager/datastore/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,35 +250,32 @@ const baseActions = {
publicationID,
publicationOnboardingState: onboardingState,
publicationOnboardingStateChanged: false,
productIDs: [],
paymentOption: '',
};

if ( isFeatureEnabled( 'rrmModuleV2' ) ) {
settings.productIDs = [];
settings.paymentOption = '';
settings.productID = 'openaccess';
if ( paymentOptions ) {
const paymentOption = Object.keys( paymentOptions ).find(
( key ) => !! paymentOptions[ key ]
);

if ( paymentOptions ) {
const paymentOption = Object.keys( paymentOptions ).find(
( key ) => !! paymentOptions[ key ]
);
if ( paymentOption ) {
settings.paymentOption = paymentOption;
}
}

if ( paymentOption ) {
settings.paymentOption = paymentOption;
if ( products ) {
settings.productIDs = products.reduce( ( ids, { name } ) => {
if ( ! name ) {
return ids;
}
}

if ( products ) {
settings.productIDs = products.reduce(
( ids, { name } ) => {
if ( ! name ) {
return ids;
}

return [ ...ids, name ];
},
[]
);
}
return [ ...ids, name ];
}, [] );
}

if ( isFeatureEnabled( 'rrmModuleV2' ) ) {
settings.productID = 'openaccess';
}

return registry
Expand Down
262 changes: 131 additions & 131 deletions assets/js/modules/reader-revenue-manager/datastore/publications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,171 +325,171 @@ describe( 'modules/reader-revenue-manager publications', () => {
).toEqual( false );
} );

describe( 'with the rrmModuleV2 feature flag enabled', () => {
beforeEach( () => {
setEnabledFeatures( [ 'rrmModuleV2' ] );
} );
it( 'should set the product IDs in state when products are provided', () => {
const products = [
{ name: 'ABC:product-1' },
{ name: 'DEF:product-2' },
];
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );

it( 'should set the product IDs in state when products are provided', () => {
const products = [
{ name: 'ABC:product-1' },
{ name: 'DEF:product-2' },
];
expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getProductIDs()
).toEqual( [ 'ABC:product-1', 'DEF:product-2' ] );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getProductIDs()
).toEqual( [ 'ABC:product-1', 'DEF:product-2' ] );
} );
it( 'should set an empty product IDs array when products array is empty', () => {
const products = [];
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );

it( 'should set an empty product IDs array when products array is empty', () => {
const products = [];
expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getProductIDs()
).toEqual( [] );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getProductIDs()
).toEqual( [] );
} );
it( 'should handle products with a missing name property', () => {
const products = [
{ name: 'ABC:product-1' },
{}, // Missing name
{ name: 'DEF:product-2' },
];
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );

it( 'should set productID to "openaccess" when different publication is selected', () => {
const products = [
{ name: 'ABC:product-1' },
{ name: 'DEF:product-2' },
];
expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getProductIDs()
).toEqual( [ 'ABC:product-1', 'DEF:product-2' ] );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getProductID()
).toEqual( 'openaccess' );
} );
it( 'should set the payment option in state when a payment option is provided', () => {
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions: {
contributions: null,
subscriptions: true,
noPayment: null,
thankStickers: null,
},
} );

it( 'should handle products with a missing name property', () => {
const products = [
{ name: 'ABC:product-1' },
{}, // Missing name
{ name: 'DEF:product-2' },
];
expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
products,
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( 'subscriptions' );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getProductIDs()
).toEqual( [ 'ABC:product-1', 'DEF:product-2' ] );
} );
it( 'should set the first true payment option when multiple options are provided', () => {
const paymentOptions = {
subscriptions: null,
contributions: true,
noPayment: true,
thankStickers: null,
};
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions,
} );

it( 'should set the payment option in state when a payment option is provided', () => {
expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions: {
contributions: null,
subscriptions: true,
noPayment: null,
thankStickers: null,
},
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( 'contributions' );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( 'subscriptions' );
} );
it( 'should default to an empty string when all payment options are null', () => {
const paymentOptions = {
subscriptions: null,
contributions: null,
noPayment: null,
thankStickers: null,
};

it( 'should set the first true payment option when multiple options are provided', () => {
const paymentOptions = {
subscriptions: null,
contributions: true,
noPayment: true,
thankStickers: null,
};
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions,
} );

expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions,
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( '' );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( 'contributions' );
} );
it( 'should default to an empty string when the payment options object is empty', () => {
const paymentOptions = {};

it( 'should default to an empty string when all payment options are null', () => {
const paymentOptions = {
subscriptions: null,
contributions: null,
noPayment: null,
thankStickers: null,
};
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions,
} );

expect(
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions,
} );
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( '' );
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( '' );
describe( 'with the rrmModuleV2 feature flag enabled', () => {
beforeEach( () => {
setEnabledFeatures( [ 'rrmModuleV2' ] );
} );

it( 'should default to an empty string when the payment options object is empty', () => {
const paymentOptions = {};

it( 'should set productID to "openaccess" when different publication is selected', () => {
const products = [
{ name: 'ABC:product-1' },
{ name: 'DEF:product-2' },
];
registry
.dispatch( MODULES_READER_REVENUE_MANAGER )
.selectPublication( {
publicationId: 'publication-id',
onboardingState: 'onboarding-state',
paymentOptions,
products,
} );

expect(
registry
.select( MODULES_READER_REVENUE_MANAGER )
.getPaymentOption()
).toEqual( '' );
.getProductID()
).toEqual( 'openaccess' );
} );
} );
} );
Expand Down
Loading
Loading