add notes/remark and refactor round-trip
PHP Tests / php-tests (push) Has been cancelled

This commit is contained in:
Nyan Lin Paing
2026-08-22 21:43:41 +07:00
parent 894352b43f
commit fa908cdcaf
46 changed files with 1679 additions and 182 deletions
@@ -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);
});