Refactor point value object and add observability
This commit is contained in:
@@ -48,7 +48,9 @@ class SignalControllerTest extends WebTestCase
|
||||
|
||||
public function testIndexReturnsRecentSignals(): void
|
||||
{
|
||||
$this->client->request('GET', '/api/signals');
|
||||
$this->client->request('GET', '/api/signals', server: [
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
]);
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
|
||||
@@ -60,12 +62,14 @@ class SignalControllerTest extends WebTestCase
|
||||
self::assertCount(3, $payload['points']);
|
||||
self::assertSame(3, $payload['totals']['points']);
|
||||
self::assertSame(2, $payload['totals']['contributors']);
|
||||
self::assertSame(-11.6852, $payload['points'][0]['lat']);
|
||||
self::assertSame(-11.6852, $payload['points'][0]['signalLocation']['lat']);
|
||||
}
|
||||
|
||||
public function testIndexRespectsLimitQueryParameter(): void
|
||||
{
|
||||
$this->client->request('GET', '/api/signals?limit=1');
|
||||
$this->client->request('GET', '/api/signals?limit=1', server: [
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
]);
|
||||
|
||||
self::assertResponseIsSuccessful();
|
||||
|
||||
@@ -80,13 +84,20 @@ class SignalControllerTest extends WebTestCase
|
||||
public function testStorePersistsNewSignal(): void
|
||||
{
|
||||
$body = [
|
||||
'lat' => -11.6901,
|
||||
'lng' => 27.4959,
|
||||
'signalLocation' => [
|
||||
'lat' => -11.6901,
|
||||
'lng' => 27.4959,
|
||||
],
|
||||
'userLocation' => [
|
||||
'lat' => -11.6899,
|
||||
'lng' => 27.4962,
|
||||
],
|
||||
];
|
||||
|
||||
$this->client->request('POST', '/api/signals', [], [], [
|
||||
$this->client->request('POST', '/api/signals', server: [
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
], json_encode($body, JSON_THROW_ON_ERROR));
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
], content: json_encode($body, JSON_THROW_ON_ERROR));
|
||||
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
|
||||
|
||||
@@ -94,8 +105,10 @@ class SignalControllerTest extends WebTestCase
|
||||
self::assertIsString($content);
|
||||
$payload = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
|
||||
self::assertSame('stored', $payload['status']);
|
||||
self::assertSame($body['lat'], $payload['point']['lat']);
|
||||
self::assertSame($body['lng'], $payload['point']['lng']);
|
||||
self::assertSame($body['signalLocation']['lat'], $payload['point']['signalLocation']['lat']);
|
||||
self::assertSame($body['signalLocation']['lng'], $payload['point']['signalLocation']['lng']);
|
||||
self::assertSame($body['userLocation']['lat'], $payload['point']['userLocation']['lat']);
|
||||
self::assertSame($body['userLocation']['lng'], $payload['point']['userLocation']['lng']);
|
||||
|
||||
$repository = $this->entityManager->getRepository(Signal::class);
|
||||
$signals = $repository->findAll();
|
||||
@@ -105,19 +118,58 @@ class SignalControllerTest extends WebTestCase
|
||||
public function testStoreRejectsInvalidCoordinates(): void
|
||||
{
|
||||
$body = [
|
||||
'lat' => 181,
|
||||
'lng' => 10,
|
||||
'signalLocation' => [
|
||||
'lat' => 181,
|
||||
'lng' => 10,
|
||||
],
|
||||
'userLocation' => [
|
||||
'lat' => 10,
|
||||
'lng' => 10,
|
||||
],
|
||||
];
|
||||
|
||||
$this->client->request('POST', '/api/signals', [], [], [
|
||||
$this->client->request('POST', '/api/signals', server: [
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
], json_encode($body, JSON_THROW_ON_ERROR));
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
], content: json_encode($body, JSON_THROW_ON_ERROR));
|
||||
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
|
||||
$content = $this->client->getResponse()->getContent();
|
||||
$response = $this->client->getResponse();
|
||||
self::assertSame('invalid_coordinates', $response->headers->get('x-error-code'));
|
||||
|
||||
$content = $response->getContent();
|
||||
self::assertIsString($content);
|
||||
$payload = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
|
||||
self::assertSame('out_of_bounds', $payload['error']);
|
||||
self::assertSame('Latitude 181.000000 is out of bounds.', $payload['detail'] ?? null);
|
||||
}
|
||||
|
||||
public function testStoreRejectsPointTooFar(): void
|
||||
{
|
||||
$body = [
|
||||
'signalLocation' => [
|
||||
'lat' => -11.6901,
|
||||
'lng' => 27.4959,
|
||||
],
|
||||
'userLocation' => [
|
||||
'lat' => -11.7005,
|
||||
'lng' => 27.4804,
|
||||
],
|
||||
];
|
||||
|
||||
$this->client->request('POST', '/api/signals', server: [
|
||||
'CONTENT_TYPE' => 'application/json',
|
||||
'HTTP_ACCEPT' => 'application/json',
|
||||
], content: json_encode($body, JSON_THROW_ON_ERROR));
|
||||
|
||||
self::assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
self::assertSame('point_too_far', $response->headers->get('x-error-code'));
|
||||
|
||||
$content = $response->getContent();
|
||||
self::assertIsString($content);
|
||||
$payload = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
|
||||
self::assertSame('The submitted point must be within 1.00km of your location.', $payload['detail'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user