Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AydinHassan committed Jul 11, 2024
1 parent 5d0aefa commit e4c946d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Command/UpdateShopsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#[AsCommand(
name: 'services:update-shops',
description: 'Add a short description for your command',
description: 'Inform all shops about the latest app version.',
)]
class UpdateShopsCommand extends Command
{
Expand All @@ -24,7 +24,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$io->success('Updating all shops with the latest manifest');
$io->success('Updating all shops with the latest app');

$this->shopUpdater->execute();

Expand Down
9 changes: 5 additions & 4 deletions src/Controller/LifecycleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function __construct(
private readonly AppZipper $appZipper,
) {}

#[Route('/service/lifecycle/choose-app', name: 'api.lifecycle.choose-app', methods: ['GET'])]
public function chooseApp(#[MapQueryParameter] string $shopwareVersion): Response
#[Route('/service/lifecycle/select-app', name: 'api.lifecycle.select-app', methods: ['GET'])]
public function selectApp(#[MapQueryParameter] string $shopwareVersion): Response
{
$app = $this->appSelector->select($shopwareVersion);

Expand Down Expand Up @@ -81,12 +81,13 @@ public function reportUpdate(WebhookAction $request): Response
public function serviceUpdateFinished(WebhookAction $request): Response
{
$version = $request->payload['appVersion'] ?? null;
$hash = $request->payload['appHash'] ?? null;

if (!is_string($version) || !is_string($hash)) {
if (!is_string($version)) {
return new Response(null, 422);
}

[$version, $hash] = explode('-', $version, 2);

$this->logger->info(sprintf('Service was updated for shop: "%s"', $request->shop->getShopId()), $request->payload);
/** @var Shop $shop */
$shop = $request->shop;
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/ShopUpdatedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
{
public function __construct(private ShopUpdater $shopUpdater) {}

public function __invoke(ShopUpdated $updateShopManifestMessage): void
public function __invoke(ShopUpdated $shopUpdatedMessage): void
{
$this->shopUpdater->run($updateShopManifestMessage->shopId, $updateShopManifestMessage->toVersion);
$this->shopUpdater->run($shopUpdatedMessage->shopId, $shopUpdatedMessage->toVersion);
}
}
11 changes: 7 additions & 4 deletions src/Resources/config/routing/lifecycle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="shopware_service_lifecycle_select_app" path="/service/lifecycle/select-app" methods="GET">
<default key="_controller">\Shopware\ServiceBundle\Controller\LifecycleController::selectApp</default>
</route>

<route id="shopware_service_lifecycle_app_zip" path="/service/lifecycle/app-zip/{version}" methods="GET">
<default key="_controller">\Shopware\ServiceBundle\Controller\LifecycleController::getAppZip</default>
</route>

<route id="shopware_service_lifecycle_update" path="/service/lifecycle/report-update" methods="POST">
<default key="_controller">\Shopware\ServiceBundle\Controller\LifecycleController::reportUpdate</default>
Expand All @@ -11,8 +18,4 @@
<route id="shopware_service_lifecycle_service_update_finished" path="/service/lifecycle/service-update-finished" methods="POST">
<default key="_controller">\Shopware\ServiceBundle\Controller\LifecycleController::serviceUpdateFinished</default>
</route>

<route id="shopware_service_lifecycle_app_zip" path="/service/lifecycle/app-zip/{version}" methods="GET">
<default key="_controller">\Shopware\ServiceBundle\Controller\LifecycleController::getAppZip</default>
</route>
</routes>
10 changes: 4 additions & 6 deletions tests/Controller/LifecycleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#[CoversClass(App::class)]
class LifecycleControllerTest extends TestCase
{
public function testChooseAppSelectAppropriateAppVersionAndReturnsInfo(): void
public function testSelectAppSelectAppropriateAppVersionAndReturnsInfo(): void
{
$appSelector = $this->createMock(AppSelector::class);
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
Expand All @@ -51,7 +51,7 @@ public function testChooseAppSelectAppropriateAppVersionAndReturnsInfo(): void
->with('shopware_service_lifecycle_app_zip', ['version' => '6.6.0.0'])
->willReturn('/download/link/for/app');

$response = $controller->chooseApp('6.6.0.0');
$response = $controller->selectApp('6.6.0.0');

static::assertEquals(200, $response->getStatusCode());
static::assertInstanceOf(JsonResponse::class, $response);
Expand Down Expand Up @@ -198,9 +198,7 @@ public static function updateFinishedInvalidPayloadProvider(): iterable

yield 'missing appVersion' => [['appHash' => 'aabbcc']];

yield 'missing appHash' => [['appVersion' => '2.0.0']];

yield 'wrong values' => [['appVersion' => 1, 'appHash' => null]];
yield 'wrong values' => [['appVersion' => 1]];
}

/**
Expand Down Expand Up @@ -270,7 +268,7 @@ public function testServiceUpdateFinishedMarksShopAsUpdated(): void
$shop,
new ActionSource('https://shop.com', '2.0.0'),
'shopware.service.updated',
['appVersion' => '2.0.0', 'appHash' => 'aabbcc'],
['appVersion' => '2.0.0-aabbcc'],
new \DateTimeImmutable(),
);

Expand Down

0 comments on commit e4c946d

Please sign in to comment.