Skip to content

Commit

Permalink
Added DraftPayment to NotificatoinUrl test. #67
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Nov 9, 2017
1 parent bcd36e2 commit 3ab1673
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 46 deletions.
73 changes: 40 additions & 33 deletions tests/Model/Generated/Object/NotificationUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use bunq\Exception\BunqException;
use bunq\Model\Core\BunqModel;
use bunq\Model\Generated\Endpoint\BunqMeTab;
use bunq\Model\Generated\Endpoint\ChatMessage;
use bunq\Model\Generated\Endpoint\DraftPayment;
use bunq\Model\Generated\Endpoint\Payment;
use bunq\Model\Generated\Object\NotificationUrl;
use bunq\test\BunqSdkTestBase;
Expand All @@ -16,6 +18,14 @@
*/
class NotificationUrlTest extends BunqSdkTestBase
{
/**
* Getter string constants
*/
const GET_PAYMENT = 'getPayment';
const GET_BUNQ_ME_TAB = 'getBunqMeTab';
const GET_CHAT_MESSAGE = 'getChatMessage';
const GET_DRAFT_PAYMENT = 'getDraftPayment';

/**
* Assertion errors.
*/
Expand All @@ -29,6 +39,7 @@ class NotificationUrlTest extends BunqSdkTestBase
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';
const JSON_PATH_CHAT_MESSAGE_MODEL = self::BASE_PATH_JSON_MODEL . '/ChatMessage.json';
const JSON_PATH_DRAFT_PAYMENT_MODEL = self::BASE_PATH_JSON_MODEL . '/DraftPayment.json';

/**
* Model root key.
Expand All @@ -37,48 +48,49 @@ class NotificationUrlTest extends BunqSdkTestBase
const KEY_MUTATION_MODEL = '';

/**
* @param string $fileName
* @param string $className
* @param string $getterName
*/
public function testMutationModel()
private function executeTest(string $fileName, string $className, string $getterName)
{
$jsonString = FileUtil::getFileContents(self::JSON_PATH_MUTATION_MODEL);
$jsonString = FileUtil::getFileContents($fileName);
$notificationUrl = $this->getNotificationUrlFromJson($jsonString);

$paymentModel = $notificationUrl->getObject()->getPayment();
$referencedPaymentModel = $notificationUrl->getObject()->getReferencedObject();
$model = $notificationUrl->getObject()->$getterName();
$referencedModel = $notificationUrl->getObject()->getReferencedObject();

$this->assetReferencedModelIsNotNull($paymentModel);
$this->assetReferencedModelIsNotNull($referencedPaymentModel);
static::assertInstanceOf(Payment::class, $referencedPaymentModel);
static::assertNotNull($model);
static::assertNotNull($referencedModel);
static::assertInstanceOf($className, $referencedModel);
}

/**
*/
public function testBunqMeTabModel()
public function testMutationModel()
{
$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);
$this->executeTest(self::JSON_PATH_MUTATION_MODEL, Payment::class, self::GET_PAYMENT);
}

/**
*/
public function testChatMessageModel()
public function testBunqMeTabModel()
{
$jsonString = FileUtil::getFileContents(self::JSON_PATH_CHAT_MESSAGE_MODEL);
$notificationUrl = $this->getNotificationUrlFromJson($jsonString);
$this->executeTest(self::JSON_PATH_BUNQ_ME_TAB_MODEL, BunqMeTab::class, self::GET_BUNQ_ME_TAB);
}

$chatMessageModel = $notificationUrl->getObject()->getChatMessage();
$referencedChatMessageModel = $notificationUrl->getObject()->getReferencedObject();
///**
// */
//public function testChatMessageModel()
//{
// $this->executeTest(self::JSON_PATH_CHAT_MESSAGE_MODEL, ChatMessage::class, self::GET_CHAT_MESSAGE);
//}

$this->assetReferencedModelIsNotNull($chatMessageModel);
$this->assetReferencedModelIsNotNull($referencedChatMessageModel);
static::assertInstanceOf(BunqMeTab::class, $referencedChatMessageModel);
/**
*/
public function testDraftPaymentModel()
{
$this->executeTest(self::JSON_PATH_DRAFT_PAYMENT_MODEL, DraftPayment::class, self::GET_DRAFT_PAYMENT);
}

