You are here

public function TaxTypePluginTest::testOrderAdjustments in Drupal Commerce Connector for AvaTax 8

Tests that order adjustments are correctly sent.

File

tests/src/Kernel/TaxTypePluginTest.php, line 372

Class

TaxTypePluginTest
Tests the tax type plugin.

Namespace

Drupal\Tests\commerce_avatax\Kernel

Code

public function testOrderAdjustments() {
  $this->order
    ->addAdjustment(new Adjustment([
    'type' => 'custom',
    'label' => 'Custom adjustment',
    'amount' => new Price('4.00', 'USD'),
    'source_id' => '1',
  ]));
  $this->order
    ->setRefreshState(Order::REFRESH_SKIP);
  $this->order
    ->save();
  $order_items = $this->order
    ->getItems();
  $order_item = reset($order_items);
  $lines = [
    [
      'lineNumber' => $order_item
        ->uuid(),
      'tax' => 5.25,
    ],
    [
      'lineNumber' => 2,
      'tax' => 2.0,
    ],
  ];
  $this
    ->mockResponse([
    new Response(200, [], Json::encode([
      'lines' => $lines,
    ])),
  ]);
  $this->taxType
    ->getPlugin()
    ->apply($this->order);
  $tax_adjustments = $this->order
    ->collectAdjustments([
    'tax',
  ]);
  $tax_adjustment_total = NULL;
  foreach ($tax_adjustments as $adjustment) {
    $this
      ->assertEquals('Sales tax', $adjustment
      ->getLabel());
    $this
      ->assertEquals('avatax|avatax', $adjustment
      ->getSourceId());
    $tax_adjustment_total = $tax_adjustment_total ? $tax_adjustment_total
      ->add($adjustment
      ->getAmount()) : $adjustment
      ->getAmount();
  }
  $this
    ->assertCount(2, $tax_adjustments);
  $this
    ->assertEquals(new Price('7.25', 'USD'), $tax_adjustment_total);
}