Files
api/services/nginx/app/tests/Api/SelfserveLaneWashInProgressApiTest.php
T
Jeppe Bundgaard 72704b7806 Add "Get My Active Self-Serve Wash" endpoint and corresponding tests
- Introduced a new `/modules/self-serve/lane/wash/my-active-wash` endpoint to retrieve the authenticated customer's active self-serve wash.
- Implemented authentication and permission checks for secure access.
- Added detailed response handling for various scenarios, including 401, 403, and 404 statuses.
- Extended API documentation and OpenAPI spec to support the new endpoint.
- Updated unit and API tests to validate endpoint functionality and route wiring.
2026-06-02 10:29:15 +02:00

137 lines
4.9 KiB
PHP

<?php
usesApiSuite();
it('requires authentication before checking in-progress wash permissions', function (): void {
$response = api_client()->get('/modules/self-serve/lane/wash/in-progress?lane_id=1');
$response
->assertStatus(401)
->assertMessage('Authentication failed. Invalid or missing token.');
});
it('requires authentication before checking the current customers active self-serve wash', function (): void {
$response = api_client()->get('/modules/self-serve/lane/wash/my-active-wash');
$response
->assertStatus(401)
->assertMessage('Authentication failed. Invalid or missing token.');
});
it('reports both elevated and customer self-serve permissions when lane polling is not allowed', function (): void {
$session = api_fixtures()->createUserSession([]);
$response = api_client()->get(
'/modules/self-serve/lane/wash/in-progress?lane_id=1',
$session['headers']
);
$response
->assertStatus(403)
->assertMissingPermissions([
'modules_selfserve_lane_wash_in_progress_view',
'list_own_department_selfserve_vehicle_conditions',
]);
});
it('requires customer self-serve permission before checking my active wash', function (): void {
$session = api_fixtures()->createUserSession([]);
$response = api_client()->get('/modules/self-serve/lane/wash/my-active-wash', $session['headers']);
$response
->assertStatus(403)
->assertMissingPermissions([
'list_own_department_selfserve_vehicle_conditions',
]);
});
it('allows customer self-serve permission to view their own in-progress wash details', function (): void {
$group = api_fixtures()->createGroup([], [
'list_own_department_selfserve_vehicle_conditions',
]);
$scenario = api_fixtures()->createSelfServeScenario([
'customer' => [
'group_id' => $group['id'],
],
]);
$token = api_fixtures()->createAuthToken((int)$scenario['customer']['id']);
$response = api_client()->get(
'/modules/self-serve/lane/wash/in-progress?lane_id=' . (int)$scenario['lane']['id'],
api_fixtures()->bearerHeaders($token)
);
$response
->assertStatus(200)
->assertSuccess(true);
expect($response->data()['in_progress'] ?? null)->toBeTrue()
->and($response->data()['session']['customer_number'] ?? null)->toBe((int)$scenario['customer']['customer_number'])
->and($response->data()['vehicle']['reg'] ?? null)->toBe($scenario['vehicle']['reg']);
});
it('returns the authenticated customers active self-serve wash without requiring a lane id', function (): void {
$group = api_fixtures()->createGroup([], [
'list_own_department_selfserve_vehicle_conditions',
]);
$scenario = api_fixtures()->createSelfServeScenario([
'customer' => [
'group_id' => $group['id'],
],
]);
$token = api_fixtures()->createAuthToken((int)$scenario['customer']['id']);
$response = api_client()->get(
'/modules/self-serve/lane/wash/my-active-wash',
api_fixtures()->bearerHeaders($token)
);
$response
->assertStatus(200)
->assertSuccess(true);
expect($response->data()['in_progress'] ?? null)->toBeTrue()
->and($response->data()['lane_id'] ?? null)->toBe((int)$scenario['lane']['id'])
->and($response->data()['session']['id'] ?? null)->toBe((int)$scenario['session']['id'])
->and($response->data()['session']['lane_id'] ?? null)->toBe((int)$scenario['lane']['id'])
->and($response->data()['session']['customer_number'] ?? null)->toBe((int)$scenario['customer']['customer_number'])
->and($response->data()['vehicle']['reg'] ?? null)->toBe($scenario['vehicle']['reg']);
});
it('returns 404 when the authenticated customer has no active self-serve wash', function (): void {
$session = api_fixtures()->createUserSession([
'list_own_department_selfserve_vehicle_conditions',
]);
$response = api_client()->get('/modules/self-serve/lane/wash/my-active-wash', $session['headers']);
$response
->assertStatus(404)
->assertMessage('No active self-serve wash found.');
});
it('redacts another customers in-progress wash from customer self-serve lane polling', function (): void {
$scenario = api_fixtures()->createSelfServeScenario();
$otherSession = api_fixtures()->createUserSession([
'list_own_department_selfserve_vehicle_conditions',
]);
$response = api_client()->get(
'/modules/self-serve/lane/wash/in-progress?lane_id=' . (int)$scenario['lane']['id'],
$otherSession['headers']
);
$response
->assertStatus(200)
->assertSuccess(true);
expect($response->data())->toMatchArray([
'lane_id' => (int)$scenario['lane']['id'],
'in_progress' => true,
'session' => null,
'customer' => null,
'vehicle' => null,
]);
});