Skip to content

Commit

Permalink
Fix incorrect default value for advanced options in FRT (#10394)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoumpierre authored Feb 18, 2025
1 parent e4cfa89 commit 4185c09
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 50 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-10393-frt-advanced-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix the default value of the FRT advanced options.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ exports[`Advanced fraud protection settings doesn't save when there's a validati
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -1345,7 +1345,7 @@ exports[`Advanced fraud protection settings doesn't save when there's a validati
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -2119,7 +2119,7 @@ exports[`Advanced fraud protection settings renders an error message when settin
id="a11y-speak-polite"
style="position: absolute;margin: -1px;padding: 0;height: 1px;width: 1px;overflow: hidden;clip: rect(1px, 1px, 1px, 1px);-webkit-clip-path: inset(50%);clip-path: inset(50%);border: 0;word-wrap: normal !important;"
>
For security, this filter is enabled and cannot be modified. Payments failing CVC verification will be blocked. Learn more
Orders from outside of the following countries will be blocked by the filter: Canada, United States
</div>
<div>
<div>
Expand Down Expand Up @@ -2415,7 +2415,7 @@ exports[`Advanced fraud protection settings renders an error message when settin
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -3277,7 +3277,7 @@ exports[`Advanced fraud protection settings renders an error message when settin
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -3925,7 +3925,7 @@ exports[`Advanced fraud protection settings renders correctly 1`] = `
id="a11y-speak-polite"
style="position: absolute;margin: -1px;padding: 0;height: 1px;width: 1px;overflow: hidden;clip: rect(1px, 1px, 1px, 1px);-webkit-clip-path: inset(50%);clip-path: inset(50%);border: 0;word-wrap: normal !important;"
>
For security, this filter is enabled and cannot be modified. Payments failing CVC verification will be blocked. Learn more
Orders from outside of the following countries will be blocked by the filter: Canada, United States
</div>
<div>
<div
Expand Down Expand Up @@ -4186,7 +4186,7 @@ exports[`Advanced fraud protection settings renders correctly 1`] = `
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -5012,7 +5012,7 @@ exports[`Advanced fraud protection settings renders correctly 1`] = `
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -5659,7 +5659,7 @@ exports[`Advanced fraud protection settings saves settings when there are no val
id="a11y-speak-polite"
style="position: absolute;margin: -1px;padding: 0;height: 1px;width: 1px;overflow: hidden;clip: rect(1px, 1px, 1px, 1px);-webkit-clip-path: inset(50%);clip-path: inset(50%);border: 0;word-wrap: normal !important;"
>
For security, this filter is enabled and cannot be modified. Payments failing CVC verification will be blocked. Learn more
Orders from outside of the following countries will be blocked by the filter: Canada, United States
</div>
<div>
<div>
Expand Down Expand Up @@ -5938,7 +5938,7 @@ exports[`Advanced fraud protection settings saves settings when there are no val
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down Expand Up @@ -6863,7 +6863,7 @@ exports[`Advanced fraud protection settings saves settings when there are no val
data-wp-c16t="true"
data-wp-component="FlexItem"
>
Orders from outside of the following countries will be screened by the filter:
Orders from outside of the following countries will be blocked by the filter:
<strong>
Canada, United States
</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ declare const global: {
}
>;
isMultiCurrencyEnabled: string;
isFRTReviewFeatureActive: boolean;
};
};

Expand Down Expand Up @@ -143,6 +144,7 @@ describe( 'Advanced fraud protection settings', () => {
},
},
isMultiCurrencyEnabled: '1',
isFRTReviewFeatureActive: false,
};

mockUseAdvancedFraudProtectionSettings.mockReturnValue( [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ import { CheckOperators, Checks, Outcomes, Rules } from '../constants';
import { readRuleset, writeRuleset } from '../utils';

const defaultUIConfig = {
avs_verification: {
block: false,
enabled: false,
},
address_mismatch: {
block: true,
enabled: false,
},
ip_address_mismatch: {
block: true,
enabled: false,
},
international_ip_address: {
block: true,
enabled: false,
},
order_items_threshold: {
block: true,
enabled: false,
max_items: null,
min_items: null,
},
purchase_price_threshold: {
block: true,
enabled: false,
max_amount: null,
min_amount: null,
},
};

const defaultUIConfigWithReviewEnabled = {
avs_verification: {
block: false,
enabled: false,
Expand Down Expand Up @@ -57,6 +88,7 @@ declare const global: {
precision: number;
};
};
isFRTReviewFeatureActive: boolean;
};
wcSettings: {
admin: {
Expand Down Expand Up @@ -88,15 +120,42 @@ describe( 'Ruleset adapter utilities test', () => {
precision: 2,
},
},
isFRTReviewFeatureActive: false,
};
} );

test( 'converts an empty ruleset to default UI config', () => {
test( 'converts an empty ruleset to default UI config with isFRTReviewFeatureActive disabled', () => {
const ruleset: FraudProtectionRule[] = [];
const expected = defaultUIConfig;
const output = readRuleset( ruleset );
expect( output ).toEqual( expected );
} );

test( 'converts an empty ruleset to default UI config with isFRTReviewFeatureActive enabled', () => {
global.wcpaySettings = {
storeCurrency: 'USD',
connect: {
country: 'US',
},
currencyData: {
US: {
code: 'USD',
symbol: '$',
symbolPosition: 'left',
thousandSeparator: ',',
decimalSeparator: '.',
precision: 2,
},
},
isFRTReviewFeatureActive: true,
};

const ruleset: FraudProtectionRule[] = [];
const expected = defaultUIConfigWithReviewEnabled;
const output = readRuleset( ruleset );
expect( output ).toEqual( expected );
} );

test( 'converts an address mismatch ruleset to matching UI config', () => {
const ruleset = [
{
Expand All @@ -111,7 +170,7 @@ describe( 'Ruleset adapter utilities test', () => {
];
const expected = Object.assign( {}, defaultUIConfig, {
address_mismatch: {
block: false,
block: true,
enabled: true,
},
} );
Expand Down Expand Up @@ -288,7 +347,7 @@ describe( 'Ruleset adapter utilities test', () => {
const expected = Object.assign( {}, defaultUIConfig, {
[ Rules.RULE_PURCHASE_PRICE_THRESHOLD ]: {
enabled: true,
block: false,
block: true,
min_amount: 1,
max_amount: '',
},
Expand Down Expand Up @@ -371,7 +430,7 @@ describe( 'Ruleset adapter utilities test', () => {
const expected = Object.assign( {}, defaultUIConfig, {
[ Rules.RULE_PURCHASE_PRICE_THRESHOLD ]: {
enabled: true,
block: false,
block: true,
min_amount: 0.01,
max_amount: '',
},
Expand Down
46 changes: 27 additions & 19 deletions client/settings/fraud-protection/advanced-settings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,36 +233,44 @@ export const writeRuleset = (
return rulesetConfig.filter( ( rule ) => rule );
};

const getRuleBlockStatus = ( outcome: string ) => {
const { isFRTReviewFeatureActive } = wcpaySettings;

if ( ! isFRTReviewFeatureActive ) {
return true;
}

return outcome === Outcomes.BLOCK;
};

export const readRuleset = (
rulesetConfig: FraudProtectionRule[] | string
): ProtectionSettingsUI => {
const { isFRTReviewFeatureActive } = wcpaySettings;
const isAVSChecksEnabled =
wcpaySettings?.accountStatus?.fraudProtection?.declineOnAVSFailure ||
false;

const defaultEnableConfig = {
enabled: false,
block: ! isFRTReviewFeatureActive,
};

const defaultUIConfig = {
[ Rules.RULE_AVS_VERIFICATION ]: {
enabled: isAVSChecksEnabled,
block: isAVSChecksEnabled,
},
[ Rules.RULE_ADDRESS_MISMATCH ]: { enabled: false, block: false },
[ Rules.RULE_INTERNATIONAL_IP_ADDRESS ]: {
enabled: false,
block: false,
},
[ Rules.RULE_IP_ADDRESS_MISMATCH ]: {
enabled: false,
block: false,
},
[ Rules.RULE_ADDRESS_MISMATCH ]: { ...defaultEnableConfig },
[ Rules.RULE_INTERNATIONAL_IP_ADDRESS ]: { ...defaultEnableConfig },
[ Rules.RULE_IP_ADDRESS_MISMATCH ]: { ...defaultEnableConfig },
[ Rules.RULE_ORDER_ITEMS_THRESHOLD ]: {
enabled: false,
block: false,
...defaultEnableConfig,
min_items: null,
max_items: null,
},
[ Rules.RULE_PURCHASE_PRICE_THRESHOLD ]: {
enabled: false,
block: false,
...defaultEnableConfig,
min_amount: null,
max_amount: null,
},
Expand All @@ -277,25 +285,25 @@ export const readRuleset = (
case Rules.RULE_AVS_VERIFICATION:
parsedUIConfig[ rule.key ] = {
enabled: true,
block: rule.outcome === Outcomes.BLOCK,
block: getRuleBlockStatus( rule.outcome ),
};
break;
case Rules.RULE_ADDRESS_MISMATCH:
parsedUIConfig[ rule.key ] = {
enabled: true,
block: rule.outcome === Outcomes.BLOCK,
block: getRuleBlockStatus( rule.outcome ),
};
break;
case Rules.RULE_INTERNATIONAL_IP_ADDRESS:
parsedUIConfig[ rule.key ] = {
enabled: true,
block: rule.outcome === Outcomes.BLOCK,
block: getRuleBlockStatus( rule.outcome ),
};
break;
case Rules.RULE_IP_ADDRESS_MISMATCH:
parsedUIConfig[ rule.key ] = {
enabled: true,
block: rule.outcome === Outcomes.BLOCK,
block: getRuleBlockStatus( rule.outcome ),
};
break;
case Rules.RULE_ORDER_ITEMS_THRESHOLD:
Expand All @@ -311,7 +319,7 @@ export const readRuleset = (
) as FraudProtectionSettingsSingleCheck;
parsedUIConfig[ rule.key ] = {
enabled: true,
block: rule.outcome === Outcomes.BLOCK,
block: getRuleBlockStatus( rule.outcome ),
min_items: minItemsCheck.value ?? '',
max_items: maxItemsCheck.value ?? '',
};
Expand All @@ -329,7 +337,7 @@ export const readRuleset = (
) as FraudProtectionSettingsSingleCheck;
parsedUIConfig[ rule.key ] = {
enabled: true,
block: rule.outcome === Outcomes.BLOCK,
block: getRuleBlockStatus( rule.outcome ),
min_amount: readFormattedRulePrice(
minAmountCheck.value
),
Expand Down
16 changes: 0 additions & 16 deletions client/settings/fraud-protection/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,6 @@
&:last-child {
margin-bottom: 0;
}

input[type='radio'] {
border-color: #757575;

&:checked {
background-color: #fff;
border-color: #757575;

&::before {
border: 6px solid #3582c4;
width: 12px;
height: 12px;
transform: translate( 3px, 3px );
}
}
}
}
}
}
Expand Down

0 comments on commit 4185c09

Please sign in to comment.