Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ name: CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main
workflow_dispatch: ~

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -57,9 +55,9 @@ jobs:
run: docker compose -f compose.test.yaml exec -T app vendor/bin/phpunit

- name: Run PHPUnit with coverage
run: docker compose -f compose.test.yaml exec -T app php -d pcov.enabled=1 vendor/bin/phpunit --testsuite=unit --coverage-clover var/coverage/clover.xml --coverage-text
run: docker compose -f compose.test.yaml exec -T app php -d pcov.enabled=1 vendor/bin/phpunit --coverage-clover var/coverage/clover.xml --coverage-text

- name: Check coverage threshold (80%)
- name: Check coverage threshold (90%)
run: |
COVERAGE=$(docker compose -f compose.test.yaml exec -T app php -r "
\$xml = simplexml_load_file('var/coverage/clover.xml');
Expand All @@ -69,8 +67,8 @@ jobs:
echo \$statements > 0 ? round((\$covered / \$statements) * 100, 2) : 0;
")
echo "Line coverage: ${COVERAGE}%"
if [ "$(echo "${COVERAGE} < 80" | bc)" -eq 1 ]; then
echo "::error::Coverage ${COVERAGE}% is below the 80% threshold"
if [ "$(echo "${COVERAGE} < 90" | bc)" -eq 1 ]; then
echo "::error::Coverage ${COVERAGE}% is below the 90% threshold"
exit 1
fi

Expand Down
17 changes: 17 additions & 0 deletions src/Infrastructure/Push/FcmPushGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,31 @@ public function send(string $fcmToken, string $alertId, string $fallTimestamp, ?
$payload = [
'message' => [
'token' => $fcmToken,
'notification' => [
'title' => 'Fall detected',
'body' => 'Tap to view and acknowledge the alert.',
],
'data' => $data,
'android' => [
'priority' => 'high',
'notification' => [
'channel_id' => 'fall_alerts',
'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
],
],
'apns' => [
'headers' => [
'apns-priority' => '10',
],
'payload' => [
'aps' => [
'alert' => [
'title' => 'Fall detected',
'body' => 'Tap to view and acknowledge the alert.',
],
'sound' => 'default',
],
],
],
],
];
Expand Down
13 changes: 7 additions & 6 deletions tests/Behat/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use RuntimeException;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface;

final class ApiContext implements Context
Expand Down Expand Up @@ -62,7 +63,7 @@ public function resetScenarioState(BeforeScenarioScope $scope): void
*/
public function iRegisterAProtectedPersonDevice(): void
{
$this->sendRequest('POST', '/api/v1/devices/register', [
$this->sendRequest(Request::METHOD_POST, '/api/v1/devices/register', [
'platform' => 'ios',
'appVersion' => '1.0.0',
]);
Expand All @@ -75,7 +76,7 @@ public function iRegisterAProtectedPersonDevice(): void
*/
public function iRegisterACaregiverDevice(): void
{
$this->sendRequest('POST', '/api/v1/devices/register', [
$this->sendRequest(Request::METHOD_POST, '/api/v1/devices/register', [
'platform' => 'android',
'appVersion' => '1.0.0',
'deviceType' => 'caregiver',
Expand Down Expand Up @@ -109,7 +110,7 @@ public function iAmAuthenticatedAsCaregiver(): void
*/
public function iSendAPostRequestTo(string $path): void
{
$this->sendRequest('POST', $this->interpolate($path), []);
$this->sendRequest(Request::METHOD_POST, $this->interpolate($path), []);
}

/**
Expand All @@ -119,7 +120,7 @@ public function iSendAPostRequestToWith(string $path, PyStringNode $body): void
{
/** @var array<mixed> $data */
$data = json_decode($body->getRaw(), true, 512, JSON_THROW_ON_ERROR);
$this->sendRequest('POST', $this->interpolate($path), $data);
$this->sendRequest(Request::METHOD_POST, $this->interpolate($path), $data);
}

/**
Expand All @@ -129,15 +130,15 @@ public function iSendAPutRequestToWith(string $path, PyStringNode $body): void
{
/** @var array<mixed> $data */
$data = json_decode($body->getRaw(), true, 512, JSON_THROW_ON_ERROR);
$this->sendRequest('PUT', $this->interpolate($path), $data);
$this->sendRequest(Request::METHOD_PUT, $this->interpolate($path), $data);
}

/**
* @When I send a GET request to :path
*/
public function iSendAGetRequestTo(string $path): void
{
$this->sendRequest('GET', $this->interpolate($path), null);
$this->sendRequest(Request::METHOD_GET, $this->interpolate($path), null);
}

// ─── Then ──────────────────────────────────────────────────────────────────
Expand Down
20 changes: 19 additions & 1 deletion tests/Unit/Infrastructure/FcmPushGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ public function itUsesBase64UrlEncodedJwtForOauthAssertion(): void
openssl_pkey_export($privateKey, $privateKeyPem);

$assertion = null;
$client = new MockHttpClient(static function (string $method, string $url, array $options) use (&$assertion): MockResponse {
$fcmPayload = null;
$client = new MockHttpClient(static function (string $method, string $url, array $options) use (&$assertion, &$fcmPayload): MockResponse {
if ('https://oauth2.googleapis.com/token' === $url) {
parse_str((string) $options['body'], $body);
$assertion = is_string($body['assertion'] ?? null) ? $body['assertion'] : null;

return new MockResponse(json_encode(['access_token' => 'access-token']) ?: '{}');
}

$decodedPayload = json_decode((string) $options['body'], true);
$fcmPayload = is_array($decodedPayload) ? $decodedPayload : null;

return new MockResponse(json_encode(['name' => 'projects/project-id/messages/message-id']) ?: '{}');
});

Expand All @@ -57,5 +61,19 @@ public function itUsesBase64UrlEncodedJwtForOauthAssertion(): void
foreach ($segments as $segment) {
self::assertDoesNotMatchRegularExpression('/[+=\/]/', $segment);
}

self::assertIsArray($fcmPayload);
self::assertSame(
'Fall detected',
$fcmPayload['message']['notification']['title'] ?? null,
);
self::assertSame(
'high',
$fcmPayload['message']['android']['priority'] ?? null,
);
self::assertSame(
'FLUTTER_NOTIFICATION_CLICK',
$fcmPayload['message']['android']['notification']['click_action'] ?? null,
);
}
}
Loading