Default vehicle subscriptions to false (#288)

Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk>
This commit is contained in:
Jeppe B
2026-07-06 09:21:31 +02:00
committed by GitHub
co-authored by Jeppe Bundgaard
parent 64e0b2444b
commit 3f41eebdf6
4 changed files with 111 additions and 5 deletions
+3 -1
View File
@@ -7462,7 +7462,7 @@ paths:
application/json:
schema:
type: object
required: [reg, type, wash_subscription]
required: [reg, type]
properties:
reg:
type: string
@@ -7474,6 +7474,8 @@ paths:
description: Product ID representing the vehicle wash type
wash_subscription:
type: boolean
default: false
description: Defaults to false when omitted.
reference:
type: string
maxLength: 255
+3 -1
View File
@@ -7462,7 +7462,7 @@ paths:
application/json:
schema:
type: object
required: [reg, type, wash_subscription]
required: [reg, type]
properties:
reg:
type: string
@@ -7474,6 +7474,8 @@ paths:
description: Product ID representing the vehicle wash type
wash_subscription:
type: boolean
default: false
description: Defaults to false when omitted.
reference:
type: string
maxLength: 255
+5 -3
View File
@@ -132,7 +132,6 @@ class vehiclesRoute
self::requireParameters([
'type',
'reg',
'wash_subscription',
]);
// Determine target customer
@@ -165,11 +164,14 @@ class vehiclesRoute
// Validate the parameters
self::requireType(self::getParameter('reg'), self::type_string());
self::requireType(self::getParameter('type'), self::type_int());
self::requireType(self::getParameter('wash_subscription'), self::type_bool());
$subscription = false;
if (self::isParametersSet(['wash_subscription'])) {
self::requireType(self::getParameter('wash_subscription'), self::type_bool());
$subscription = (bool)self::getParameter('wash_subscription');
}
// Get the parameters
$reg = (string)self::getParameter('reg');
$type = (int)self::getParameter('type');
$subscription = (bool)self::getParameter('wash_subscription');
$reg = trim($reg);
// Create a new vehicle
@@ -4,6 +4,106 @@ declare(strict_types=1);
usesApiSuite();
it('defaults wash subscriptions to false when a customer creates a vehicle without the field', function (): void {
api_test_covers('POST /vehicles', 'happy');
$session = api_fixtures()->createUserSession(['add_vehicle']);
$response = api_client()->post('/vehicles', [
'type' => 53,
'reg' => 'DEFAULTOWN',
], $session['headers']);
$response
->assertStatus(200)
->assertEnvelope()
->assertSuccess();
$vehicleId = (int)($response->data()['id'] ?? 0);
expect($vehicleId)->toBeGreaterThan(0);
$row = api_fixtures()->fetchRowById('customer_vehicles', $vehicleId);
expect($row)->not->toBeNull();
expect((int)$row['customer_id'])->toBe((int)$session['user']['customer_number']);
expect((int)$row['wash_subscription'])->toBe(0);
expect($response->data())->toMatchArray([
'id' => $vehicleId,
'customer_id' => (int)$session['user']['customer_number'],
'reg' => 'DEFAULTOWN',
'wash_subscription' => false,
]);
api_fixtures()->cleanupDeleteById('customer_vehicles', $vehicleId);
api_fixtures()->cleanupDeleteWhere('customer_vehicle_subscription_versions', ['vehicle_id' => $vehicleId]);
});
it('defaults wash subscriptions to false when a superuser creates a vehicle for another customer without the field', function (): void {
api_test_covers('POST /vehicles', 'happy');
$targetCustomer = api_fixtures()->createUser(['display_name' => 'Vehicle Default Target Customer']);
$session = api_fixtures()->createUserSession(['add_vehicle_other']);
$response = api_client()->post('/vehicles', [
'customer_id' => $targetCustomer['customer_number'],
'type' => 53,
'reg' => 'DEFAULTSU',
], $session['headers']);
$response
->assertStatus(200)
->assertEnvelope()
->assertSuccess();
$vehicleId = (int)($response->data()['id'] ?? 0);
expect($vehicleId)->toBeGreaterThan(0);
$row = api_fixtures()->fetchRowById('customer_vehicles', $vehicleId);
expect($row)->not->toBeNull();
expect((int)$row['customer_id'])->toBe((int)$targetCustomer['customer_number']);
expect((int)$row['wash_subscription'])->toBe(0);
expect($response->data())->toMatchArray([
'id' => $vehicleId,
'customer_id' => (int)$targetCustomer['customer_number'],
'reg' => 'DEFAULTSU',
'wash_subscription' => false,
]);
api_fixtures()->cleanupDeleteById('customer_vehicles', $vehicleId);
api_fixtures()->cleanupDeleteWhere('customer_vehicle_subscription_versions', ['vehicle_id' => $vehicleId]);
});
it('still honors an explicit wash subscription true value on vehicle create', function (): void {
api_test_covers('POST /vehicles', 'happy');
$session = api_fixtures()->createUserSession(['add_vehicle']);
$response = api_client()->post('/vehicles', [
'type' => 53,
'reg' => 'EXPLICITON',
'wash_subscription' => true,
], $session['headers']);
$response
->assertStatus(200)
->assertEnvelope()
->assertSuccess();
$vehicleId = (int)($response->data()['id'] ?? 0);
expect($vehicleId)->toBeGreaterThan(0);
$row = api_fixtures()->fetchRowById('customer_vehicles', $vehicleId);
expect($row)->not->toBeNull();
expect((int)$row['wash_subscription'])->toBe(1);
expect($response->data())->toMatchArray([
'id' => $vehicleId,
'reg' => 'EXPLICITON',
'wash_subscription' => true,
]);
api_fixtures()->cleanupDeleteById('customer_vehicles', $vehicleId);
api_fixtures()->cleanupDeleteWhere('customer_vehicle_subscription_versions', ['vehicle_id' => $vehicleId]);
});
it('returns the newest vehicle last_order_id that still has order items', function (): void {
api_test_covers('GET /vehicles', 'happy');