From b4d9f279dc383f806c673784217c8f830d422508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Rub=C3=A9l?= Date: Tue, 9 May 2023 09:37:13 +0200 Subject: [PATCH] Add test to make sure `isAllowedToRedeemBy` check works correctly. --- tests/CouponsTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/CouponsTest.php b/tests/CouponsTest.php index f4f0d3f..3496d34 100644 --- a/tests/CouponsTest.php +++ b/tests/CouponsTest.php @@ -180,6 +180,28 @@ public function testCanVerifyCouponWhenSpecificModelAssigned() Event::assertDispatched(CouponVerified::class); } + /** @test */ + public function testVerifyCouponThrowsExceptionWhenSpecificModelAssignedAndLimitIsSet() + { + $this->expectException(NotAllowedToRedeemException::class); + + Coupon::create([ + 'code' => 'redeemer-coupon', + 'redeemer_type' => $this->user::class, + 'redeemer_id' => $this->user->id, + 'limit' => 1, + 'quantity' => 1, + ]); + + $redeemer = User::create([ + 'name' => 'Tester2', + 'email' => 'test2@example.com', + 'password' => Hash::make('pass2'), + ]); + + $redeemer->verifyCoupon('redeemer-coupon'); + } + /** @test */ public function testCanRedeemCouponWhenSpecificModelAssigned() {