-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathFlatRateTest.php
More file actions
70 lines (55 loc) · 1.8 KB
/
FlatRateTest.php
File metadata and controls
70 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use Illuminate\Foundation\Testing\RefreshDatabase;
use Lunar\DataTypes\ShippingOption;
use Lunar\Models\Currency;
use Lunar\Models\TaxClass;
use Lunar\Shipping\DataTransferObjects\ShippingOptionRequest;
use Lunar\Shipping\Drivers\ShippingMethods\FlatRate;
use Lunar\Shipping\Models\ShippingMethod;
use Lunar\Shipping\Models\ShippingRate;
use Lunar\Shipping\Models\ShippingZone;
use Lunar\Tests\Shipping\TestCase;
use Lunar\Tests\Shipping\TestUtils;
uses(TestCase::class)->group('shipping', 'shipping-driver', 'shipping-driver-flatrate');
uses(RefreshDatabase::class);
uses(TestUtils::class);
test('can get flat rate shipping', function () {
$currency = Currency::factory()->create([
'default' => true,
]);
TaxClass::factory()->create([
'default' => true,
]);
$shippingZone = ShippingZone::factory()->create([
'type' => 'countries',
]);
$shippingMethod = ShippingMethod::factory()->create([
'driver' => 'flat-rate',
'data' => [
'minimum_spend' => [
"{$currency->code}" => 200,
],
],
]);
$shippingRate = ShippingRate::factory()
->create([
'shipping_method_id' => $shippingMethod->id,
'shipping_zone_id' => $shippingZone->id,
]);
$shippingRate->prices()->createMany([
[
'price' => 600,
'min_quantity' => 1,
'currency_id' => $currency->id,
],
]);
$cart = $this->createCart($currency, 500);
$driver = new FlatRate;
$request = new ShippingOptionRequest(
cart: $cart,
shippingRate: $shippingRate
);
$shippingOption = $driver->resolve($request);
expect($shippingOption)->toBeInstanceOf(ShippingOption::class);
expect($shippingOption->price->value)->toEqual(600);
});