diff --git a/tests/Model/Generated/Object/NotificationUrlTest.php b/tests/Model/Generated/Object/NotificationUrlTest.php index 47517c0f..a347ca81 100644 --- a/tests/Model/Generated/Object/NotificationUrlTest.php +++ b/tests/Model/Generated/Object/NotificationUrlTest.php @@ -4,6 +4,7 @@ use bunq\Exception\BunqException; use bunq\Model\Core\BunqModel; +use bunq\Model\Generated\Endpoint\BunqMeTab; use bunq\Model\Generated\Endpoint\Payment; use bunq\Model\Generated\Object\NotificationUrl; use bunq\test\BunqSdkTestBase; @@ -20,11 +21,12 @@ class NotificationUrlTest extends BunqSdkTestBase */ const BASE_PATH_JSON_MODEL = __DIR__ . '/../../../resource/NotificationUrlJsons'; const JSON_PATH_MUTATION_MODEL = self::BASE_PATH_JSON_MODEL . '/Mutation.json'; + const JSON_PATH_BUNQ_ME_TAB_MODEL = self::BASE_PATH_JSON_MODEL . '/BunqMeTab.json'; /** * Model root key. */ - const KEY_NOTFICATION_URL_MODEL = 'NotificationUrl'; + const KEY_NOTIFICATION_URL_MODEL = 'NotificationUrl'; const KEY_MUTATION_MODEL = ''; /** @@ -32,10 +34,7 @@ class NotificationUrlTest extends BunqSdkTestBase public function testMutationModel() { $jsonString = FileUtil::getFileContents(self::JSON_PATH_MUTATION_MODEL); - $json = json_decode($jsonString, true); - $notificationObject = $this->getNotificationObjectAsString($json); - $notificationUrl = NotificationUrl::fromJsonToModel($notificationObject); - $notificationUrl = self::assertInstanceOfNotificationUrl($notificationUrl); + $notificationUrl = $this->getNotificationUrlFromJson($jsonString); $paymentModel = $notificationUrl->getObject()->getPayment(); $referencedPaymentModel = $notificationUrl->getObject()->getReferencedObject(); @@ -45,6 +44,36 @@ public function testMutationModel() static::assertInstanceOf(Payment::class, $referencedPaymentModel); } + /** + */ + public function testBunqMeTabModel() + { + $jsonString = FileUtil::getFileContents(self::JSON_PATH_BUNQ_ME_TAB_MODEL); + $notificationUrl = $this->getNotificationUrlFromJson($jsonString); + + $bunqMeTabModel = $notificationUrl->getObject()->getBunqMeTab(); + $referencedBunqMeTabModel = $notificationUrl->getObject()->getReferencedObject(); + + $this->assetReferencedModelIsNotNull($bunqMeTabModel); + $this->assetReferencedModelIsNotNull($referencedBunqMeTabModel); + static::assertInstanceOf(BunqMeTab::class, $referencedBunqMeTabModel); + } + + /** + * @param string $jsonString + * + * @return NotificationUrl + */ + private function getNotificationUrlFromJson(string $jsonString): NotificationUrl + { + $json = json_decode($jsonString, true); + static::assertNotNull($json, 'Might be that the JSON file is not a valid json.'); + $notificationObject = $this->getNotificationObjectAsString($json); + $notificationUrl = NotificationUrl::fromJsonToModel($notificationObject); + + return self::assertInstanceOfNotificationUrl($notificationUrl); + } + /** * @param BunqModel $model */ @@ -79,7 +108,7 @@ private function getNotificationObjectAsString(array $json) { $this->assertJsonIsNotificationUrlJson($json); - return json_encode($json[self::KEY_NOTFICATION_URL_MODEL]); + return json_encode($json[self::KEY_NOTIFICATION_URL_MODEL]); } /** @@ -87,6 +116,6 @@ private function getNotificationObjectAsString(array $json) */ private function assertJsonIsNotificationUrlJson(array $json) { - static::assertArrayHasKey(self::KEY_NOTFICATION_URL_MODEL, $json); + static::assertArrayHasKey(self::KEY_NOTIFICATION_URL_MODEL, $json); } -} \ No newline at end of file +} diff --git a/tests/resource/NotificationUrlJsons/BunqMeTab.json b/tests/resource/NotificationUrlJsons/BunqMeTab.json new file mode 100644 index 00000000..20948581 --- /dev/null +++ b/tests/resource/NotificationUrlJsons/BunqMeTab.json @@ -0,0 +1,77 @@ +{ + "NotificationUrl": { + "target_url": "nope", + "category": "BUNQME_TAB", + "event_type": "BUNQME_TAB_CREATED", + "object": { + "BunqMeTab": { + "id": 8, + "created": "2017-11-09 11:05:42.364451", + "updated": "2017-11-09 11:05:42.364451", + "time_expiry": "2017-12-09 11:05:42.361442", + "monetary_account_id": 32, + "status": "WAITING_FOR_PAYMENT", + "bunqme_tab_share_url": "https:\/\/bunq.me\/t\/4da1167c-01bc-4a91-a1e1-44a83e4fef2e", + "bunqme_tab_entry": { + "uuid": "4da1167c-01bc-4a91-a1e1-44a83e4fef2e", + "created": "2017-11-09 11:05:42.450462", + "updated": "2017-11-09 11:05:42.450462", + "amount_inquired": { + "currency": "EUR", + "value": "5.00" + }, + "status": "WAITING_FOR_PAYMENT", + "description": "Thank you for building this awesome feature!", + "alias": { + "iban": "NL18BUNQ2025104340", + "is_light": false, + "display_name": "B.O. Varb", + "avatar": { + "uuid": "b0005448-e385-4d6c-baef-244c295b524f", + "image": [ + { + "attachment_public_uuid": "0c872c0e-1c98-4eea-ba75-a36c6d0a40c7", + "height": 1024, + "width": 1024, + "content_type": "image\/png" + } + ], + "anchor_uuid": null + }, + "label_user": { + "uuid": "353f4064-96bd-49d7-ac69-f87513726c80", + "display_name": "B.O. Varb", + "country": "NL", + "avatar": { + "uuid": "ec2dc709-c8dd-4868-b3e7-601338d88881", + "image": [ + { + "attachment_public_uuid": "7444998c-ff1d-4708-afe3-7b56e33c6f89", + "height": 480, + "width": 480, + "content_type": "image\/jpeg" + } + ], + "anchor_uuid": "353f4064-96bd-49d7-ac69-f87513726c80" + }, + "public_nick_name": "Bravo O (nickname)" + }, + "country": "NL" + }, + "redirect_url": null, + "merchant_available": [ + { + "merchant_type": "IDEAL", + "available": true + }, + { + "merchant_type": "SOFORT", + "available": true + } + ] + }, + "result_inquiries": [] + } + } + } +} \ No newline at end of file diff --git a/tests/resource/NotificationUrlJsons/Mutation.json b/tests/resource/NotificationUrlJsons/Mutation.json index d680763e..2dd85f34 100644 --- a/tests/resource/NotificationUrlJsons/Mutation.json +++ b/tests/resource/NotificationUrlJsons/Mutation.json @@ -1,5 +1,6 @@ -{"NotificationUrl": { - "target_url": "https:\/\/develop.bunq.com\/callback.php?email=khellemun@bunq.com", +{ + "NotificationUrl": { + "target_url|tu": "nope", "category": "MUTATION", "event_type": "MUTATION_CREATED", "object": {