Skip to content

Commit 1a9ed00

Browse files
Add support for evening delivery and extra assurance (#63)
1 parent 423b14e commit 1a9ed00

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

src/Resources/Parcel.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public function onlyRecipient(): self
5555
return $this;
5656
}
5757

58+
public function extraAssurance(): self
59+
{
60+
$this->options->extra_assurance = true;
61+
62+
return $this;
63+
}
64+
65+
public function eveningDelivery(): self
66+
{
67+
$this->options->evening_delivery = true;
68+
69+
return $this;
70+
}
71+
5872
public function signature(): self
5973
{
6074
$this->options->signature = true;

src/Resources/ShipmentOptions.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class ShipmentOptions extends BaseResource
2121
/** @var bool */
2222
public $only_recipient;
2323

24+
/** @var bool */
25+
public $extra_assurance;
26+
27+
/** @var bool */
28+
public $evening_delivery;
29+
2430
/** @var bool */
2531
public $signature;
2632

@@ -36,6 +42,8 @@ public function setDefaultOptions(): self
3642
$this->delivery_type = 'DOOR';
3743
$this->signature = false;
3844
$this->only_recipient = false;
45+
$this->extra_assurance = false;
46+
$this->evening_delivery = false;
3947

4048
return $this;
4149
}
@@ -118,6 +126,16 @@ public function toArray(): array
118126
'key' => 'NBB',
119127
]);
120128
})
129+
->when($this->extra_assurance, function ($collection) {
130+
return $collection->push([
131+
'key' => 'EA',
132+
]);
133+
})
134+
->when($this->evening_delivery, function ($collection) {
135+
return $collection->push([
136+
'key' => 'EVE',
137+
]);
138+
})
121139
->all();
122140
}
123141
}

tests/Unit/Resources/ParcelTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function create_a_new_parcel()
5050
'description' => 'Test 123',
5151
'only_recipient' => true,
5252
'signature' => true,
53+
'extra_assurance' => true,
54+
'evening_delivery' => true,
5355
],
5456
'pieces' => [
5557
[
@@ -71,6 +73,8 @@ public function create_a_new_parcel()
7173
$this->assertEquals(1, $parcel->pieces->first()->weight);
7274
$this->assertSame(true, $parcel->options->only_recipient);
7375
$this->assertSame(true, $parcel->options->signature);
76+
$this->assertSame(true, $parcel->options->extra_assurance);
77+
$this->assertSame(true, $parcel->options->evening_delivery);
7478
}
7579

7680
/** @test */
@@ -167,6 +171,46 @@ public function calling_the_only_recipient_method_returns_the_same_parcel_instan
167171
$this->assertSame($parcel, $parcel->onlyRecipient());
168172
}
169173

174+
/** @test */
175+
public function it_can_set_a_parcel_to_be_extra_assured()
176+
{
177+
$parcel = new Parcel();
178+
179+
$this->assertFalse($parcel->options->extra_assurance);
180+
181+
$parcel->extraAssurance();
182+
183+
$this->assertTrue($parcel->options->extra_assurance);
184+
}
185+
186+
/** @test */
187+
public function it_can_set_a_parcel_to_be_evening_delivery()
188+
{
189+
$parcel = new Parcel();
190+
191+
$this->assertFalse($parcel->options->evening_delivery);
192+
193+
$parcel->eveningDelivery();
194+
195+
$this->assertTrue($parcel->options->evening_delivery);
196+
}
197+
198+
/** @test */
199+
public function calling_the_extra_assurance_method_returns_the_same_parcel_instance()
200+
{
201+
$parcel = new Parcel();
202+
203+
$this->assertSame($parcel, $parcel->extraAssurance());
204+
}
205+
206+
/** @test */
207+
public function calling_the_evening_delivery_method_returns_the_same_parcel_instance()
208+
{
209+
$parcel = new Parcel();
210+
211+
$this->assertSame($parcel, $parcel->eveningDelivery());
212+
}
213+
170214
/** @test */
171215
public function it_can_set_a_parcel_to_be_a_mailbox_package()
172216
{

tests/Unit/Resources/ShipmentOptionsTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function creating_a_shipments_options_resource()
1717
$this->assertEquals('Test', $options->label_description);
1818
$this->assertFalse($options->signature);
1919
$this->assertFalse($options->only_recipient);
20+
$this->assertFalse($options->extra_assurance);
21+
$this->assertFalse($options->evening_delivery);
2022
}
2123

2224
/** @test */
@@ -120,6 +122,48 @@ public function to_array_with_recipient_only()
120122
], $array);
121123
}
122124

125+
/** @test */
126+
public function to_array_with_extra_assurance()
127+
{
128+
$options = new ShipmentOptions([
129+
'extra_assurance' => true,
130+
]);
131+
132+
$array = $options->toArray();
133+
134+
$this->assertIsArray($array);
135+
136+
$this->assertEquals([
137+
[
138+
'key' => 'DOOR',
139+
],
140+
[
141+
'key' => 'EA',
142+
],
143+
], $array);
144+
}
145+
146+
/** @test */
147+
public function to_array_with_evening_delivery()
148+
{
149+
$options = new ShipmentOptions([
150+
'evening_delivery' => true,
151+
]);
152+
153+
$array = $options->toArray();
154+
155+
$this->assertIsArray($array);
156+
157+
$this->assertEquals([
158+
[
159+
'key' => 'DOOR',
160+
],
161+
[
162+
'key' => 'EVE',
163+
],
164+
], $array);
165+
}
166+
123167
/** @test */
124168
public function to_array_with_mailbox_package()
125169
{

0 commit comments

Comments
 (0)