Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/362284 )

Change subject: Add tests around payments-antifraud messages
......................................................................

Add tests around payments-antifraud messages

Change-Id: I3df20685d7940d6379b8cedd7f0a0d285bbc7cd9
---
M gateway_common/gateway.adapter.php
M tests/phpunit/Adapter/AstroPay/AstroPayTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
M tests/phpunit/FraudFiltersTest.php
4 files changed, 94 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/84/362284/1

diff --git a/gateway_common/gateway.adapter.php 
b/gateway_common/gateway.adapter.php
index be079a7..2752870 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -1837,7 +1837,7 @@
        }
 
        public function addStandardMessageFields( $transaction ) {
-               //bascially, add all the stuff we have come to take for 
granted, because syslog.
+               // basically, add all the stuff we have come to take for 
granted, because syslog.
                $transaction['gateway_txn_id'] = 
$this->getTransactionGatewayTxnId();
                $transaction['date'] = UtcDate::getUtcTimestamp();
                $transaction['server'] = gethostname();
@@ -1846,6 +1846,7 @@
                        'gateway',
                        'contribution_tracking_id',
                        'order_id',
+                       'payment_method',
                );
                foreach ( $these_too as $field ) {
                        $transaction[$field] = $this->getData_Unstaged_Escaped( 
$field );
@@ -2089,7 +2090,6 @@
                //for now, though, just taking the ones that make it to the 
logs.
                $keys = array(
                        'payment_submethod',
-                       'payment_method',
                        'country',
                        'amount',
                        'currency',
diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php 
b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
index 5b6643a..bf16954 100644
--- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
+++ b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
@@ -17,6 +17,9 @@
  */
 
 use \Psr\Log\LogLevel;
+use SmashPig\Core\Configuration;
+use SmashPig\Core\Context;
+use SmashPig\CrmLink\Messages\SourceFields;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -42,6 +45,8 @@
                $this->setMwGlobals( array(
                        'wgAstroPayGatewayEnabled' => true,
                ) );
+               $config = Configuration::createForView( 'astropay' );
+               Context::initWithLogger( $config );
        }
 
        /**
@@ -463,6 +468,29 @@
                $this->assertEquals( 'challenge', 
$gateway->getValidationAction(), 'Validation action is not as expected' );
                $exposed = TestingAccessWrapper::newFromObject( $gateway );
                $this->assertEquals( 60, $exposed->risk_score, 'RiskScore is 
not as expected' );
+               $message = DonationQueue::instance()->pop( 'payments-antifraud' 
);
+               SourceFields::removeFromMessage( $message );
+               $expected = array(
+                       'validation_action' => 'challenge',
+                       'risk_score' => 60,
+                       'score_breakdown' => array(
+                               'initial' => 0,
+                               'getScoreUtmCampaignMap' => 0,
+                               'getScoreCountryMap' => 0,
+                               'getScoreUtmSourceMap' => 10.5,
+                               'getScoreUtmMediumMap' => 12,
+                               'getScoreEmailDomainMap' => 37.5,
+                       ),
+                       'user_ip' => '127.0.0.1',
+                       'gateway_txn_id' => false,
+                       'date' => $message['date'],
+                       'server' => gethostname(),
+                       'gateway' => 'astropay',
+                       'contribution_tracking_id' => 
$gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ),
+                       'order_id' => $gateway->getData_Unstaged_Escaped( 
'order_id' ),
+                       'payment_method' => 'cc',
+               );
+               $this->assertEquals( $expected, $message );
        }
 
        function testStageFiscalNumber() {
diff --git 
a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
index 9560034..3e2ed75 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
@@ -17,6 +17,9 @@
  */
 
 use Psr\Log\LogLevel;
+use SmashPig\Core\Configuration;
+use SmashPig\Core\Context;
+use SmashPig\CrmLink\Messages\SourceFields;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -29,6 +32,9 @@
 class DonationInterface_Adapter_GlobalCollect_Orphans_GlobalCollectTest 
extends DonationInterfaceTestCase {
        public function setUp() {
                parent::setUp();
+
+               $config = Configuration::createForView( 'globalcollect' );
+               Context::initWithLogger( $config );
 
                $this->setMwGlobals( array(
                        'wgGlobalCollectGatewayEnabled' => true,
@@ -177,5 +183,26 @@
                $exposed = TestingAccessWrapper::newFromObject( $gateway );
                $this->assertEquals( 40, $exposed->risk_score,
                        'Risk score was incremented correctly.' );
+               $message = DonationQueue::instance()->pop( 'payments-antifraud' 
);
+               SourceFields::removeFromMessage( $message );
+               $expected = array(
+                       'validation_action' => 'review',
+                       'risk_score' => 40,
+                       'score_breakdown' => array(
+                               // FIXME: need to enable utm / email / country 
checks ???
+                               'initial' => 0,
+                               'getCVVResult' => 10,
+                               'getAVSResult' => 30,
+                       ),
+                       'user_ip' => null, // FIXME
+                       'gateway_txn_id' => '55555',
+                       'date' => $message['date'],
+                       'server' => gethostname(),
+                       'gateway' => 'globalcollect',
+                       'contribution_tracking_id' => 
$gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ),
+                       'order_id' => $gateway->getData_Unstaged_Escaped( 
'order_id' ),
+                       'payment_method' => 'cc',
+               );
+               $this->assertEquals( $expected, $message );
        }
 }
diff --git a/tests/phpunit/FraudFiltersTest.php 
b/tests/phpunit/FraudFiltersTest.php
index b8726c7..d119b56 100644
--- a/tests/phpunit/FraudFiltersTest.php
+++ b/tests/phpunit/FraudFiltersTest.php
@@ -16,6 +16,9 @@
  *
  */
 
+use SmashPig\Core\Configuration;
+use SmashPig\Core\Context;
+use SmashPig\CrmLink\Messages\SourceFields;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -97,15 +100,21 @@
                ) );
        }
 
