Skip to content

Commit

Permalink
Fix test for Amount Off discount (#1929)
Browse files Browse the repository at this point in the history
After #1922 the discount test was failing due to what looks like an
initial false positive or incorrect test case. This PR looks to fix that
up.

---------

Co-authored-by: alecritson <[email protected]>
  • Loading branch information
alecritson and alecritson authored Sep 3, 2024
1 parent 8568009 commit 2b31dca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tests/core/Unit/DiscountTypes/BuyXGetYTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
],
]);

Discount::factory()->create([
$discountB = Discount::factory()->create([
'type' => AmountOff::class,
'name' => 'Test A amount off',
'uses' => 0,
Expand All @@ -394,6 +394,13 @@
],
]);

$discountB->customerGroups()->sync([
$customerGroup->id => [
'enabled' => false,
'starts_at' => now(),
],
]);

$discount->customerGroups()->sync([
$customerGroup->id => [
'enabled' => true,
Expand Down Expand Up @@ -421,8 +428,11 @@

$cart = $cart->calculate();

expect($cart->total->value)->toEqual(1200);
expect($cart->freeItems)->toHaveCount(1);
expect($cart->discountTotal->value)->toBe(1010)
->and($cart->subTotalDiscounted->value)->toBe(2000 - 1010)
->and($cart->subTotal->value)->toBe(2000)
->and($cart->total->value)->toBe(1188)
->and($cart->freeItems)->toHaveCount(1);
});

test('can apply multiple different discounts', function () {
Expand Down
18 changes: 18 additions & 0 deletions tests/core/Unit/Managers/DiscountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@

$discount = Discount::factory()->create();

$discount->customerGroups()->sync([
$customerGroup->id => [
'enabled' => false,
'starts_at' => null,
],
]);

$discount->channels()->sync([
$channel->id => [
'enabled' => false,
'starts_at' => null,
],
$channelTwo->id => [
'enabled' => false,
'starts_at' => null,
],
]);

$manager = app(DiscountManagerInterface::class);

expect($manager->getDiscounts())->toBeEmpty();
Expand Down

0 comments on commit 2b31dca

Please sign in to comment.