Skip to content

Commit

Permalink
[CreditMemo] Fixes for reworking credit memos after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Jan 29, 2020
1 parent 981220d commit b7a1869
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 141 deletions.
8 changes: 4 additions & 4 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### UPGRADE FROM 1.0.0-RC.1 TO 1.0.0-RC.2

1. `CreditMemoUnit` changed to `LineItem` which is a resource entity now
1. `Sylius\RefundPlugin\Entity\CreditMemoUnit` was changed to `Sylius\RefundPlugin\Entity\LineItem` which is a resource entity now.

2. `CreditMemoUnitGeneratorInterface` changed to `LineItemsConverterInterface` and moved from `Generator` to `Converter` directory
2. `Sylius\RefundPlugin\Generator\CreditMemoUnitGeneratorInterface` was changed to `Sylius\RefundPlugin\Converter\LineItemsConverterInterface`.

3. `OrderItemUnitCreditMemoUnitGenerator` changed to `LineItemsConverter` and moved from `Generator` to `Converter` directory
3. `Sylius\RefundPlugin\Generator\OrderItemUnitCreditMemoUnitGenerator` was changed to `Sylius\RefundPlugin\Converter\LineItemsConverter`.

4. `ShipmentCreditMemoUnitGenerator` changed to `ShipmentLineItemsConverter` and moved from `Generator` to `Converter` directory
4. `Sylius\RefundPlugin\Generator\ShipmentCreditMemoUnitGenerator` was changed to `Sylius\RefundPlugin\Converter\ShipmentLineItemsConverter`.

There are no migrations that provide backward compatibility, save current credit memos before upgrading the version of plugin.

Expand Down
6 changes: 3 additions & 3 deletions features/refunding_part_of_order_unit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ Feature: Refunding a part of an order unit

@ui @application
Scenario: Refunding the whole order unit price after partial refund
Given the 1st "Mr. Meeseeks T-Shirt" product from order "#00000022" already has a refund of "$5.00" with "Space money" payment
Given the 1st "Mr. Meeseeks T-Shirt" product from order "#00000022" has a refund of "$5.00" with "Space money" payment
When I want to refund some units of order "#00000022"
And I decide to refund 1st "Mr. Meeseeks T-Shirt" product with "Space money" payment
Then I should be notified that selected order units have been successfully refunded
And this order refunded total should be "$12.30"

@ui @javascript
Scenario: Refunding the whole order price after partial refund
Given the 1st "Mr. Meeseeks T-Shirt" product from order "#00000022" already has a refund of "$5.00" with "Space money" payment
Given the 1st "Mr. Meeseeks T-Shirt" product from order "#00000022" has a refund of "$5.00" with "Space money" payment
When I want to refund some units of order "#00000022"
And I decide to refund all units of this order with "Space money" payment
Then I should be notified that selected order units have been successfully refunded
And this order refunded total should be "$44.60"

@ui @application
Scenario: Not being able to refund more money than order unit total
Given the 1st "Mr. Meeseeks T-Shirt" product from order "#00000022" already has a refund of "$5.00" with "Space money" payment
Given the 1st "Mr. Meeseeks T-Shirt" product from order "#00000022" has a refund of "$5.00" with "Space money" payment
When I want to refund some units of order "#00000022"
And I decide to refund "$10.00" from 1st "Mr. Meeseeks T-Shirt" product with "Space money" payment
Then I should be notified that I cannot refund more money than the order unit total
Expand Down
2 changes: 1 addition & 1 deletion features/viewing_details_of_credit_memo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Feature: Viewing details of a credit memo