+       public function setUp() {
+               parent::setUp();
+               $config = Configuration::createForView( 'globalcollect' );
+               Context::initWithLogger( $config );
+       }
+
        function testGCFraudFilters() {
                $this->setMwGlobals( array(
-                       'wgGlobalCollectGatewayEnableMinfraud' => true,
+                       'wgDonationInterfaceEnableMinfraud' => true,
                        'wgDonationInterfaceMinFraudServers' => 
array('0.0.0.0'),
                ) );
 
                $options = $this->getDonorTestData();
                $options['email'] = 'someb...@wikipedia.org';
-               $class = $this->testAdapterClass;
+               $options['payment_method'] = 'cc';
 
                $gateway = $this->getFreshGatewayObject( $options );
 
@@ -114,6 +123,32 @@
                $this->assertEquals( 'reject', $gateway->getValidationAction(), 
'Validation action is not as expected' );
                $exposed = TestingAccessWrapper::newFromObject( $gateway );
                $this->assertEquals( 107.5, $exposed->risk_score, 'RiskScore is 
not as expected for failure mode' );
+               $message = DonationQueue::instance()->pop( 'payments-antifraud' 
);
+               SourceFields::removeFromMessage( $message );
+               $expected = array(
+                       'validation_action' => 'reject',
+                       'risk_score' => 107.5,
+                       'score_breakdown' => array(
+                               'initial' => 0,
+                               'getScoreUtmCampaignMap' => 0,
+                               'getScoreCountryMap' => 20,
+                               'getScoreUtmSourceMap' => 0,
+                               'getScoreUtmMediumMap' => 0,
+                               'getScoreEmailDomainMap' => 37.5,
+                               'getCVVResult' => 0,
+                               'getAVSResult' => 0,
+                               'minfraud_filter' => 50,
+                       ),
+                       'user_ip' => '127.0.0.1',
+                       'gateway_txn_id' => false,
+                       'date' => $message['date'],
+                       'server' => gethostname(),
+                       'gateway' => 'globalcollect',
+                       'contribution_tracking_id' => 
$gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ),
+                       'order_id' => $gateway->getData_Unstaged_Escaped( 
'order_id' ),
+                       'payment_method' => 'cc',
+               );
+               $this->assertEquals( $expected, $message );
        }
 }
 // Stub out Minfraud class for CI tests

-- 
To view, visit https://gerrit.wikimedia.org/r/362284
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3df20685d7940d6379b8cedd7f0a0d285bbc7cd9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to