jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/356959 )

Change subject: Add API test for Amazon
......................................................................


Add API test for Amazon

This would have caught the SmashPig init failure

Change-Id: Id75d9f1471f092cc9cb2b81147428bee1dd28b04
---
M amazon_gateway/amazon.api.php
A tests/phpunit/Adapter/Amazon/AmazonApiTest.php
2 files changed, 60 insertions(+), 1 deletion(-)

Approvals:
  Mepps: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/amazon_gateway/amazon.api.php b/amazon_gateway/amazon.api.php
index 740b912..3b9cd54 100644
--- a/amazon_gateway/amazon.api.php
+++ b/amazon_gateway/amazon.api.php
@@ -24,7 +24,9 @@
                        ),
                );
 
-               $adapter = new AmazonAdapter( $adapterParams );
+               $adapterClass = DonationInterface::getAdapterClassForGateway( 
'amazon' );
+               // @var AmazonAdapter
+               $adapter = new $adapterClass( $adapterParams );
 
                if ( $adapter->getErrorState()->hasErrors() ) {
                        $output->addValue(
diff --git a/tests/phpunit/Adapter/Amazon/AmazonApiTest.php 
b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
new file mode 100644
index 0000000..04ca56b
--- /dev/null
+++ b/tests/phpunit/Adapter/Amazon/AmazonApiTest.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * @group Amazon
+ * @group medium
+ */
+class AmazonApiTest extends ApiTestCase {
+       public function setUp() {
+               parent::setUp();
+               TestingAmazonAdapter::$mockClient = new MockAmazonClient();
+               $this->setMwGlobals( array(
+                       'wgDonationInterfaceEnableQueue' => true,
+                       'wgDonationInterfaceDefaultQueueServer' => array(
+                               'type' => 'TestingQueue',
+                       ),
+               ) );
+       }
+
+       public function tearDown() {
+               TestingAmazonAdapter::$mockClient = null;
+               parent::tearDown();
+       }
+
+       public function testDoPaymentSuccess() {
+               $params = array(
+                       'amount' => '1.55',
+                       'currency' => 'USD',
+                       'recurring' => '0',
+                       'wmf_token' => 'e601502632e5e51dc2a17a0045162272+\\',
+                       'orderReferenceId' => mt_rand( 0, 10000000 ),
+                       'action' => 'di_amazon_bill',
+               );
+               $session = array(
+                       'Donor' => array(
+                               'amount' => '1.55',
+                               'currency' => 'USD',
+                               'recurring' => '0',
+                               'contribution_tracking_id' => mt_rand( 0, 
10000000 ),
+                               'country' => 'US',
+                       ),
+                       'amazonEditToken' => 'kjaskdjahsdkjsad',
+               );
+               $apiResult = $this->doApiRequest( $params, $session );
+               $redirect = $apiResult[0]['redirect'];
+               $this->assertEquals( 
'https://wikimediafoundation.org/wiki/Thank_You/en?country=US', $redirect );
+               $mockClient = TestingAmazonAdapter::$mockClient;
+               $setOrderReferenceDetailsArgs = 
$mockClient->calls['setOrderReferenceDetails'][0];
+               $oid = $session['Donor']['contribution_tracking_id'] . '-0';
+               $this->assertEquals( $oid, 
$setOrderReferenceDetailsArgs['seller_order_id'], 'Did not set order id on 
order reference' );
+               $this->assertEquals( $params['amount'], 
$setOrderReferenceDetailsArgs['amount'], 'Did not set amount on order 
reference' );
+
+               $this->assertEquals( $params['currency'], 
$setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on 
order reference' );
+               $message = DonationQueue::instance()->pop( 'donations' );
+               $this->assertNotNull( $message, 'Not sending a message to the 
donations queue' );
+               $this->assertEquals( 'S01-0391295-0674065-C095112', 
$message['gateway_txn_id'], 'Queue message has wrong txn ID' );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id75d9f1471f092cc9cb2b81147428bee1dd28b04
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to