From fa54013d701d6b1ef42d43878d2ce8bebf4d1936 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 13 Jan 2025 22:14:01 +0530 Subject: [PATCH] Add RRM settings validations in validateCanSubmitChanges. --- .../datastore/settings.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/assets/js/modules/reader-revenue-manager/datastore/settings.js b/assets/js/modules/reader-revenue-manager/datastore/settings.js index d105e2e3a2a..4867a5eca9f 100644 --- a/assets/js/modules/reader-revenue-manager/datastore/settings.js +++ b/assets/js/modules/reader-revenue-manager/datastore/settings.js @@ -33,6 +33,7 @@ import { createStrictSelect } from '../../../googlesitekit/data/utils'; import { isValidPublicationID, isValidOnboardingState, + isValidSnippetMode, } from '../utils/validation'; // Invariant error messages. @@ -42,6 +43,20 @@ export const INVARIANT_INVALID_PUBLICATION_ID = export const INVARIANT_INVALID_PUBLICATION_ONBOARDING_STATE = 'a valid publication onboarding state is required'; +export const INVARIANT_INVALID_SNIPPET_MODE = + 'a valid snippet mode is required'; + +export const INVARIANT_INVALID_POST_TYPES = + 'a valid post types array is required'; + +export const INVARIANT_INVALID_PRODUCT_ID = 'a valid product ID is required'; + +export const INVARIANT_INVALID_PRODUCT_IDS = + 'a valid product IDs array is required'; + +export const INVARIANT_INVALID_PAYMENT_OPTION = + 'a valid payment option is required'; + export function validateCanSubmitChanges( select ) { const strictSelect = createStrictSelect( select ); // Strict select will cause all selector functions to throw an error @@ -52,6 +67,11 @@ export function validateCanSubmitChanges( select ) { isDoingSubmitChanges, getPublicationID, getPublicationOnboardingState, + getSnippetMode, + getPostTypes, + getProductID, + getProductIDs, + getPaymentOption, } = strictSelect( MODULES_READER_REVENUE_MANAGER ); invariant( ! isDoingSubmitChanges(), INVARIANT_DOING_SUBMIT_CHANGES ); @@ -59,6 +79,12 @@ export function validateCanSubmitChanges( select ) { const publicationID = getPublicationID(); const onboardingState = getPublicationOnboardingState(); + const snippetMode = getSnippetMode(); + const postTypes = getPostTypes(); + const productID = getProductID(); + const productIDs = getProductIDs(); + const paymentOption = getPaymentOption(); + invariant( isValidPublicationID( publicationID ), INVARIANT_INVALID_PUBLICATION_ID @@ -68,4 +94,30 @@ export function validateCanSubmitChanges( select ) { isValidOnboardingState( onboardingState ), INVARIANT_INVALID_PUBLICATION_ONBOARDING_STATE ); + + invariant( + isValidSnippetMode( snippetMode ), + INVARIANT_INVALID_SNIPPET_MODE + ); + + invariant( + Array.isArray( postTypes ) && + postTypes.every( ( item ) => typeof item === 'string' ), + INVARIANT_INVALID_POST_TYPES + ); + + invariant( typeof productID === 'string', INVARIANT_INVALID_PRODUCT_ID ); + + invariant( + Array.isArray( productIDs ) && + productIDs.every( ( item ) => typeof item === 'string' ), + INVARIANT_INVALID_PRODUCT_IDS + ); + + invariant( + typeof paymentOption === 'string', + INVARIANT_INVALID_PAYMENT_OPTION + ); + + return true; }