Skip to content

Commit b38765a

Browse files
mstegmeyercyl3x
andauthored
fix: incorrect IAP detail result (#106)
* fix: incorrect IAP detail result * fix: remove debugging * test: add unit test * fix: cs * chore: update composer version --------- Co-authored-by: Michel <m.bade@shopware.com>
1 parent 5eb70fd commit b38765a

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swag/swag-extension-store",
3-
"version": "4.0.4",
3+
"version": "4.0.5",
44
"description": "SWAG Extension Store",
55
"type": "shopware-platform-plugin",
66
"license": "MIT",

src/Controller/InAppPurchasesController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ public function getInAppPurchaseDetails(string $technicalName, Context $context)
5151

5252
$extension = $this->extensionDataProvider
5353
->getInstalledExtensions($context, false, $criteria)
54-
->first();
54+
->get($technicalName);
55+
56+
if (!$extension) {
57+
throw ExtensionStoreException::unknownExtension($technicalName);
58+
}
5559

5660
return new JsonResponse($extension);
5761
}

src/Exception/ExtensionStoreException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,14 @@ public static function invalidInAppPurchase(): self
4848
'The extension provider disallowed your purchase. Please contact the extension provider.',
4949
);
5050
}
51+
52+
public static function unknownExtension(string $technicalName): self
53+
{
54+
return new self(
55+
Response::HTTP_NOT_FOUND,
56+
'FRAMEWORK__UNKNOWN_EXTENSION',
57+
'The extension with technical name "{{ technicalName }}" is not known.',
58+
['technicalName' => $technicalName],
59+
);
60+
}
5161
}

tests/Controller/InAppPurchasesControllerTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ public function testGetInAppFeature(): void
3333
{
3434
$extension = new ExtensionStruct();
3535
$extension->setName('testExtension');
36+
$otherExtension = new ExtensionStruct();
37+
$otherExtension->setName('otherExtension');
3638
$service = $this->createMock(InAppPurchasesService::class);
3739
$dataProvider = $this->createMock(AbstractExtensionDataProvider::class);
3840
$dataProvider->expects(static::once())
3941
->method('getInstalledExtensions')
40-
->willReturn(new ExtensionCollection([$extension]));
42+
->willReturn(new ExtensionCollection([
43+
'otherExtension' => $otherExtension,
44+
'testExtension' => $extension,
45+
]));
4146

4247
$controller = new InAppPurchasesController(
4348
$service,
@@ -54,6 +59,30 @@ public function testGetInAppFeature(): void
5459
static::assertSame('testExtension', $content['name']);
5560
}
5661

62+
public function testGetInAppFeatureWithUnknownExtension(): void
63+
{
64+
$extension = new ExtensionStruct();
65+
$extension->setName('testExtension');
66+
$service = $this->createMock(InAppPurchasesService::class);
67+
$dataProvider = $this->createMock(AbstractExtensionDataProvider::class);
68+
$dataProvider->expects(static::once())
69+
->method('getInstalledExtensions')
70+
->willReturn(new ExtensionCollection(['testExtension' => $extension]));
71+
72+
$controller = new InAppPurchasesController(
73+
$service,
74+
$this->createMock(InAppPurchaseUpdater::class),
75+
$dataProvider,
76+
$this->createMock(InAppPurchasesGateway::class),
77+
$this->createMock(EntityRepository::class),
78+
);
79+
80+
$this->expectException(ExtensionStoreException::class);
81+
$this->expectExceptionMessage('The extension with technical name "otherExtension" is not known.');
82+
83+
$controller->getInAppPurchaseDetails('otherExtension', Context::createDefaultContext());
84+
}
85+
5786
public function testCreateCart(): void
5887
{
5988
$cartStruct = $this->getInAppPurchaseCartStruct();

0 commit comments

Comments
 (0)