@ui @application
Scenario: Viewing details of a credit memo issued for a partial refund
Given the 1st "PHP T-Shirt" product from order "#00000022" already has a refund of "$5.50" with "Space money" payment
Given the 1st "PHP T-Shirt" product from order "#00000022" has a refund of "$5.50" with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should be issued in "United States" channel
Expand Down
8 changes: 4 additions & 4 deletions spec/Converter/LineItemsConverterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function it_converts_unit_refunds_to_line_items(
$orderItem->getProductName()->willReturn('Portal gun');
$adjustment->getLabel()->willReturn('25%');

$this->convert([$unitRefund])->shouldBeLike(new ArrayCollection([new LineItem(
$this->convert([$unitRefund])->shouldBeLike([new LineItem(
'Portal gun',
1,
400,
Expand All @@ -56,7 +56,7 @@ function it_converts_unit_refunds_to_line_items(
500,
100,
'25%'
)]));
)]);
}

function it_groups_the_same_line_items_during_converting(
Expand Down Expand Up @@ -98,7 +98,7 @@ function it_groups_the_same_line_items_during_converting(
$secondOrderItem->getProductName()->willReturn('Space gun');
$secondAdjustment->getLabel()->willReturn('20%');

$this->convert([$firstUnitRefund, $secondUnitRefund, $thirdUnitRefund])->shouldBeLike(new ArrayCollection([
$this->convert([$firstUnitRefund, $secondUnitRefund, $thirdUnitRefund])->shouldBeLike([
new LineItem(
'Portal gun',
1,
Expand All @@ -119,7 +119,7 @@ function it_groups_the_same_line_items_during_converting(
320,
'20%'
),
]));
]);
}

function it_throws_an_exception_if_there_is_no_shipping_adjustment_with_given_id(
Expand Down
5 changes: 2 additions & 3 deletions spec/Converter/ShipmentLineItemsConverterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace spec\Sylius\RefundPlugin\Converter;

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
Expand Down Expand Up @@ -38,15 +37,15 @@ function it_converts_shipment_unit_refunds_to_line_items(
$shippingAdjustment->getLabel()->willReturn('Galaxy post');
$shippingAdjustment->getAmount()->willReturn(1000);

$this->convert([$unitRefund])->shouldBeLike(new ArrayCollection([new LineItem(
$this->convert([$unitRefund])->shouldBeLike([new LineItem(
'Galaxy post',
1,
500,
500,
500,
500,
0
)]));
)]);
}

function it_throws_an_exception_if_there_is_no_shipping_adjustment_with_given_id(
Expand Down
11 changes: 2 additions & 9 deletions spec/Entity/CreditMemoSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace spec\Sylius\RefundPlugin\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
use Sylius\RefundPlugin\Entity\CustomerBillingData;
use Sylius\RefundPlugin\Entity\LineItemInterface;
Expand All @@ -29,7 +27,7 @@ function let(LineItemInterface $lineItem, ChannelInterface $channel, OrderInterf
'USD',
'en_US',
$channel,
new ArrayCollection([$lineItem->getWrappedObject()]),
[$lineItem->getWrappedObject()],
[$taxItem->serialize()],
'Comment',
new \DateTime('01-01-2020 10:10:10'),
Expand All @@ -43,11 +41,6 @@ function it_implements_a_credit_memo_interface(): void
$this->shouldImplement(CreditMemoInterface::class);
}

function it_implements_a_resource_interface(): void
{
$this->shouldImplement(ResourceInterface::class);
}

function it_has_id(): void
{
$this->getId()->shouldReturn('7903c83a-4c5e-4bcf-81d8-9dc304c6a353');
Expand Down Expand Up @@ -85,7 +78,7 @@ function it_has_a_channel(ChannelInterface $channel): void

function it_has_line_items(LineItemInterface $lineItem): void
{
$this->getLineItems()->shouldBeLike(new ArrayCollection([$lineItem->getWrappedObject()]));
$this->getLineItems()->shouldBeLike([$lineItem->getWrappedObject()]);
}

function it_has_tax_items(): void
Expand Down
46 changes: 46 additions & 0 deletions spec/Entity/LineItemSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\RefundPlugin\Entity\LineItemInterface;
use Sylius\RefundPlugin\Exception\LineItemsCannotBeMerged;

final class LineItemSpec extends ObjectBehavior
{
Expand Down Expand Up @@ -36,4 +37,49 @@ function it_has_proper_line_item_data(): void
$this->taxAmount()->shouldReturn(200);
$this->taxRate()->shouldReturn('10%');
}

function it_merges_with_another_line_item(LineItemInterface $newLineItem): void
{
$newLineItem->name()->willReturn('Mjolnir');
$newLineItem->quantity()->willReturn(1);
$newLineItem->unitNetPrice()->willReturn(1000);
$newLineItem->unitGrossPrice()->willReturn(1100);
$newLineItem->netValue()->willReturn(1000);
$newLineItem->grossValue()->willReturn(1100);
$newLineItem->taxAmount()->willReturn(100);
$newLineItem->taxRate()->willReturn('10%');

$this->merge($newLineItem);

$this->quantity()->shouldReturn(3);
$this->netValue()->shouldReturn(3000);
$this->grossValue()->shouldReturn(3300);
$this->taxAmount()->shouldReturn(300);
}

function it_throws_an_exception_if_another_line_item_is_different_during_merging(LineItemInterface $newLineItem): void
{
$newLineItem->name()->willReturn('Stormbreaker');
$newLineItem->unitNetPrice()->willReturn(1000);
$newLineItem->unitGrossPrice()->willReturn(1100);
$newLineItem->taxRate()->willReturn('10%');

$this->shouldThrow(LineItemsCannotBeMerged::class)->during('merge', [$newLineItem]);
}

function it_compares_with_another_line_item(LineItemInterface $theSameLineItem, LineItemInterface $differentLineItem): void
{
$theSameLineItem->name()->willReturn('Mjolnir');
$theSameLineItem->unitNetPrice()->willReturn(1000);
$theSameLineItem->unitGrossPrice()->willReturn(1100);
$theSameLineItem->taxRate()->willReturn('10%');

$differentLineItem->name()->willReturn('Stormbreaker');
$differentLineItem->unitNetPrice()->willReturn(1000);
$differentLineItem->unitGrossPrice()->willReturn(1100);
$differentLineItem->taxRate()->willReturn('10%');

$this->compare($theSameLineItem)->shouldReturn(true);
$this->compare($differentLineItem)->shouldReturn(false);
}
}
15 changes: 7 additions & 8 deletions spec/Generator/CreditMemoGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace spec\Sylius\RefundPlugin\Generator;

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\ChannelInterface;
Expand All @@ -13,6 +12,7 @@
use Sylius\RefundPlugin\Converter\LineItemsConverterInterface;
use Sylius\RefundPlugin\Entity\CreditMemo;
use Sylius\RefundPlugin\Entity\CustomerBillingData;
use Sylius\RefundPlugin\Entity\LineItemInterface;
use Sylius\RefundPlugin\Entity\ShopBillingData;
use Sylius\RefundPlugin\Entity\TaxItem;
use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface;
Expand Down Expand Up @@ -59,6 +59,8 @@ function it_generates_credit_memo_basing_on_event_data(
ChannelInterface $channel,
ShopBillingDataInterface $shopBillingData,
AddressInterface $customerBillingAddress,
LineItemInterface $firstLineItem,
LineItemInterface $secondLineItem,
\DateTime $dateTime
): void {
$firstUnitRefund = new OrderItemUnitRefund(1, 500);
Expand Down Expand Up @@ -92,14 +94,11 @@ function it_generates_credit_memo_basing_on_event_data(
$customerBillingAddress->getProvinceName()->willReturn(null);
$customerBillingAddress->getProvinceCode()->willReturn(null);

$mockedLineItems = new ArrayCollection();
$mockedShipmentLineItems = new ArrayCollection();

$lineItemsConverter->convert([$firstUnitRefund, $secondUnitRefund])->willReturn($mockedLineItems);
$shipmentLineItemsConverter->convert([$shipmentRefund])->willReturn($mockedShipmentLineItems);
$lineItemsConverter->convert([$firstUnitRefund, $secondUnitRefund])->willReturn([$firstLineItem]);
$shipmentLineItemsConverter->convert([$shipmentRefund])->willReturn([$secondLineItem]);

$taxItem = new TaxItem('VAT', 100);
$taxItemsGenerator->generate($mockedLineItems)->willReturn([$taxItem]);
$taxItemsGenerator->generate([$firstLineItem, $secondLineItem])->willReturn([$taxItem]);

$creditMemoNumberGenerator->generate()->willReturn('2018/07/00001111');

Expand All @@ -115,7 +114,7 @@ function it_generates_credit_memo_basing_on_event_data(
'GBP',
'en_US',
$channel->getWrappedObject(),
$mockedLineItems,
[$firstLineItem->getWrappedObject(), $secondLineItem->getWrappedObject()],
[$taxItem->serialize()],
'Comment',
$dateTime->getWrappedObject(),
Expand Down
3 changes: 1 addition & 2 deletions spec/Generator/TaxItemsGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace spec\Sylius\RefundPlugin\Generator;

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Sylius\RefundPlugin\Entity\LineItemInterface;
use Sylius\RefundPlugin\Entity\TaxItem;
Expand All @@ -26,7 +25,7 @@ function it_generates_tax_items(LineItemInterface $firstLineItem, LineItemInterf
$secondLineItem->taxAmount()->willReturn(800);

$this
->generate(new ArrayCollection([$firstLineItem->getWrappedObject(), $secondLineItem->getWrappedObject()]))
->generate([$firstLineItem->getWrappedObject(), $secondLineItem->getWrappedObject()])
->shouldBeLike([new TaxItem('VAT', 1300)])
;
}
Expand Down
Loading

0 comments on commit b7a1869

Please sign in to comment.