Skip to content

Commit

Permalink
Added bunq me tab NotificatoinUrl test. #67
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Nov 9, 2017
1 parent 7a2ced1 commit e4e53d9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 10 deletions.
45 changes: 37 additions & 8 deletions tests/Model/Generated/Object/NotificationUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,22 +21,20 @@ 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 = '';

/**
*/
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();
Expand All @@ -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
*/
Expand Down Expand Up @@ -79,14 +108,14 @@ 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]);
}

/**
* @param array $json
*/
private function assertJsonIsNotificationUrlJson(array $json)
{
static::assertArrayHasKey(self::KEY_NOTFICATION_URL_MODEL, $json);
static::assertArrayHasKey(self::KEY_NOTIFICATION_URL_MODEL, $json);
}
}
}
77 changes: 77 additions & 0 deletions tests/resource/NotificationUrlJsons/BunqMeTab.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}
}
}
5 changes: 3 additions & 2 deletions tests/resource/NotificationUrlJsons/Mutation.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit e4e53d9

Please sign in to comment.