Default vehicle subscriptions to false (#288)
Co-authored-by: Jeppe Bundgaard <jb@truckwash.dk>
This commit is contained in:
co-authored by
Jeppe Bundgaard
parent
64e0b2444b
commit
3f41eebdf6
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user