Skip to content

Commit

Permalink
Merge pull request #123 from bc-joshroe/api-fix-1
Browse files Browse the repository at this point in the history
Adding coupon delete methods
  • Loading branch information
aleachjr committed Mar 3, 2015
2 parents 1d68679 + cf1ab88 commit 34e6ee8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,16 @@ public static function updateSku($id, $object)
return self::updateResource('/product/skus/' . $id, $object);
}

/**
* Get a single coupon by given id.
*
* @param int $id customer id
* @return Coupon
*/
public static function getCoupon($id)
{
return self::getResource('/coupon/' . $id, 'Coupon');
}

/**
* Get coupons
Expand Down Expand Up @@ -1041,6 +1051,27 @@ public static function updateCoupon($id, $object)
return self::updateResource('/coupons/' . $id, $object);
}

/**
* Delete the given coupon.
*
* @param int $id coupon id
* @return hash|bool|mixed
*/
public static function deleteCoupon($id)
{
return self::deleteResource('/coupons/' . $id);
}

/**
* Delete all Coupons.
*
* @return hash|bool|mixed
*/
public static function deleteAllCoupons()
{
return self::deleteResource('/coupons');
}

/**
* The request logs with usage history statistics.
*/
Expand Down
29 changes: 29 additions & 0 deletions test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,33 @@ public function testDeletingACustomerDeletesToTheCustomerResource()

Client::deleteCustomers();
}

public function testDeletingAllCouponDeletesToTheCouponResource()
{
$this->connection->expects($this->once())
->method('delete')
->with('/coupons');

Client::deleteAllCoupons();
}

public function testDeletingACouponDeletesToTheCouponResource()
{
$this->connection->expects($this->once())
->method('delete')
->with('/coupons/1');

Client::deleteCoupon(1);
}

public function testGettingASpecifiedCouponReturnsThatCoupon()
{
$this->connection->expects($this->once())
->method('get')
->with('/coupon/1', false)
->will($this->returnValue(array(array(), array())));

$resource = Client::getCoupon(1);
$this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Coupon', $resource);
}
}

0 comments on commit 34e6ee8

Please sign in to comment.