-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the discount controller to use the new API
- Loading branch information
1 parent
162b93d
commit de9456c
Showing
6 changed files
with
97 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Happypixels\Shopr\Exceptions; | ||
|
||
use Exception; | ||
|
||
class DiscountValidationException extends Exception | ||
{ | ||
/** | ||
* The message of the exception. | ||
* | ||
* @var string | ||
*/ | ||
protected $message; | ||
|
||
/** | ||
* The status code of the exception. | ||
* | ||
* @var int | ||
*/ | ||
protected $code = 422; | ||
|
||
/** | ||
* Create an instance of the exception. | ||
* | ||
* @param string $message | ||
*/ | ||
public function __construct($message) | ||
{ | ||
$this->message = $message; | ||
} | ||
|
||
/** | ||
* Render the exception into an HTTP response. | ||
* | ||
* @param \Illuminate\Http\Request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function render($request) | ||
{ | ||
return response()->json(['message' => $this->message], $this->code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Happypixels\Shopr\Tests\Http\Discounts; | ||
|
||
use Happypixels\Shopr\Facades\Cart; | ||
use Happypixels\Shopr\Tests\TestCase; | ||
use Happypixels\Shopr\Models\DiscountCoupon; | ||
use Happypixels\Shopr\Tests\Support\Traits\InteractsWithCart; | ||
|
||
class AddDiscountHttpTest extends TestCase | ||
{ | ||
use InteractsWithCart; | ||
|
||
/** @test */ | ||
public function it_adds_the_coupon() | ||
{ | ||
$this->withoutExceptionHandling(); | ||
|
||
$discount = factory(DiscountCoupon::class)->create(); | ||
|
||
Cart::shouldReceive('addDiscount')->once()->with($discount->code); | ||
Cart::shouldReceive('get')->once()->andReturn(['result']); | ||
|
||
$this->json('POST', 'api/shopr/cart/discounts', ['code' => $discount->code]) | ||
->assertStatus(200) | ||
->assertJson(['result']); | ||
} | ||
|
||
/** @test */ | ||
public function it_validates_the_code() | ||
{ | ||
$this->json('POST', 'api/shopr/cart/discounts', ['code' => ''])->assertStatus(422); | ||
} | ||
|
||
/** @test */ | ||
public function it_validates_configurated_rules() | ||
{ | ||
$discount = factory(DiscountCoupon::class)->create(); | ||
|
||
$this->json('POST', 'api/shopr/cart/discounts', ['code' => $discount->code]) | ||
->assertStatus(422) | ||
->assertJsonFragment(['message' => trans('shopr::cart.cart_is_empty')]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.