/**
Expand All @@ -92,16 +104,11 @@ private function getNotificationUrlFromJson(string $jsonString): NotificationUrl
static::assertNotNull($json, self::ASSERT_JSON_DECODE_ERROR);
$notificationObject = $this->getNotificationObjectAsString($json);
$notificationUrl = NotificationUrl::fromJsonToModel($notificationObject);
$notificationUrl = self::assertInstanceOfNotificationUrl($notificationUrl);

return self::assertInstanceOfNotificationUrl($notificationUrl);
}
static::assertNotNull($notificationUrl->getObject());

/**
* @param BunqModel $model
*/
private function assetReferencedModelIsNotNull(BunqModel $model)
{
static::assertNotNull($model);
return $notificationUrl;
}

/**
Expand Down
25 changes: 12 additions & 13 deletions tests/resource/NotificationUrlJsons/ChatMessage.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"NotificationUrl": {
"target_url|tu": "nope",
"category|c": "BUNQME_TAB",
"event_type|et": "BUNQME_TAB_CREATED",
"object|o": {
{"NotificationUrl": {
"target_url": "nope",
"category": "BUNQME_TAB",
"event_type": "BUNQME_TAB_CREATED",
"object": {
"ChatMessageAnnouncement": {
"id|i": 30,
"created|ct": "2017-09-05 12:00:00.912674",
"updated|ut": "2017-09-05 12:00:00.912674",
"conversation_id|ci": 3,
"content|con": {
"id": 30,
"created": "2017-09-05 12:00:00.912674",
"updated": "2017-09-05 12:00:00.912674",
"conversation_id": 3,
"content": {
"ChatMessageContentText": {
"text|t": "Hey! You have failed to pay more than five direct debits over the past 30 days. Although such things can happen, please keep in mind that we might be forced to take measures if we get a lot of complaints about it. To help prevent this we summarised some information which might prove useful.\n\nRead more here. https:\/\/www.bunq.com\/en\/direct-debits\/\n\nPlease let us know if you have any further questions, we would love to help you out!"
"text": "Hey! You have failed to pay more than five direct debits over the past 30 days. Although such things can happen, please keep in mind that we might be forced to take measures if we get a lot of complaints about it. To help prevent this we summarised some information which might prove useful.\n\nRead more here. https:\/\/www.bunq.com\/en\/direct-debits\/\n\nPlease let us know if you have any further questions, we would love to help you out!"
}
},
"client_message_uuid|cmu": null
"client_message_uuid": null
}
}
}
Expand Down
202 changes: 202 additions & 0 deletions tests/resource/NotificationUrlJsons/DraftPayment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{"NotificationUrl": {
"target_url": "https:\/\/develop.bunq.com\/callback.php?email=khellemun@bunq.com",
"category": "DRAFT_PAYMENT",
"event_type": "DRAFT_PAYMENT_ACCEPTED",
"object": {
"DraftPayment": {
"id": 1,
"created": "2017-07-13 21:44:31.314437",
"updated": "2017-07-13 21:44:31.314437",
"monetary_account_id": 42,
"status": "PENDING",
"type": "BUNQ",
"user_alias_created": {
"uuid": "fbff5c27-e5c1-44c6-be6f-ddd2c6615bf5",
"display_name": "G. Mason",
"country": "NL",
"avatar": {
"uuid": "4605580d-014c-42f1-a4d4-7b398f3b37e5",
"image": [
{
"attachment_public_uuid": "d6b930f4-1fd0-4b29-8455-e900ed0aced5",
"height": 480,
"width": 480,
"content_type": "image\/jpeg"
}
],
"anchor_uuid": "fbff5c27-e5c1-44c6-be6f-ddd2c6615bf5"
},
"public_nick_name": "Griffin (nickname)"
},
"responses": null,
"entries": [
{
"amount": {
"currency": "EUR",
"value": "46.26"
},
"alias": {
"iban": "NL16BUNQ2025103794",
"is_light": false,
"display_name": "G. Mason",
"avatar": {
"uuid": "e3bc865a-83a8-4788-af62-4f0c38df8f0d",
"image": [
{
"attachment_public_uuid": "62c88a57-3cd9-49f7-81dc-8f1a4fcc80ac",
"height": 1024,
"width": 1024,
"content_type": "image\/png"
}
],
"anchor_uuid": null
},
"label_user": {
"uuid": "fbff5c27-e5c1-44c6-be6f-ddd2c6615bf5",
"display_name": "G. Mason",
"country": "NL",
"avatar": {
"uuid": "4605580d-014c-42f1-a4d4-7b398f3b37e5",
"image": [
{
"attachment_public_uuid": "d6b930f4-1fd0-4b29-8455-e900ed0aced5",
"height": 480,
"width": 480,
"content_type": "image\/jpeg"
}
],
"anchor_uuid": "fbff5c27-e5c1-44c6-be6f-ddd2c6615bf5"
},
"public_nick_name": "Griffin (nickname)"
},
"country": "NL"
},
"counterparty_alias": {
"iban": "NL49BUNQ2025104073",
"is_light": false,
"display_name": "Echo (nickname)",
"avatar": {
"uuid": "11ec9a66-3c18-4711-8586-36f32e262830",
"image": [
{
"attachment_public_uuid": "63eb3676-058a-45f0-b81d-8b26ee2e4f21",
"height": 1024,
"width": 1024,
"content_type": "image\/png"
}
],
"anchor_uuid": null
},
"label_user": {
"uuid": "688e4bdc-ec27-4d8e-942b-3aee7b5d15e9",
"display_name": "Echo (nickname)",
"country": "NL",
"avatar": {
"uuid": "3da21898-1535-43c9-9023-83333e776b8b",
"image": [
{
"attachment_public_uuid": "6bb2b5d6-faee-4d5d-8284-af026bde3640",
"height": 480,
"width": 480,
"content_type": "image\/jpeg"
}
],
"anchor_uuid": "688e4bdc-ec27-4d8e-942b-3aee7b5d15e9"
},
"public_nick_name": "Echo (nickname)"
},
"country": "NL"
},
"description": "Test payment to NL49BUNQ2025104073",
"type": "BUNQ",
"attachment": [],
"merchant_reference": null
},
{
"amount": {
"currency": "EUR",
"value": "2.56"
},
"alias": {
"iban": "NL16BUNQ2025103794",
"is_light": false,
"display_name": "G. Mason",
"avatar": {
"uuid": "e3bc865a-83a8-4788-af62-4f0c38df8f0d",
"image": [
{
"attachment_public_uuid": "62c88a57-3cd9-49f7-81dc-8f1a4fcc80ac",
"height": 1024,
"width": 1024,
"content_type": "image\/png"
}
],
"anchor_uuid": null
},
"label_user": {
"uuid": "fbff5c27-e5c1-44c6-be6f-ddd2c6615bf5",
"display_name": "G. Mason",
"country": "NL",
"avatar": {
"uuid": "4605580d-014c-42f1-a4d4-7b398f3b37e5",
"image": [
{
"attachment_public_uuid": "d6b930f4-1fd0-4b29-8455-e900ed0aced5",
"height": 480,
"width": 480,
"content_type": "image\/jpeg"
}
],
"anchor_uuid": "fbff5c27-e5c1-44c6-be6f-ddd2c6615bf5"
},
"public_nick_name": "Griffin (nickname)"
},
"country": "NL"
},
"counterparty_alias": {
"iban": "NL32BUNQ2025103506",
"is_light": false,
"display_name": "Niels (nickname)",
"avatar": {
"uuid": "e47f5214-2198-4605-886c-9950714476f3",
"image": [
{
"attachment_public_uuid": "3c7d4d11-d203-4ed4-b471-5b5e24079bf6",
"height": 1024,
"width": 1024,
"content_type": "image\/png"
}
],
"anchor_uuid": null
},
"label_user": {
"uuid": "398e4411-6d98-40b9-bb48-9b33a4cb82da",
"display_name": "Niels (nickname)",
"country": "NL",
"avatar": {
"uuid": "ad92c001-a4ec-4344-89ad-bf6a6b0e5628",
"image": [
{
"attachment_public_uuid": "2b7bc30e-d6af-4440-90ba-a801cba3d8d7",
"height": 480,
"width": 480,
"content_type": "image\/jpeg"
}
],
"anchor_uuid": "398e4411-6d98-40b9-bb48-9b33a4cb82da"
},
"public_nick_name": "Niels (nickname)"
},
"country": "NL"
},
"description": "Test payment to NL32BUNQ2025103506",
"type": "BUNQ",
"attachment": [],
"merchant_reference": null
}
],
"object": null
}
}
}
}

0 comments on commit 3ab1673

Please sign in to comment.