This commit is contained in:
@@ -191,3 +191,44 @@ test('404s for a booking that does not exist', function () {
|
||||
->postJson('/api/v1/payments/EVB-DOES-NOT-EXIST/initiate')
|
||||
->assertNotFound();
|
||||
});
|
||||
|
||||
test('round trip: initiating payment on the primary leg charges the combined total of both legs', function () {
|
||||
$outbound = Booking::factory()->create([
|
||||
'user_id' => $this->owner->id,
|
||||
'status' => BookingStatus::PendingPayment,
|
||||
'price' => 9000,
|
||||
]);
|
||||
$return = Booking::factory()->create([
|
||||
'status' => BookingStatus::PendingPayment,
|
||||
'price' => 11000,
|
||||
'is_return_leg' => true,
|
||||
'linked_booking_id' => $outbound->id,
|
||||
]);
|
||||
$outbound->update(['linked_booking_id' => $return->id]);
|
||||
|
||||
$this->withHeader('Authorization', "Bearer {$this->token}")
|
||||
->postJson("/api/v1/payments/{$outbound->booking_ref}/initiate")
|
||||
->assertCreated();
|
||||
|
||||
$payment = Payment::where('booking_id', $outbound->id)->sole();
|
||||
|
||||
expect((float) $payment->amount)->toBe(20000.0)
|
||||
->and(Payment::where('booking_id', $return->id)->count())->toBe(0);
|
||||
});
|
||||
|
||||
test('round trip: initiating payment on the return leg directly surfaces as 422', function () {
|
||||
$outbound = Booking::factory()->create(['user_id' => $this->owner->id, 'status' => BookingStatus::PendingPayment]);
|
||||
$return = Booking::factory()->create([
|
||||
'user_id' => $this->owner->id,
|
||||
'status' => BookingStatus::PendingPayment,
|
||||
'is_return_leg' => true,
|
||||
'linked_booking_id' => $outbound->id,
|
||||
]);
|
||||
$outbound->update(['linked_booking_id' => $return->id]);
|
||||
|
||||
$this->withHeader('Authorization', "Bearer {$this->token}")
|
||||
->postJson("/api/v1/payments/{$return->booking_ref}/initiate")
|
||||
->assertStatus(422);
|
||||
|
||||
expect(Payment::where('booking_id', $return->id)->count())->toBe(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user