diff --git a/.fern/metadata.json b/.fern/metadata.json index b984b84..4e4a7d0 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -1,5 +1,5 @@ { - "cliVersion": "4.43.1", + "cliVersion": "4.46.0", "generatorName": "fernapi/fern-php-sdk", "generatorVersion": "2.2.3", "generatorConfig": { @@ -14,12 +14,12 @@ }, "license": "MIT" }, - "enable-wire-tests": false, + "enable-wire-tests": true, "propertyAccess": "public", "packageName": "getbrevo/brevo-php", "generateClientInterfaces": true, "useDefaultRequestParameterValues": true }, - "originGitCommit": "7d08ac3fbe2aa66ba3d56077e8582739d530298b", - "sdkVersion": "4.0.11" + "originGitCommit": "f25a5c52b4f8c7fb0eab7532cf4d3032bce1c05c", + "sdkVersion": "4.0.12" } \ No newline at end of file diff --git a/composer.json b/composer.json index 2ba0e42..90e3fce 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "getbrevo/brevo-php", - "version": "4.0.11", + "version": "4.0.12", "description": "Official PHP SDK for the Brevo API.", "keywords": [ "brevo", diff --git a/phpunit.xml b/phpunit.xml index 54630a5..718cb50 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ - + tests - \ No newline at end of file + diff --git a/src/Brevo.php b/src/Brevo.php index 0a355af..5980504 100644 --- a/src/Brevo.php +++ b/src/Brevo.php @@ -265,8 +265,8 @@ public function __construct( 'api-key' => $apiKey, 'X-Fern-Language' => 'PHP', 'X-Fern-SDK-Name' => 'Brevo', - 'X-Fern-SDK-Version' => '4.0.11', - 'User-Agent' => 'getbrevo/brevo-php/4.0.11', + 'X-Fern-SDK-Version' => '4.0.12', + 'User-Agent' => 'getbrevo/brevo-php/4.0.12', ]; $this->options = $options ?? []; diff --git a/src/Ecommerce/Types/CreateBatchOrderResponse.php b/src/Ecommerce/Types/CreateBatchOrderResponse.php index bfbf821..5e55c20 100644 --- a/src/Ecommerce/Types/CreateBatchOrderResponse.php +++ b/src/Ecommerce/Types/CreateBatchOrderResponse.php @@ -7,18 +7,18 @@ class CreateBatchOrderResponse extends JsonSerializableType { - /** - * @var float $batchId Batch ID of the request - */ - #[JsonProperty('batchId')] - public float $batchId; - /** * @var ?int $count Number of orders */ #[JsonProperty('count')] public ?int $count; + /** + * @var float $batchId Batch ID of the request + */ + #[JsonProperty('batch_id')] + public float $batchId; + /** * @param array{ * batchId: float, @@ -28,8 +28,8 @@ class CreateBatchOrderResponse extends JsonSerializableType public function __construct( array $values, ) { - $this->batchId = $values['batchId']; $this->count = $values['count'] ?? null; + $this->batchId = $values['batchId']; } /** diff --git a/tests/Wire/AccountWireTest.php b/tests/Wire/AccountWireTest.php new file mode 100644 index 0000000..484dd93 --- /dev/null +++ b/tests/Wire/AccountWireTest.php @@ -0,0 +1,69 @@ +client->account->getAccount( + [ + 'headers' => [ + 'X-Test-Id' => 'account.get_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/account", + null, + 1 + ); + } + + /** + */ + public function testGetAccountActivity(): void { + $testId = 'account.get_account_activity.0'; + $this->client->account->getAccountActivity( + new GetAccountActivityRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'account.get_account_activity.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/organization/activities", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/BalanceWireTest.php b/tests/Wire/BalanceWireTest.php new file mode 100644 index 0000000..39c79c9 --- /dev/null +++ b/tests/Wire/BalanceWireTest.php @@ -0,0 +1,490 @@ +client->balance->getActiveBalancesApi( + 'pid', + new GetLoyaltyBalanceProgramsPidActiveBalanceRequest([ + 'contactId' => 1, + 'balanceDefinitionId' => 'balance_definition_id', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_active_balances_api.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/active-balance", + ['contact_id' => '1', 'balance_definition_id' => 'balance_definition_id'], + 1 + ); + } + + /** + */ + public function testGetBalanceDefinitionList(): void { + $testId = 'balance.get_balance_definition_list.0'; + $this->client->balance->getBalanceDefinitionList( + 'pid', + new GetBalanceDefinitionListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_balance_definition_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/balance-definitions", + null, + 1 + ); + } + + /** + */ + public function testCreateBalanceDefinition(): void { + $testId = 'balance.create_balance_definition.0'; + $this->client->balance->createBalanceDefinition( + 'pid', + new PostLoyaltyBalanceProgramsPidBalanceDefinitionsRequest([ + 'name' => 'name', + 'unit' => PostLoyaltyBalanceProgramsPidBalanceDefinitionsRequestUnit::Points->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.create_balance_definition.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/balance-definitions", + null, + 1 + ); + } + + /** + */ + public function testGetBalanceDefinition(): void { + $testId = 'balance.get_balance_definition.0'; + $this->client->balance->getBalanceDefinition( + 'pid', + 'bdid', + new GetBalanceDefinitionRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_balance_definition.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/balance-definitions/bdid", + null, + 1 + ); + } + + /** + */ + public function testUpdateBalanceDefinition(): void { + $testId = 'balance.update_balance_definition.0'; + $this->client->balance->updateBalanceDefinition( + 'pid', + 'bdid', + new UpdateBalanceDefinitionRequest([ + 'name' => 'name', + 'unit' => UpdateBalanceDefinitionRequestUnit::Points->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.update_balance_definition.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/loyalty/balance/programs/pid/balance-definitions/bdid", + null, + 1 + ); + } + + /** + */ + public function testDeleteBalanceDefinition(): void { + $testId = 'balance.delete_balance_definition.0'; + $this->client->balance->deleteBalanceDefinition( + 'pid', + 'bdid', + [ + 'headers' => [ + 'X-Test-Id' => 'balance.delete_balance_definition.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/balance/programs/pid/balance-definitions/bdid", + null, + 1 + ); + } + + /** + */ + public function testCreateBalanceLimit(): void { + $testId = 'balance.create_balance_limit.0'; + $this->client->balance->createBalanceLimit( + 'pid', + 'bdid', + new CreateBalanceLimitRequest([ + 'constraintType' => CreateBalanceLimitRequestConstraintType::Transaction->value, + 'durationUnit' => CreateBalanceLimitRequestDurationUnit::Day->value, + 'durationValue' => 1, + 'transactionType' => CreateBalanceLimitRequestTransactionType::Credit->value, + 'value' => 1, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.create_balance_limit.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/balance-definitions/bdid/limits", + null, + 1 + ); + } + + /** + */ + public function testGetBalanceLimit(): void { + $testId = 'balance.get_balance_limit.0'; + $this->client->balance->getBalanceLimit( + 'pid', + 'bdid', + 'blid', + new GetBalanceLimitRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_balance_limit.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/balance-definitions/bdid/limits/blid", + null, + 1 + ); + } + + /** + */ + public function testUpdateBalanceLimit(): void { + $testId = 'balance.update_balance_limit.0'; + $this->client->balance->updateBalanceLimit( + 'pid', + 'bdid', + 'blid', + new UpdateBalanceLimitRequest([ + 'constraintType' => UpdateBalanceLimitRequestConstraintType::Transaction->value, + 'durationUnit' => UpdateBalanceLimitRequestDurationUnit::Day->value, + 'durationValue' => 1, + 'transactionType' => UpdateBalanceLimitRequestTransactionType::Credit->value, + 'value' => 1, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.update_balance_limit.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/loyalty/balance/programs/pid/balance-definitions/bdid/limits/blid", + null, + 1 + ); + } + + /** + */ + public function testDeleteBalanceLimit(): void { + $testId = 'balance.delete_balance_limit.0'; + $this->client->balance->deleteBalanceLimit( + 'pid', + 'bdid', + 'blid', + [ + 'headers' => [ + 'X-Test-Id' => 'balance.delete_balance_limit.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/balance/programs/pid/balance-definitions/bdid/limits/blid", + null, + 1 + ); + } + + /** + */ + public function testGetContactBalances(): void { + $testId = 'balance.get_contact_balances.0'; + $this->client->balance->getContactBalances( + 'pid', + new GetContactBalancesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_contact_balances.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/contact-balances", + null, + 1 + ); + } + + /** + */ + public function testCreateBalanceOrder(): void { + $testId = 'balance.create_balance_order.0'; + $this->client->balance->createBalanceOrder( + 'pid', + new CreateBalanceOrderRequest([ + 'amount' => 1.1, + 'balanceDefinitionId' => 'balanceDefinitionId', + 'contactId' => 1, + 'dueAt' => 'dueAt', + 'source' => 'source', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.create_balance_order.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/create-order", + null, + 1 + ); + } + + /** + */ + public function testGetSubscriptionBalances(): void { + $testId = 'balance.get_subscription_balances.0'; + $this->client->balance->getSubscriptionBalances( + 'pid', + 'cid', + new GetSubscriptionBalancesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_subscription_balances.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/subscriptions/cid/balances", + null, + 1 + ); + } + + /** + */ + public function testCreateSubscriptionBalances(): void { + $testId = 'balance.create_subscription_balances.0'; + $this->client->balance->createSubscriptionBalances( + 'pid', + 'cid', + new PostLoyaltyBalanceProgramsPidSubscriptionsCidBalancesRequest([ + 'balanceDefinitionId' => 'balanceDefinitionId', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.create_subscription_balances.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/subscriptions/cid/balances", + null, + 1 + ); + } + + /** + */ + public function testGetTransactionHistoryApi(): void { + $testId = 'balance.get_transaction_history_api.0'; + $this->client->balance->getTransactionHistoryApi( + 'pid', + new GetLoyaltyBalanceProgramsPidTransactionHistoryRequest([ + 'contactId' => 1, + 'balanceDefinitionId' => 'balanceDefinitionId', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.get_transaction_history_api.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/balance/programs/pid/transaction-history", + ['contactId' => '1', 'balanceDefinitionId' => 'balanceDefinitionId'], + 1 + ); + } + + /** + */ + public function testBeginTransaction(): void { + $testId = 'balance.begin_transaction.0'; + $this->client->balance->beginTransaction( + 'pid', + new BeginTransactionRequest([ + 'amount' => 1.1, + 'balanceDefinitionId' => 'balanceDefinitionId', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'balance.begin_transaction.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/transactions", + null, + 1 + ); + } + + /** + */ + public function testCancelTransaction(): void { + $testId = 'balance.cancel_transaction.0'; + $this->client->balance->cancelTransaction( + 'pid', + 'tid', + [ + 'headers' => [ + 'X-Test-Id' => 'balance.cancel_transaction.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/transactions/tid/cancel", + null, + 1 + ); + } + + /** + */ + public function testCompleteTransaction(): void { + $testId = 'balance.complete_transaction.0'; + $this->client->balance->completeTransaction( + 'pid', + 'tid', + [ + 'headers' => [ + 'X-Test-Id' => 'balance.complete_transaction.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/balance/programs/pid/transactions/tid/complete", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/CompaniesWireTest.php b/tests/Wire/CompaniesWireTest.php new file mode 100644 index 0000000..a3d9a00 --- /dev/null +++ b/tests/Wire/CompaniesWireTest.php @@ -0,0 +1,278 @@ +client->companies->getAllCompanies( + new GetCompaniesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.get_all_companies.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/companies", + null, + 1 + ); + } + + /** + */ + public function testCreateACompany(): void { + $testId = 'companies.create_a_company.0'; + $this->client->companies->createACompany( + new PostCompaniesRequest([ + 'name' => 'company', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.create_a_company.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/companies", + null, + 1 + ); + } + + /** + */ + public function testImportCompaniesCreationAndUpdation(): void { + $testId = 'companies.import_companies_creation_and_updation.0'; + $this->client->companies->importCompaniesCreationAndUpdation( + new PostCompaniesImportRequest([ + 'file' => File::createFromString("example_file", "example_file"), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.import_companies_creation_and_updation.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/companies/import", + null, + 1 + ); + } + + /** + */ + public function testLinkAndUnlinkCompanyWithContactAndDeal(): void { + $testId = 'companies.link_and_unlink_company_with_contact_and_deal.0'; + $this->client->companies->linkAndUnlinkCompanyWithContactAndDeal( + 'id', + new PatchCompaniesLinkUnlinkIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.link_and_unlink_company_with_contact_and_deal.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/companies/link-unlink/id", + null, + 1 + ); + } + + /** + */ + public function testGetACompany(): void { + $testId = 'companies.get_a_company.0'; + $this->client->companies->getACompany( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'companies.get_a_company.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/companies/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteACompany(): void { + $testId = 'companies.delete_a_company.0'; + $this->client->companies->deleteACompany( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'companies.delete_a_company.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/companies/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateACompany(): void { + $testId = 'companies.update_a_company.0'; + $this->client->companies->updateACompany( + 'id', + new PatchCompaniesIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.update_a_company.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/companies/id", + null, + 1 + ); + } + + /** + */ + public function testCreateACompanyDealAttribute(): void { + $testId = 'companies.create_a_company_deal_attribute.0'; + $this->client->companies->createACompanyDealAttribute( + new PostCrmAttributesRequest([ + 'attributeType' => PostCrmAttributesRequestAttributeType::Text->value, + 'label' => 'Attribute Label', + 'objectType' => PostCrmAttributesRequestObjectType::Companies->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.create_a_company_deal_attribute.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/crm/attributes", + null, + 1 + ); + } + + /** + */ + public function testDeleteAnAttribute(): void { + $testId = 'companies.delete_an_attribute.0'; + $this->client->companies->deleteAnAttribute( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'companies.delete_an_attribute.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/crm/attributes/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateAnAttribute(): void { + $testId = 'companies.update_an_attribute.0'; + $this->client->companies->updateAnAttribute( + 'id', + new PatchCrmAttributesIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'companies.update_an_attribute.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/crm/attributes/id", + null, + 1 + ); + } + + /** + */ + public function testGetCompanyAttributes(): void { + $testId = 'companies.get_company_attributes.0'; + $this->client->companies->getCompanyAttributes( + [ + 'headers' => [ + 'X-Test-Id' => 'companies.get_company_attributes.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/attributes/companies", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/ContactsWireTest.php b/tests/Wire/ContactsWireTest.php new file mode 100644 index 0000000..76b6db1 --- /dev/null +++ b/tests/Wire/ContactsWireTest.php @@ -0,0 +1,727 @@ +client->contacts->getContacts( + new GetContactsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_contacts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts", + null, + 1 + ); + } + + /** + */ + public function testCreateContact(): void { + $testId = 'contacts.create_contact.0'; + $this->client->contacts->createContact( + new CreateContactRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.create_contact.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts", + null, + 1 + ); + } + + /** + */ + public function testGetAttributes(): void { + $testId = 'contacts.get_attributes.0'; + $this->client->contacts->getAttributes( + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_attributes.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/attributes", + null, + 1 + ); + } + + /** + */ + public function testCreateAttribute(): void { + $testId = 'contacts.create_attribute.0'; + $this->client->contacts->createAttribute( + CreateAttributeRequestAttributeCategory::Normal->value, + 'attributeName', + new CreateAttributeRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.create_attribute.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/attributes/normal/attributeName", + null, + 1 + ); + } + + /** + */ + public function testUpdateAttribute(): void { + $testId = 'contacts.update_attribute.0'; + $this->client->contacts->updateAttribute( + UpdateAttributeRequestAttributeCategory::Category->value, + 'attributeName', + new UpdateAttributeRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.update_attribute.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/contacts/attributes/category/attributeName", + null, + 1 + ); + } + + /** + */ + public function testDeleteAttribute(): void { + $testId = 'contacts.delete_attribute.0'; + $this->client->contacts->deleteAttribute( + DeleteAttributeRequestAttributeCategory::Normal->value, + 'attributeName', + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.delete_attribute.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/contacts/attributes/normal/attributeName", + null, + 1 + ); + } + + /** + */ + public function testDeleteMultiAttributeOptions(): void { + $testId = 'contacts.delete_multi_attribute_options.0'; + $this->client->contacts->deleteMultiAttributeOptions( + 'multiple-choice', + 'multipleChoiceAttribute', + 'multipleChoiceAttributeOption', + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.delete_multi_attribute_options.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/contacts/attributes/multiple-choice/multipleChoiceAttribute/multipleChoiceAttributeOption", + null, + 1 + ); + } + + /** + */ + public function testUpdateBatchContacts(): void { + $testId = 'contacts.update_batch_contacts.0'; + $this->client->contacts->updateBatchContacts( + new UpdateBatchContactsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.update_batch_contacts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/batch", + null, + 1 + ); + } + + /** + */ + public function testCreateDoiContact(): void { + $testId = 'contacts.create_doi_contact.0'; + $this->client->contacts->createDoiContact( + new CreateDoiContactRequest([ + 'email' => 'elly@example.com', + 'includeListIds' => [ + 36, + ], + 'redirectionUrl' => 'http://requestb.in/173lyyx1', + 'templateId' => 2, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.create_doi_contact.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/doubleOptinConfirmation", + null, + 1 + ); + } + + /** + */ + public function testRequestContactExport(): void { + $testId = 'contacts.request_contact_export.0'; + $this->client->contacts->requestContactExport( + new RequestContactExportRequest([ + 'customContactFilter' => new RequestContactExportRequestCustomContactFilter([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.request_contact_export.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/export", + null, + 1 + ); + } + + /** + */ + public function testGetFolders(): void { + $testId = 'contacts.get_folders.0'; + $this->client->contacts->getFolders( + new GetFoldersRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_folders.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/folders", + null, + 1 + ); + } + + /** + */ + public function testCreateFolder(): void { + $testId = 'contacts.create_folder.0'; + $this->client->contacts->createFolder( + new CreateUpdateFolder([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.create_folder.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/folders", + null, + 1 + ); + } + + /** + */ + public function testGetFolder(): void { + $testId = 'contacts.get_folder.0'; + $this->client->contacts->getFolder( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_folder.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/folders/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateFolder(): void { + $testId = 'contacts.update_folder.0'; + $this->client->contacts->updateFolder( + 1000000, + new UpdateFolderRequest([ + 'body' => new CreateUpdateFolder([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.update_folder.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/contacts/folders/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteFolder(): void { + $testId = 'contacts.delete_folder.0'; + $this->client->contacts->deleteFolder( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.delete_folder.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/contacts/folders/1000000", + null, + 1 + ); + } + + /** + */ + public function testGetFolderLists(): void { + $testId = 'contacts.get_folder_lists.0'; + $this->client->contacts->getFolderLists( + 1000000, + new GetFolderListsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_folder_lists.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/folders/1000000/lists", + null, + 1 + ); + } + + /** + */ + public function testImportContacts(): void { + $testId = 'contacts.import_contacts.0'; + $this->client->contacts->importContacts( + new ImportContactsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.import_contacts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/import", + null, + 1 + ); + } + + /** + */ + public function testGetLists(): void { + $testId = 'contacts.get_lists.0'; + $this->client->contacts->getLists( + new GetListsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_lists.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/lists", + null, + 1 + ); + } + + /** + */ + public function testCreateList(): void { + $testId = 'contacts.create_list.0'; + $this->client->contacts->createList( + new CreateListRequest([ + 'folderId' => 2, + 'name' => 'Magento Customer - ES', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.create_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/lists", + null, + 1 + ); + } + + /** + */ + public function testGetList(): void { + $testId = 'contacts.get_list.0'; + $this->client->contacts->getList( + 1000000, + new GetListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/lists/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateList(): void { + $testId = 'contacts.update_list.0'; + $this->client->contacts->updateList( + 1000000, + new UpdateListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.update_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/contacts/lists/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteList(): void { + $testId = 'contacts.delete_list.0'; + $this->client->contacts->deleteList( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.delete_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/contacts/lists/1000000", + null, + 1 + ); + } + + /** + */ + public function testGetContactsFromList(): void { + $testId = 'contacts.get_contacts_from_list.0'; + $this->client->contacts->getContactsFromList( + 1000000, + new GetContactsFromListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_contacts_from_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/lists/1000000/contacts", + null, + 1 + ); + } + + /** + */ + public function testAddContactToList(): void { + $testId = 'contacts.add_contact_to_list.0'; + $this->client->contacts->addContactToList( + 1000000, + new AddContactToListRequest([ + 'body' => new AddContactToListRequestBodyEmails([ + 'emails' => [ + 'jeff32@example.com', + 'jim56@example.com', + ], + ]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.add_contact_to_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/lists/1000000/contacts/add", + null, + 1 + ); + } + + /** + */ + public function testRemoveContactFromList(): void { + $testId = 'contacts.remove_contact_from_list.0'; + $this->client->contacts->removeContactFromList( + 1000000, + new RemoveContactFromListRequest([ + 'body' => new RemoveContactFromListRequestBodyEmails([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.remove_contact_from_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/contacts/lists/1000000/contacts/remove", + null, + 1 + ); + } + + /** + */ + public function testGetSegments(): void { + $testId = 'contacts.get_segments.0'; + $this->client->contacts->getSegments( + new GetSegmentsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_segments.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/segments", + null, + 1 + ); + } + + /** + */ + public function testGetContactInfo(): void { + $testId = 'contacts.get_contact_info.0'; + $this->client->contacts->getContactInfo( + 'identifier', + new GetContactInfoRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_contact_info.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/identifier", + null, + 1 + ); + } + + /** + */ + public function testUpdateContact(): void { + $testId = 'contacts.update_contact.0'; + $this->client->contacts->updateContact( + 'identifier', + new UpdateContactRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.update_contact.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/contacts/identifier", + null, + 1 + ); + } + + /** + */ + public function testDeleteContact(): void { + $testId = 'contacts.delete_contact.0'; + $this->client->contacts->deleteContact( + 'identifier', + new DeleteContactRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.delete_contact.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/contacts/identifier", + null, + 1 + ); + } + + /** + */ + public function testGetContactStats(): void { + $testId = 'contacts.get_contact_stats.0'; + $this->client->contacts->getContactStats( + 'identifier', + new GetContactStatsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'contacts.get_contact_stats.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/contacts/identifier/campaignStats", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/ConversationsWireTest.php b/tests/Wire/ConversationsWireTest.php new file mode 100644 index 0000000..d571001 --- /dev/null +++ b/tests/Wire/ConversationsWireTest.php @@ -0,0 +1,261 @@ +client->conversations->setsAgentsStatusToOnlineFor23Minutes( + new PostConversationsAgentOnlinePingRequest([ + 'agentId' => "d9nKoegKSjmCtyK78", + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.sets_agents_status_to_online_for23minutes.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/conversations/agentOnlinePing", + null, + 1 + ); + } + + /** + */ + public function testSendAMessageAsAnAgent(): void { + $testId = 'conversations.send_a_message_as_an_agent.0'; + $this->client->conversations->sendAMessageAsAnAgent( + new PostConversationsMessagesRequest([ + 'agentId' => "d9nKoegKSjmCtyK78", + 'text' => "Hello! How can I help you?", + 'visitorId' => "kZMvWhf8npAu3H6qd57w2Hv6nh6rnxvg", + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.send_a_message_as_an_agent.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/conversations/messages", + null, + 1 + ); + } + + /** + */ + public function testGetAMessage(): void { + $testId = 'conversations.get_a_message.0'; + $this->client->conversations->getAMessage( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.get_a_message.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/conversations/messages/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateAMessageSentByAnAgent(): void { + $testId = 'conversations.update_a_message_sent_by_an_agent.0'; + $this->client->conversations->updateAMessageSentByAnAgent( + 'id', + new PutConversationsMessagesIdRequest([ + 'text' => 'Good morning! How can I help you?', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.update_a_message_sent_by_an_agent.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/conversations/messages/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteAMessageSentByAnAgent(): void { + $testId = 'conversations.delete_a_message_sent_by_an_agent.0'; + $this->client->conversations->deleteAMessageSentByAnAgent( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.delete_a_message_sent_by_an_agent.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/conversations/messages/id", + null, + 1 + ); + } + + /** + */ + public function testSendAnAutomatedMessageToAVisitor(): void { + $testId = 'conversations.send_an_automated_message_to_a_visitor.0'; + $this->client->conversations->sendAnAutomatedMessageToAVisitor( + new PostConversationsPushedMessagesRequest([ + 'groupId' => "PjRBMhWGen6aRHjif", + 'text' => "Your order has shipped! Here’s your tracking number: 9114 5847 3325 9667 4328 88", + 'visitorId' => "kZMvWhf8npAu3H6qd57w2Hv6nh6rnxvg", + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.send_an_automated_message_to_a_visitor.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/conversations/pushedMessages", + null, + 1 + ); + } + + /** + */ + public function testGetAnAutomatedMessage(): void { + $testId = 'conversations.get_an_automated_message.0'; + $this->client->conversations->getAnAutomatedMessage( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.get_an_automated_message.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/conversations/pushedMessages/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateAnAutomatedMessage(): void { + $testId = 'conversations.update_an_automated_message.0'; + $this->client->conversations->updateAnAutomatedMessage( + 'id', + new PutConversationsPushedMessagesIdRequest([ + 'text' => 'Your order has shipped! Here’s your tracking number: 9114 5847 4668 7775 9233 54', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.update_an_automated_message.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/conversations/pushedMessages/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteAnAutomatedMessage(): void { + $testId = 'conversations.delete_an_automated_message.0'; + $this->client->conversations->deleteAnAutomatedMessage( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.delete_an_automated_message.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/conversations/pushedMessages/id", + null, + 1 + ); + } + + /** + */ + public function testSetVisitorGroupAssignment(): void { + $testId = 'conversations.set_visitor_group_assignment.0'; + $this->client->conversations->setVisitorGroupAssignment( + new PutConversationsVisitorGroupRequest([ + 'groupId' => "PjRBMhWGen6aRHjif", + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'conversations.set_visitor_group_assignment.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/conversations/visitorGroup", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/CouponsWireTest.php b/tests/Wire/CouponsWireTest.php new file mode 100644 index 0000000..6ad354c --- /dev/null +++ b/tests/Wire/CouponsWireTest.php @@ -0,0 +1,145 @@ +client->coupons->getCouponCollections( + new GetCouponCollectionsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'coupons.get_coupon_collections.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/couponCollections", + null, + 1 + ); + } + + /** + */ + public function testCreateCouponCollection(): void { + $testId = 'coupons.create_coupon_collection.0'; + $this->client->coupons->createCouponCollection( + new CreateCouponCollectionRequest([ + 'defaultCoupon' => 'Winter', + 'name' => '10%OFF', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'coupons.create_coupon_collection.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/couponCollections", + null, + 1 + ); + } + + /** + */ + public function testGetCouponCollection(): void { + $testId = 'coupons.get_coupon_collection.0'; + $this->client->coupons->getCouponCollection( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'coupons.get_coupon_collection.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/couponCollections/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateCouponCollection(): void { + $testId = 'coupons.update_coupon_collection.0'; + $this->client->coupons->updateCouponCollection( + 'id', + new UpdateCouponCollectionRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'coupons.update_coupon_collection.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/couponCollections/id", + null, + 1 + ); + } + + /** + */ + public function testCreateCoupons(): void { + $testId = 'coupons.create_coupons.0'; + $this->client->coupons->createCoupons( + new CreateCouponsRequest([ + 'collectionId' => '23befbae-1505-47a8-bd27-e30ef739f32c', + 'coupons' => [ + 'Uf12AF', + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'coupons.create_coupons.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/coupons", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/CustomObjectsWireTest.php b/tests/Wire/CustomObjectsWireTest.php new file mode 100644 index 0000000..b4aea20 --- /dev/null +++ b/tests/Wire/CustomObjectsWireTest.php @@ -0,0 +1,111 @@ +client->customObjects->upsertrecords( + 'vehicle', + new UpsertrecordsRequest([ + 'records' => [ + new UpsertrecordsRequestRecordsItem([]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'custom_objects.upsertrecords.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/objects/vehicle/batch/upsert", + null, + 1 + ); + } + + /** + */ + public function testGetrecords(): void { + $testId = 'custom_objects.getrecords.0'; + $this->client->customObjects->getrecords( + 'vehicle', + new GetrecordsRequest([ + 'limit' => 1000000, + 'pageNum' => 1000000, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'custom_objects.getrecords.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/objects/vehicle/records", + ['limit' => '1000000', 'page_num' => '1000000'], + 1 + ); + } + + /** + */ + public function testBatchDeleteObjectRecords(): void { + $testId = 'custom_objects.batch_delete_object_records.0'; + $this->client->customObjects->batchDeleteObjectRecords( + 'vehicle', + new BatchDeleteObjectRecordsRequest([ + 'identifiers' => new BatchDeleteObjectRecordsRequestIdentifiersIds([ + 'ids' => [ + 1, + ], + ]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'custom_objects.batch_delete_object_records.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/objects/vehicle/batch/delete", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/DealsWireTest.php b/tests/Wire/DealsWireTest.php new file mode 100644 index 0000000..2a88a1f --- /dev/null +++ b/tests/Wire/DealsWireTest.php @@ -0,0 +1,267 @@ +client->deals->getDealAttributes( + [ + 'headers' => [ + 'X-Test-Id' => 'deals.get_deal_attributes.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/attributes/deals", + null, + 1 + ); + } + + /** + */ + public function testGetAllDeals(): void { + $testId = 'deals.get_all_deals.0'; + $this->client->deals->getAllDeals( + new GetCrmDealsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'deals.get_all_deals.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/deals", + null, + 1 + ); + } + + /** + */ + public function testCreateADeal(): void { + $testId = 'deals.create_a_deal.0'; + $this->client->deals->createADeal( + new PostCrmDealsRequest([ + 'name' => 'Deal: Connect with company', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'deals.create_a_deal.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/crm/deals", + null, + 1 + ); + } + + /** + */ + public function testImportDealsCreationAndUpdation(): void { + $testId = 'deals.import_deals_creation_and_updation.0'; + $this->client->deals->importDealsCreationAndUpdation( + new PostCrmDealsImportRequest([ + 'file' => File::createFromString("example_file", "example_file"), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'deals.import_deals_creation_and_updation.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/crm/deals/import", + null, + 1 + ); + } + + /** + */ + public function testLinkAndUnlinkADealWithContactsAndCompanies(): void { + $testId = 'deals.link_and_unlink_a_deal_with_contacts_and_companies.0'; + $this->client->deals->linkAndUnlinkADealWithContactsAndCompanies( + 'id', + new PatchCrmDealsLinkUnlinkIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'deals.link_and_unlink_a_deal_with_contacts_and_companies.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/crm/deals/link-unlink/id", + null, + 1 + ); + } + + /** + */ + public function testGetADeal(): void { + $testId = 'deals.get_a_deal.0'; + $this->client->deals->getADeal( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'deals.get_a_deal.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/deals/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteADeal(): void { + $testId = 'deals.delete_a_deal.0'; + $this->client->deals->deleteADeal( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'deals.delete_a_deal.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/crm/deals/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateADeal(): void { + $testId = 'deals.update_a_deal.0'; + $this->client->deals->updateADeal( + 'id', + new PatchCrmDealsIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'deals.update_a_deal.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/crm/deals/id", + null, + 1 + ); + } + + /** + */ + public function testGetPipelineStages(): void { + $testId = 'deals.get_pipeline_stages.0'; + $this->client->deals->getPipelineStages( + [ + 'headers' => [ + 'X-Test-Id' => 'deals.get_pipeline_stages.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/pipeline/details", + null, + 1 + ); + } + + /** + */ + public function testGetAllPipelines(): void { + $testId = 'deals.get_all_pipelines.0'; + $this->client->deals->getAllPipelines( + [ + 'headers' => [ + 'X-Test-Id' => 'deals.get_all_pipelines.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/pipeline/details/all", + null, + 1 + ); + } + + /** + */ + public function testGetAPipeline(): void { + $testId = 'deals.get_a_pipeline.0'; + $this->client->deals->getAPipeline( + 'pipelineID', + [ + 'headers' => [ + 'X-Test-Id' => 'deals.get_a_pipeline.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/pipeline/details/pipelineID", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/DomainsWireTest.php b/tests/Wire/DomainsWireTest.php new file mode 100644 index 0000000..84e49f9 --- /dev/null +++ b/tests/Wire/DomainsWireTest.php @@ -0,0 +1,134 @@ +client->domains->getDomains( + [ + 'headers' => [ + 'X-Test-Id' => 'domains.get_domains.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/senders/domains", + null, + 1 + ); + } + + /** + */ + public function testCreateDomain(): void { + $testId = 'domains.create_domain.0'; + $this->client->domains->createDomain( + new CreateDomainRequest([ + 'name' => 'mycompany.com', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'domains.create_domain.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/senders/domains", + null, + 1 + ); + } + + /** + */ + public function testGetDomainConfiguration(): void { + $testId = 'domains.get_domain_configuration.0'; + $this->client->domains->getDomainConfiguration( + 'domainName', + [ + 'headers' => [ + 'X-Test-Id' => 'domains.get_domain_configuration.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/senders/domains/domainName", + null, + 1 + ); + } + + /** + */ + public function testDeleteDomain(): void { + $testId = 'domains.delete_domain.0'; + $this->client->domains->deleteDomain( + 'domainName', + [ + 'headers' => [ + 'X-Test-Id' => 'domains.delete_domain.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/senders/domains/domainName", + null, + 1 + ); + } + + /** + */ + public function testAuthenticateDomain(): void { + $testId = 'domains.authenticate_domain.0'; + $this->client->domains->authenticateDomain( + 'domainName', + [ + 'headers' => [ + 'X-Test-Id' => 'domains.authenticate_domain.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/senders/domains/domainName/authenticate", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/EcommerceWireTest.php b/tests/Wire/EcommerceWireTest.php new file mode 100644 index 0000000..3dac760 --- /dev/null +++ b/tests/Wire/EcommerceWireTest.php @@ -0,0 +1,476 @@ +client->ecommerce->getCategories( + new GetCategoriesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_categories.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/categories", + null, + 1 + ); + } + + /** + */ + public function testCreateUpdateCategory(): void { + $testId = 'ecommerce.create_update_category.0'; + $this->client->ecommerce->createUpdateCategory( + new CreateUpdateCategoryRequest([ + 'id' => 'CAT123', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_update_category.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/categories", + null, + 1 + ); + } + + /** + */ + public function testCreateUpdateBatchCategory(): void { + $testId = 'ecommerce.create_update_batch_category.0'; + $this->client->ecommerce->createUpdateBatchCategory( + new CreateUpdateBatchCategoryRequest([ + 'categories' => [ + new CreateUpdateBatchCategoryRequestCategoriesItem([ + 'id' => 'CAT123', + ]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_update_batch_category.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/categories/batch", + null, + 1 + ); + } + + /** + */ + public function testGetCategoryInfo(): void { + $testId = 'ecommerce.get_category_info.0'; + $this->client->ecommerce->getCategoryInfo( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_category_info.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/categories/id", + null, + 1 + ); + } + + /** + */ + public function testActivateTheECommerceApp(): void { + $testId = 'ecommerce.activate_the_e_commerce_app.0'; + $this->client->ecommerce->activateTheECommerceApp( + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.activate_the_e_commerce_app.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/ecommerce/activate", + null, + 1 + ); + } + + /** + */ + public function testGetAttributionMetricsForOneOrMoreBrevoCampaignsOrWorkflows(): void { + $testId = 'ecommerce.get_attribution_metrics_for_one_or_more_brevo_campaigns_or_workflows.0'; + $this->client->ecommerce->getAttributionMetricsForOneOrMoreBrevoCampaignsOrWorkflows( + new GetEcommerceAttributionMetricsRequest([ + 'periodFrom' => new DateTime('2022-01-02T00:00:00Z'), + 'periodTo' => new DateTime('2022-01-03T00:00:00Z'), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_attribution_metrics_for_one_or_more_brevo_campaigns_or_workflows.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/ecommerce/attribution/metrics", + ['periodFrom' => '2022-01-02T00:00:00Z', 'periodTo' => '2022-01-03T00:00:00Z'], + 1 + ); + } + + /** + */ + public function testGetDetailedAttributionMetricsForASingleBrevoCampaignOrWorkflow(): void { + $testId = 'ecommerce.get_detailed_attribution_metrics_for_a_single_brevo_campaign_or_workflow.0'; + $this->client->ecommerce->getDetailedAttributionMetricsForASingleBrevoCampaignOrWorkflow( + GetEcommerceAttributionMetricsConversionSourceConversionSourceIdRequestConversionSource::EmailCampaign->value, + 'sale', + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_detailed_attribution_metrics_for_a_single_brevo_campaign_or_workflow.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/ecommerce/attribution/metrics/email_campaign/sale", + null, + 1 + ); + } + + /** + */ + public function testGetAttributedProductSalesForASingleBrevoCampaignOrWorkflow(): void { + $testId = 'ecommerce.get_attributed_product_sales_for_a_single_brevo_campaign_or_workflow.0'; + $this->client->ecommerce->getAttributedProductSalesForASingleBrevoCampaignOrWorkflow( + GetEcommerceAttributionProductsConversionSourceConversionSourceIdRequestConversionSource::EmailCampaign->value, + 'sale', + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_attributed_product_sales_for_a_single_brevo_campaign_or_workflow.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/ecommerce/attribution/products/email_campaign/sale", + null, + 1 + ); + } + + /** + */ + public function testGetTheIso4217CompliantDisplayCurrencyCodeForYourBrevoAccount(): void { + $testId = 'ecommerce.get_the_iso4217compliant_display_currency_code_for_your_brevo_account.0'; + $this->client->ecommerce->getTheIso4217CompliantDisplayCurrencyCodeForYourBrevoAccount( + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_the_iso4217compliant_display_currency_code_for_your_brevo_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/ecommerce/config/displayCurrency", + null, + 1 + ); + } + + /** + */ + public function testSetConfigDisplayCurrency(): void { + $testId = 'ecommerce.set_config_display_currency.0'; + $this->client->ecommerce->setConfigDisplayCurrency( + new SetConfigDisplayCurrencyRequest([ + 'code' => 'EUR', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.set_config_display_currency.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/ecommerce/config/displayCurrency", + null, + 1 + ); + } + + /** + */ + public function testGetOrders(): void { + $testId = 'ecommerce.get_orders.0'; + $this->client->ecommerce->getOrders( + new GetOrdersRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_orders.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/orders", + null, + 1 + ); + } + + /** + */ + public function testCreateOrder(): void { + $testId = 'ecommerce.create_order.0'; + $this->client->ecommerce->createOrder( + new Order([ + 'amount' => 308.42, + 'createdAt' => '2021-07-29T20:59:23.383Z', + 'id' => '14', + 'products' => [ + new OrderProductsItem([ + 'price' => 99.99, + 'productId' => 'P1', + ]), + ], + 'status' => 'completed', + 'updatedAt' => '2021-07-30T10:59:23.383Z', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_order.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/orders/status", + null, + 1 + ); + } + + /** + */ + public function testCreateBatchOrder(): void { + $testId = 'ecommerce.create_batch_order.0'; + $this->client->ecommerce->createBatchOrder( + new CreateBatchOrderRequest([ + 'orders' => [ + new Order([ + 'amount' => 308.42, + 'createdAt' => '2021-07-29T20:59:23.383Z', + 'id' => '14', + 'products' => [ + new OrderProductsItem([ + 'price' => 99.99, + 'productId' => 'P1', + ]), + ], + 'status' => 'completed', + 'updatedAt' => '2021-07-30T10:59:23.383Z', + ]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_batch_order.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/orders/status/batch", + null, + 1 + ); + } + + /** + */ + public function testGetProducts(): void { + $testId = 'ecommerce.get_products.0'; + $this->client->ecommerce->getProducts( + new GetProductsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_products.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/products", + null, + 1 + ); + } + + /** + */ + public function testCreateUpdateProduct(): void { + $testId = 'ecommerce.create_update_product.0'; + $this->client->ecommerce->createUpdateProduct( + new CreateUpdateProductRequest([ + 'id' => 'P11', + 'name' => 'Iphone 11', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_update_product.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/products", + null, + 1 + ); + } + + /** + */ + public function testCreateUpdateBatchProducts(): void { + $testId = 'ecommerce.create_update_batch_products.0'; + $this->client->ecommerce->createUpdateBatchProducts( + new CreateUpdateBatchProductsRequest([ + 'products' => [ + new CreateUpdateBatchProductsRequestProductsItem([ + 'id' => 'P11', + 'name' => 'Iphone 11', + ]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_update_batch_products.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/products/batch", + null, + 1 + ); + } + + /** + */ + public function testGetProductInfo(): void { + $testId = 'ecommerce.get_product_info.0'; + $this->client->ecommerce->getProductInfo( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.get_product_info.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/products/id", + null, + 1 + ); + } + + /** + */ + public function testCreateProductAlert(): void { + $testId = 'ecommerce.create_product_alert.0'; + $this->client->ecommerce->createProductAlert( + 'id', + 'back_in_stock', + new CreateProductAlertRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'ecommerce.create_product_alert.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/products/id/alerts/back_in_stock", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/EmailCampaignsWireTest.php b/tests/Wire/EmailCampaignsWireTest.php new file mode 100644 index 0000000..4384805 --- /dev/null +++ b/tests/Wire/EmailCampaignsWireTest.php @@ -0,0 +1,341 @@ +client->emailCampaigns->getEmailCampaigns( + new GetEmailCampaignsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.get_email_campaigns.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/emailCampaigns", + null, + 1 + ); + } + + /** + */ + public function testCreateEmailCampaign(): void { + $testId = 'email_campaigns.create_email_campaign.0'; + $this->client->emailCampaigns->createEmailCampaign( + new CreateEmailCampaignRequest([ + 'name' => 'Newsletter - May 2017', + 'sender' => new CreateEmailCampaignRequestSender([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.create_email_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/emailCampaigns", + null, + 1 + ); + } + + /** + */ + public function testUploadImageToGallery(): void { + $testId = 'email_campaigns.upload_image_to_gallery.0'; + $this->client->emailCampaigns->uploadImageToGallery( + new UploadImageToGalleryRequest([ + 'imageUrl' => 'https://somedomain.com/image1.jpg', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.upload_image_to_gallery.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/emailCampaigns/images", + null, + 1 + ); + } + + /** + */ + public function testGetEmailCampaign(): void { + $testId = 'email_campaigns.get_email_campaign.0'; + $this->client->emailCampaigns->getEmailCampaign( + 1000000, + new GetEmailCampaignRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.get_email_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/emailCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateEmailCampaign(): void { + $testId = 'email_campaigns.update_email_campaign.0'; + $this->client->emailCampaigns->updateEmailCampaign( + 1000000, + new UpdateEmailCampaignRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.update_email_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/emailCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteEmailCampaign(): void { + $testId = 'email_campaigns.delete_email_campaign.0'; + $this->client->emailCampaigns->deleteEmailCampaign( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.delete_email_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/emailCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testGetAbTestCampaignResult(): void { + $testId = 'email_campaigns.get_ab_test_campaign_result.0'; + $this->client->emailCampaigns->getAbTestCampaignResult( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.get_ab_test_campaign_result.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/emailCampaigns/1000000/abTestCampaignResult", + null, + 1 + ); + } + + /** + */ + public function testEmailExportRecipients(): void { + $testId = 'email_campaigns.email_export_recipients.0'; + $this->client->emailCampaigns->emailExportRecipients( + 1000000, + new EmailExportRecipientsRequest([ + 'recipientsType' => EmailExportRecipientsRequestRecipientsType::All->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.email_export_recipients.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/emailCampaigns/1000000/exportRecipients", + null, + 1 + ); + } + + /** + */ + public function testSendEmailCampaignNow(): void { + $testId = 'email_campaigns.send_email_campaign_now.0'; + $this->client->emailCampaigns->sendEmailCampaignNow( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.send_email_campaign_now.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/emailCampaigns/1000000/sendNow", + null, + 1 + ); + } + + /** + */ + public function testSendReport(): void { + $testId = 'email_campaigns.send_report.0'; + $this->client->emailCampaigns->sendReport( + 1000000, + new SendReportRequest([ + 'body' => new SendReport([ + 'email' => new SendReportEmail([ + 'body' => 'Please find attached the report of our last email campaign.', + 'to' => [ + 'jim.suehan@example.com', + ], + ]), + ]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.send_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/emailCampaigns/1000000/sendReport", + null, + 1 + ); + } + + /** + */ + public function testSendTestEmail(): void { + $testId = 'email_campaigns.send_test_email.0'; + $this->client->emailCampaigns->sendTestEmail( + 1000000, + new SendTestEmailRequest([ + 'body' => new SendTestEmail([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.send_test_email.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/emailCampaigns/1000000/sendTest", + null, + 1 + ); + } + + /** + */ + public function testGetSharedTemplateUrl(): void { + $testId = 'email_campaigns.get_shared_template_url.0'; + $this->client->emailCampaigns->getSharedTemplateUrl( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.get_shared_template_url.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/emailCampaigns/1000000/sharedUrl", + null, + 1 + ); + } + + /** + */ + public function testUpdateCampaignStatus(): void { + $testId = 'email_campaigns.update_campaign_status.0'; + $this->client->emailCampaigns->updateCampaignStatus( + 1000000, + new UpdateCampaignStatusRequest([ + 'body' => new UpdateCampaignStatus([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'email_campaigns.update_campaign_status.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/emailCampaigns/1000000/status", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/EventWireTest.php b/tests/Wire/EventWireTest.php new file mode 100644 index 0000000..b8d2db5 --- /dev/null +++ b/tests/Wire/EventWireTest.php @@ -0,0 +1,103 @@ +client->event->getEvents( + new GetEventsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'event.get_events.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/events", + null, + 1 + ); + } + + /** + */ + public function testCreateEvent(): void { + $testId = 'event.create_event.0'; + $this->client->event->createEvent( + new CreateEventRequest([ + 'eventName' => 'video_played', + 'identifiers' => new CreateEventRequestIdentifiers([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'event.create_event.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/events", + null, + 1 + ); + } + + /** + */ + public function testCreateBatchEvents(): void { + $testId = 'event.create_batch_events.0'; + $this->client->event->createBatchEvents( + [ + new CreateBatchEventsRequestItem([ + 'eventName' => 'order_created', + 'identifiers' => new CreateBatchEventsRequestItemIdentifiers([]), + ]), + ], + [ + 'headers' => [ + 'X-Test-Id' => 'event.create_batch_events.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/events/batch", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/ExternalFeedsWireTest.php b/tests/Wire/ExternalFeedsWireTest.php new file mode 100644 index 0000000..df56873 --- /dev/null +++ b/tests/Wire/ExternalFeedsWireTest.php @@ -0,0 +1,151 @@ +client->externalFeeds->getAllExternalFeeds( + new GetAllExternalFeedsRequest([ + 'search' => 'product', + 'startDate' => new DateTime('2024-01-01'), + 'endDate' => new DateTime('2024-01-31'), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'external_feeds.get_all_external_feeds.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/feeds", + ['search' => 'product', 'startDate' => '2024-01-01', 'endDate' => '2024-01-31'], + 1 + ); + } + + /** + */ + public function testCreateExternalFeed(): void { + $testId = 'external_feeds.create_external_feed.0'; + $this->client->externalFeeds->createExternalFeed( + new CreateExternalFeedRequest([ + 'name' => 'Public API Feed', + 'url' => 'https://jsonplaceholder.typicode.com/posts', + 'authType' => CreateExternalFeedRequestAuthType::NoAuth->value, + 'maxRetries' => 3, + 'cache' => true, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'external_feeds.create_external_feed.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/feeds", + null, + 1 + ); + } + + /** + */ + public function testGetExternalFeedByUuid(): void { + $testId = 'external_feeds.get_external_feed_by_uuid.0'; + $this->client->externalFeeds->getExternalFeedByUuid( + 'b1c2d3e4-f5a6-47b8-89c0-d1e2f3a4b5c6', + [ + 'headers' => [ + 'X-Test-Id' => 'external_feeds.get_external_feed_by_uuid.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/feeds/b1c2d3e4-f5a6-47b8-89c0-d1e2f3a4b5c6", + null, + 1 + ); + } + + /** + */ + public function testUpdateExternalFeed(): void { + $testId = 'external_feeds.update_external_feed.0'; + $this->client->externalFeeds->updateExternalFeed( + 'b1c2d3e4-f5a6-47b8-89c0-d1e2f3a4b5c6', + new UpdateExternalFeedRequest([ + 'name' => 'Updated Product Catalog', + 'url' => 'https://api.newstore.com/products/v2', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'external_feeds.update_external_feed.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/feeds/b1c2d3e4-f5a6-47b8-89c0-d1e2f3a4b5c6", + null, + 1 + ); + } + + /** + */ + public function testDeleteExternalFeed(): void { + $testId = 'external_feeds.delete_external_feed.0'; + $this->client->externalFeeds->deleteExternalFeed( + 'b1c2d3e4-f5a6-47b8-89c0-d1e2f3a4b5c6', + [ + 'headers' => [ + 'X-Test-Id' => 'external_feeds.delete_external_feed.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/feeds/b1c2d3e4-f5a6-47b8-89c0-d1e2f3a4b5c6", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/FilesWireTest.php b/tests/Wire/FilesWireTest.php new file mode 100644 index 0000000..ed6e71c --- /dev/null +++ b/tests/Wire/FilesWireTest.php @@ -0,0 +1,137 @@ +client->files->getAllFiles( + new GetCrmFilesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'files.get_all_files.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/files", + null, + 1 + ); + } + + /** + */ + public function testUploadAFile(): void { + $testId = 'files.upload_a_file.0'; + $this->client->files->uploadAFile( + new PostCrmFilesRequest([ + 'file' => File::createFromString("example_file", "example_file"), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'files.upload_a_file.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/crm/files", + null, + 1 + ); + } + + /** + */ + public function testDownloadAFile(): void { + $testId = 'files.download_a_file.0'; + $this->client->files->downloadAFile( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'files.download_a_file.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/files/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteAFile(): void { + $testId = 'files.delete_a_file.0'; + $this->client->files->deleteAFile( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'files.delete_a_file.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/crm/files/id", + null, + 1 + ); + } + + /** + */ + public function testGetFileDetails(): void { + $testId = 'files.get_file_details.0'; + $this->client->files->getFileDetails( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'files.get_file_details.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/files/id/data", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/InboundParsingWireTest.php b/tests/Wire/InboundParsingWireTest.php new file mode 100644 index 0000000..3b0bbc0 --- /dev/null +++ b/tests/Wire/InboundParsingWireTest.php @@ -0,0 +1,91 @@ +client->inboundParsing->getInboundEmailEvents( + new GetInboundEmailEventsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'inbound_parsing.get_inbound_email_events.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/inbound/events", + null, + 1 + ); + } + + /** + */ + public function testGetInboundEmailEventsByUuid(): void { + $testId = 'inbound_parsing.get_inbound_email_events_by_uuid.0'; + $this->client->inboundParsing->getInboundEmailEventsByUuid( + 'uuid', + [ + 'headers' => [ + 'X-Test-Id' => 'inbound_parsing.get_inbound_email_events_by_uuid.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/inbound/events/uuid", + null, + 1 + ); + } + + /** + */ + public function testGetInboundEmailAttachment(): void { + $testId = 'inbound_parsing.get_inbound_email_attachment.0'; + $this->client->inboundParsing->getInboundEmailAttachment( + 'downloadToken', + [ + 'headers' => [ + 'X-Test-Id' => 'inbound_parsing.get_inbound_email_attachment.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/inbound/attachments/downloadToken", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/MasterAccountWireTest.php b/tests/Wire/MasterAccountWireTest.php new file mode 100644 index 0000000..18110ef --- /dev/null +++ b/tests/Wire/MasterAccountWireTest.php @@ -0,0 +1,749 @@ +client->masterAccount->createANewGroupOfSubAccounts( + new PostCorporateGroupRequest([ + 'groupName' => 'My group', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.create_a_new_group_of_sub_accounts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/group", + null, + 1 + ); + } + + /** + */ + public function testDeleteSubAccountFromGroup(): void { + $testId = 'master_account.delete_sub_account_from_group.0'; + $this->client->masterAccount->deleteSubAccountFromGroup( + 'groupId', + new PutCorporateGroupUnlinkGroupIdSubAccountsRequest([ + 'subAccountIds' => [ + 423432, + 234323, + 87678, + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.delete_sub_account_from_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/group/unlink/groupId/subAccounts", + null, + 1 + ); + } + + /** + */ + public function testGetAGroupDetails(): void { + $testId = 'master_account.get_a_group_details.0'; + $this->client->masterAccount->getAGroupDetails( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_a_group_details.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/group/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateAGroupOfSubAccounts(): void { + $testId = 'master_account.update_a_group_of_sub_accounts.0'; + $this->client->masterAccount->updateAGroupOfSubAccounts( + 'id', + new PutCorporateGroupIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.update_a_group_of_sub_accounts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/group/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteAGroup(): void { + $testId = 'master_account.delete_a_group.0'; + $this->client->masterAccount->deleteAGroup( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.delete_a_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/corporate/group/id", + null, + 1 + ); + } + + /** + */ + public function testGetSubAccountGroups(): void { + $testId = 'master_account.get_sub_account_groups.0'; + $this->client->masterAccount->getSubAccountGroups( + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_sub_account_groups.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/groups", + null, + 1 + ); + } + + /** + */ + public function testGetCorporateInvitedUsersList(): void { + $testId = 'master_account.get_corporate_invited_users_list.0'; + $this->client->masterAccount->getCorporateInvitedUsersList( + new GetCorporateInvitedUsersListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_corporate_invited_users_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/invited/users", + null, + 1 + ); + } + + /** + */ + public function testListOfAllIPs(): void { + $testId = 'master_account.list_of_all_i_ps.0'; + $this->client->masterAccount->listOfAllIPs( + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.list_of_all_i_ps.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/ip", + null, + 1 + ); + } + + /** + */ + public function testGetTheDetailsOfRequestedMasterAccount(): void { + $testId = 'master_account.get_the_details_of_requested_master_account.0'; + $this->client->masterAccount->getTheDetailsOfRequestedMasterAccount( + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_the_details_of_requested_master_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/masterAccount", + null, + 1 + ); + } + + /** + */ + public function testGenerateSsoTokenToAccessAdminAccount(): void { + $testId = 'master_account.generate_sso_token_to_access_admin_account.0'; + $this->client->masterAccount->generateSsoTokenToAccessAdminAccount( + new PostCorporateSsoTokenRequest([ + 'email' => 'vipin+ent-user@brevo.com', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.generate_sso_token_to_access_admin_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/ssoToken", + null, + 1 + ); + } + + /** + */ + public function testGetTheListOfAllTheSubAccountsOfTheMasterAccount(): void { + $testId = 'master_account.get_the_list_of_all_the_sub_accounts_of_the_master_account.0'; + $this->client->masterAccount->getTheListOfAllTheSubAccountsOfTheMasterAccount( + new GetCorporateSubAccountRequest([ + 'offset' => 1, + 'limit' => 1, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_the_list_of_all_the_sub_accounts_of_the_master_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/subAccount", + ['offset' => '1', 'limit' => '1'], + 1 + ); + } + + /** + */ + public function testCreateANewSubAccountUnderAMasterAccount(): void { + $testId = 'master_account.create_a_new_sub_account_under_a_master_account.0'; + $this->client->masterAccount->createANewSubAccountUnderAMasterAccount( + new PostCorporateSubAccountRequest([ + 'companyName' => 'Test Sub-account', + 'email' => 'test-sub@example.com', + 'groupIds' => [ + '5f8f8c3b5f56a02d4433b3a7', + '5f8f8c3b5f56a02d4433b3a8', + ], + 'language' => PostCorporateSubAccountRequestLanguage::Fr->value, + 'timezone' => 'Europe/Paris', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.create_a_new_sub_account_under_a_master_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/subAccount", + null, + 1 + ); + } + + /** + */ + public function testAssociateAnIpToSubAccounts(): void { + $testId = 'master_account.associate_an_ip_to_sub_accounts.0'; + $this->client->masterAccount->associateAnIpToSubAccounts( + new PostCorporateSubAccountIpAssociateRequest([ + 'ids' => [ + 234322, + 325553, + 893432, + ], + 'ip' => '103.11.32.88', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.associate_an_ip_to_sub_accounts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/subAccount/ip/associate", + null, + 1 + ); + } + + /** + */ + public function testDissociateAnIpToSubAccounts(): void { + $testId = 'master_account.dissociate_an_ip_to_sub_accounts.0'; + $this->client->masterAccount->dissociateAnIpToSubAccounts( + new PutCorporateSubAccountIpDissociateRequest([ + 'ids' => [ + 234322, + 325553, + 893432, + ], + 'ip' => '103.11.32.88', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.dissociate_an_ip_to_sub_accounts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/subAccount/ip/dissociate", + null, + 1 + ); + } + + /** + */ + public function testCreateAnApiKeyForASubAccount(): void { + $testId = 'master_account.create_an_api_key_for_a_sub_account.0'; + $this->client->masterAccount->createAnApiKeyForASubAccount( + new PostCorporateSubAccountKeyRequest([ + 'id' => 3232323, + 'name' => 'My Api Key', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.create_an_api_key_for_a_sub_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/subAccount/key", + null, + 1 + ); + } + + /** + */ + public function testGenerateSsoTokenToAccessSubAccount(): void { + $testId = 'master_account.generate_sso_token_to_access_sub_account.0'; + $this->client->masterAccount->generateSsoTokenToAccessSubAccount( + new PostCorporateSubAccountSsoTokenRequest([ + 'id' => 3232323, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.generate_sso_token_to_access_sub_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/subAccount/ssoToken", + null, + 1 + ); + } + + /** + */ + public function testGetSubAccountDetails(): void { + $testId = 'master_account.get_sub_account_details.0'; + $this->client->masterAccount->getSubAccountDetails( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_sub_account_details.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/subAccount/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteASubAccount(): void { + $testId = 'master_account.delete_a_sub_account.0'; + $this->client->masterAccount->deleteASubAccount( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.delete_a_sub_account.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/corporate/subAccount/1000000", + null, + 1 + ); + } + + /** + */ + public function testEnableDisableSubAccountApplicationS(): void { + $testId = 'master_account.enable_disable_sub_account_application_s.0'; + $this->client->masterAccount->enableDisableSubAccountApplicationS( + 1000000, + new PutCorporateSubAccountIdApplicationsToggleRequest([ + 'landingPages' => true, + 'meetings' => true, + 'smsCampaigns' => false, + 'webPush' => false, + 'whatsapp' => true, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.enable_disable_sub_account_application_s.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/subAccount/1000000/applications/toggle", + null, + 1 + ); + } + + /** + */ + public function testUpdateSubAccountPlan(): void { + $testId = 'master_account.update_sub_account_plan.0'; + $this->client->masterAccount->updateSubAccountPlan( + 1000000, + new PutCorporateSubAccountIdPlanRequest([ + 'credits' => new PutCorporateSubAccountIdPlanRequestCredits([ + 'email' => 5000, + 'externalFeeds' => 1, + 'sms' => 2000, + 'whatsapp' => 100, + 'wpSubscribers' => -1, + ]), + 'features' => new PutCorporateSubAccountIdPlanRequestFeatures([ + 'inbox' => 10, + 'landingPage' => 20, + 'salesUsers' => 6, + 'users' => 15, + ]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.update_sub_account_plan.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/subAccount/1000000/plan", + null, + 1 + ); + } + + /** + */ + public function testUpdateSubAccountsPlan(): void { + $testId = 'master_account.update_sub_accounts_plan.0'; + $this->client->masterAccount->updateSubAccountsPlan( + new PutCorporateSubAccountsPlanRequest([ + 'credits' => new PutCorporateSubAccountsPlanRequestCredits([ + 'email' => 5000, + 'externalFeeds' => 1, + 'sms' => 2000, + 'whatsapp' => 100, + 'wpSubscribers' => -1, + ]), + 'features' => new PutCorporateSubAccountsPlanRequestFeatures([ + 'landingPage' => 20, + 'salesUsers' => 6, + 'users' => 15, + ]), + 'subAccountIds' => [ + 4534345, + 987893, + 876785, + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.update_sub_accounts_plan.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/subAccounts/plan", + null, + 1 + ); + } + + /** + */ + public function testInviteAdminUser(): void { + $testId = 'master_account.invite_admin_user.0'; + $this->client->masterAccount->inviteAdminUser( + new InviteAdminUserRequest([ + 'allFeaturesAccess' => true, + 'email' => 'inviteuser@example.com', + 'privileges' => [ + new InviteAdminUserRequestPrivilegesItem([]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.invite_admin_user.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/corporate/user/invitation/send", + null, + 1 + ); + } + + /** + */ + public function testResendCancelAdminUserInvitation(): void { + $testId = 'master_account.resend_cancel_admin_user_invitation.0'; + $this->client->masterAccount->resendCancelAdminUserInvitation( + PutCorporateUserInvitationActionEmailRequestAction::Resend->value, + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.resend_cancel_admin_user_invitation.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/user/invitation/resend/email", + null, + 1 + ); + } + + /** + */ + public function testRevokeAnAdminUser(): void { + $testId = 'master_account.revoke_an_admin_user.0'; + $this->client->masterAccount->revokeAnAdminUser( + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.revoke_an_admin_user.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/corporate/user/revoke/email", + null, + 1 + ); + } + + /** + */ + public function testGetCorporateUserPermission(): void { + $testId = 'master_account.get_corporate_user_permission.0'; + $this->client->masterAccount->getCorporateUserPermission( + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.get_corporate_user_permission.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/corporate/user/email/permissions", + null, + 1 + ); + } + + /** + */ + public function testChangeAdminUserPermissions(): void { + $testId = 'master_account.change_admin_user_permissions.0'; + $this->client->masterAccount->changeAdminUserPermissions( + 'email', + new PutCorporateUserEmailPermissionsRequest([ + 'allFeaturesAccess' => false, + 'privileges' => [ + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::UserManagement->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::All->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::Api->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::All->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::MyPlan->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::None->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::AppsManagement->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::All->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::CreateSubOrganizations->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::All->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::SubOrganizationGroups->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::Create->value, + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::EditDelete->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::ManageSubOrganizations->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::All->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::Security->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::None->value, + ], + ]), + new PutCorporateUserEmailPermissionsRequestPrivilegesItem([ + 'feature' => PutCorporateUserEmailPermissionsRequestPrivilegesItemFeature::Analytics->value, + 'permissions' => [ + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::CreateAlerts->value, + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::DownloadData->value, + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::MyLooks->value, + PutCorporateUserEmailPermissionsRequestPrivilegesItemPermissionsItem::ExploreCreate->value, + ], + ]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'master_account.change_admin_user_permissions.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/corporate/user/email/permissions", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/NotesWireTest.php b/tests/Wire/NotesWireTest.php new file mode 100644 index 0000000..0120fd4 --- /dev/null +++ b/tests/Wire/NotesWireTest.php @@ -0,0 +1,142 @@ +client->notes->getAllNotes( + new GetCrmNotesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'notes.get_all_notes.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/notes", + null, + 1 + ); + } + + /** + */ + public function testCreateANote(): void { + $testId = 'notes.create_a_note.0'; + $this->client->notes->createANote( + new NoteData([ + 'text' => 'In communication with client_dev for resolution of queries.', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'notes.create_a_note.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/crm/notes", + null, + 1 + ); + } + + /** + */ + public function testGetANote(): void { + $testId = 'notes.get_a_note.0'; + $this->client->notes->getANote( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'notes.get_a_note.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/notes/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteANote(): void { + $testId = 'notes.delete_a_note.0'; + $this->client->notes->deleteANote( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'notes.delete_a_note.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/crm/notes/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateANote(): void { + $testId = 'notes.update_a_note.0'; + $this->client->notes->updateANote( + 'id', + new PatchCrmNotesIdRequest([ + 'body' => new NoteData([ + 'text' => 'In communication with client_dev for resolution of queries.', + ]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'notes.update_a_note.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/crm/notes/id", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/PaymentsWireTest.php b/tests/Wire/PaymentsWireTest.php new file mode 100644 index 0000000..42ab01e --- /dev/null +++ b/tests/Wire/PaymentsWireTest.php @@ -0,0 +1,99 @@ +client->payments->createPaymentRequest( + new CreatePaymentRequestRequest([ + 'cart' => new Cart([ + 'currency' => 'EUR', + 'specificAmount' => 1200, + ]), + 'contactId' => 43, + 'reference' => 'Invoice #INV0001', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'payments.create_payment_request.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/payments/requests", + null, + 1 + ); + } + + /** + */ + public function testGetPaymentRequest(): void { + $testId = 'payments.get_payment_request.0'; + $this->client->payments->getPaymentRequest( + '050db7b0-9bb7-4c1e-9c68-5a8dace8c1dc', + [ + 'headers' => [ + 'X-Test-Id' => 'payments.get_payment_request.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/payments/requests/050db7b0-9bb7-4c1e-9c68-5a8dace8c1dc", + null, + 1 + ); + } + + /** + */ + public function testDeletePaymentRequest(): void { + $testId = 'payments.delete_payment_request.0'; + $this->client->payments->deletePaymentRequest( + '9ae7d68a-565c-4695-9381-d8fb3e3a14cc', + [ + 'headers' => [ + 'X-Test-Id' => 'payments.delete_payment_request.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/payments/requests/9ae7d68a-565c-4695-9381-d8fb3e3a14cc", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/ProcessWireTest.php b/tests/Wire/ProcessWireTest.php new file mode 100644 index 0000000..c9e8c69 --- /dev/null +++ b/tests/Wire/ProcessWireTest.php @@ -0,0 +1,70 @@ +client->process->getProcesses( + new GetProcessesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'process.get_processes.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/processes", + null, + 1 + ); + } + + /** + */ + public function testGetProcess(): void { + $testId = 'process.get_process.0'; + $this->client->process->getProcess( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'process.get_process.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/processes/1000000", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/ProgramWireTest.php b/tests/Wire/ProgramWireTest.php new file mode 100644 index 0000000..273a163 --- /dev/null +++ b/tests/Wire/ProgramWireTest.php @@ -0,0 +1,306 @@ +client->program->getLpList( + new GetLpListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.get_lp_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/config/programs", + null, + 1 + ); + } + + /** + */ + public function testCreateNewLp(): void { + $testId = 'program.create_new_lp.0'; + $this->client->program->createNewLp( + new CreateNewLpRequest([ + 'name' => 'name', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.create_new_lp.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/config/programs", + null, + 1 + ); + } + + /** + */ + public function testGetLoyaltyProgramInfo(): void { + $testId = 'program.get_loyalty_program_info.0'; + $this->client->program->getLoyaltyProgramInfo( + 'pid', + [ + 'headers' => [ + 'X-Test-Id' => 'program.get_loyalty_program_info.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/config/programs/pid", + null, + 1 + ); + } + + /** + */ + public function testUpdateLoyaltyProgram(): void { + $testId = 'program.update_loyalty_program.0'; + $this->client->program->updateLoyaltyProgram( + 'pid', + new UpdateLoyaltyProgramRequest([ + 'name' => 'name', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.update_loyalty_program.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/loyalty/config/programs/pid", + null, + 1 + ); + } + + /** + */ + public function testDeleteLoyaltyProgram(): void { + $testId = 'program.delete_loyalty_program.0'; + $this->client->program->deleteLoyaltyProgram( + 'pid', + [ + 'headers' => [ + 'X-Test-Id' => 'program.delete_loyalty_program.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/config/programs/pid", + null, + 1 + ); + } + + /** + */ + public function testPartiallyUpdateLoyaltyProgram(): void { + $testId = 'program.partially_update_loyalty_program.0'; + $this->client->program->partiallyUpdateLoyaltyProgram( + 'pid', + new PartiallyUpdateLoyaltyProgramRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.partially_update_loyalty_program.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/loyalty/config/programs/pid", + null, + 1 + ); + } + + /** + */ + public function testGetParameterSubscriptionInfo(): void { + $testId = 'program.get_parameter_subscription_info.0'; + $this->client->program->getParameterSubscriptionInfo( + 'pid', + new GetParameterSubscriptionInfoRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.get_parameter_subscription_info.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/config/programs/pid/account-info", + null, + 1 + ); + } + + /** + */ + public function testDeleteContactSubscription(): void { + $testId = 'program.delete_contact_subscription.0'; + $this->client->program->deleteContactSubscription( + 'pid', + 1, + [ + 'headers' => [ + 'X-Test-Id' => 'program.delete_contact_subscription.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/config/programs/pid/contact/1", + null, + 1 + ); + } + + /** + */ + public function testPublishLoyaltyProgram(): void { + $testId = 'program.publish_loyalty_program.0'; + $this->client->program->publishLoyaltyProgram( + 'pid', + [ + 'headers' => [ + 'X-Test-Id' => 'program.publish_loyalty_program.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/config/programs/pid/publish", + null, + 1 + ); + } + + /** + */ + public function testSubscribeMemberToASubscription(): void { + $testId = 'program.subscribe_member_to_a_subscription.0'; + $this->client->program->subscribeMemberToASubscription( + 'pid', + new SubscribeMemberToASubscriptionRequest([ + 'memberContactIds' => [ + 1, + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.subscribe_member_to_a_subscription.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/config/programs/pid/subscription-members", + null, + 1 + ); + } + + /** + */ + public function testDeleteContactMembers(): void { + $testId = 'program.delete_contact_members.0'; + $this->client->program->deleteContactMembers( + 'pid', + new DeleteContactMembersRequest([ + 'memberContactIds' => 'memberContactIds', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.delete_contact_members.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/config/programs/pid/subscription-members", + ['memberContactIds' => 'memberContactIds'], + 1 + ); + } + + /** + */ + public function testSubscribeToLoyaltyProgram(): void { + $testId = 'program.subscribe_to_loyalty_program.0'; + $this->client->program->subscribeToLoyaltyProgram( + 'pid', + new SubscribeToLoyaltyProgramRequest([ + 'contactId' => 1, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'program.subscribe_to_loyalty_program.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/config/programs/pid/subscriptions", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/RewardWireTest.php b/tests/Wire/RewardWireTest.php new file mode 100644 index 0000000..9babcb7 --- /dev/null +++ b/tests/Wire/RewardWireTest.php @@ -0,0 +1,262 @@ +client->reward->getCodeCount( + 'pid', + 'cpid', + [ + 'headers' => [ + 'X-Test-Id' => 'reward.get_code_count.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/offer/programs/pid/code-pools/cpid/codes-count", + null, + 1 + ); + } + + /** + */ + public function testGetRewardPageApi(): void { + $testId = 'reward.get_reward_page_api.0'; + $this->client->reward->getRewardPageApi( + 'pid', + new GetLoyaltyOfferProgramsPidOffersRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.get_reward_page_api.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/offer/programs/pid/offers", + null, + 1 + ); + } + + /** + */ + public function testCreateReward(): void { + $testId = 'reward.create_reward.0'; + $this->client->reward->createReward( + 'pid', + new CreateRewardRequest([ + 'name' => 'name', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.create_reward.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/offer/programs/pid/offers", + null, + 1 + ); + } + + /** + */ + public function testCreateVoucher(): void { + $testId = 'reward.create_voucher.0'; + $this->client->reward->createVoucher( + 'pid', + new CreateVoucherRequest([ + 'rewardId' => 'rewardId', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.create_voucher.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/offer/programs/pid/rewards/attribute", + null, + 1 + ); + } + + /** + */ + public function testRedeemVoucher(): void { + $testId = 'reward.redeem_voucher.0'; + $this->client->reward->redeemVoucher( + 'pid', + new RedeemVoucherRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.redeem_voucher.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/offer/programs/pid/rewards/redeem", + null, + 1 + ); + } + + /** + */ + public function testCompleteRedeemTransaction(): void { + $testId = 'reward.complete_redeem_transaction.0'; + $this->client->reward->completeRedeemTransaction( + 'pid', + 'tid', + [ + 'headers' => [ + 'X-Test-Id' => 'reward.complete_redeem_transaction.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/offer/programs/pid/rewards/redeem/tid/complete", + null, + 1 + ); + } + + /** + */ + public function testRevokeVouchers(): void { + $testId = 'reward.revoke_vouchers.0'; + $this->client->reward->revokeVouchers( + 'pid', + new RevokeVouchersRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.revoke_vouchers.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/offer/programs/pid/rewards/revoke", + null, + 1 + ); + } + + /** + */ + public function testValidateReward(): void { + $testId = 'reward.validate_reward.0'; + $this->client->reward->validateReward( + 'pid', + new ValidateRewardRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.validate_reward.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/offer/programs/pid/rewards/validate", + null, + 1 + ); + } + + /** + */ + public function testGetRewardInformation(): void { + $testId = 'reward.get_reward_information.0'; + $this->client->reward->getRewardInformation( + 'pid', + 'rid', + new GetLoyaltyOfferProgramsPidRewardsRidRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.get_reward_information.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/offer/programs/pid/rewards/rid", + null, + 1 + ); + } + + /** + */ + public function testGetVoucherForAContact(): void { + $testId = 'reward.get_voucher_for_a_contact.0'; + $this->client->reward->getVoucherForAContact( + 'pid', + new GetLoyaltyOfferProgramsPidVouchersRequest([ + 'contactId' => 1, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'reward.get_voucher_for_a_contact.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/offer/programs/pid/vouchers", + ['contactId' => '1'], + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/SendersWireTest.php b/tests/Wire/SendersWireTest.php new file mode 100644 index 0000000..a4bc1b3 --- /dev/null +++ b/tests/Wire/SendersWireTest.php @@ -0,0 +1,186 @@ +client->senders->getSenders( + new GetSendersRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'senders.get_senders.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/senders", + null, + 1 + ); + } + + /** + */ + public function testCreateSender(): void { + $testId = 'senders.create_sender.0'; + $this->client->senders->createSender( + new CreateSenderRequest([ + 'email' => 'support@example.com', + 'name' => 'Support Team', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'senders.create_sender.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/senders", + null, + 1 + ); + } + + /** + */ + public function testGetIps(): void { + $testId = 'senders.get_ips.0'; + $this->client->senders->getIps( + [ + 'headers' => [ + 'X-Test-Id' => 'senders.get_ips.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/senders/ips", + null, + 1 + ); + } + + /** + */ + public function testUpdateSender(): void { + $testId = 'senders.update_sender.0'; + $this->client->senders->updateSender( + 1000000, + new UpdateSenderRequest([ + 'name' => 'New Support Team', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'senders.update_sender.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/senders/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteSender(): void { + $testId = 'senders.delete_sender.0'; + $this->client->senders->deleteSender( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'senders.delete_sender.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/senders/1000000", + null, + 1 + ); + } + + /** + */ + public function testGetIpsFromSender(): void { + $testId = 'senders.get_ips_from_sender.0'; + $this->client->senders->getIpsFromSender( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'senders.get_ips_from_sender.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/senders/1000000/ips", + null, + 1 + ); + } + + /** + */ + public function testValidateSenderByOtp(): void { + $testId = 'senders.validate_sender_by_otp.0'; + $this->client->senders->validateSenderByOtp( + 1000000, + new ValidateSenderByOtpRequest([ + 'otp' => 123456, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'senders.validate_sender_by_otp.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/senders/1000000/validate", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/SmsCampaignsWireTest.php b/tests/Wire/SmsCampaignsWireTest.php new file mode 100644 index 0000000..4796c50 --- /dev/null +++ b/tests/Wire/SmsCampaignsWireTest.php @@ -0,0 +1,270 @@ +client->smsCampaigns->getSmsCampaigns( + new GetSmsCampaignsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.get_sms_campaigns.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smsCampaigns", + null, + 1 + ); + } + + /** + */ + public function testCreateSmsCampaign(): void { + $testId = 'sms_campaigns.create_sms_campaign.0'; + $this->client->smsCampaigns->createSmsCampaign( + new CreateSmsCampaignRequest([ + 'content' => 'Get a discount by visiting our NY store and saying : Happy Spring!', + 'name' => 'Spring Promo Code', + 'sender' => 'MyShop', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.create_sms_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smsCampaigns", + null, + 1 + ); + } + + /** + */ + public function testGetSmsCampaign(): void { + $testId = 'sms_campaigns.get_sms_campaign.0'; + $this->client->smsCampaigns->getSmsCampaign( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.get_sms_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smsCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateSmsCampaign(): void { + $testId = 'sms_campaigns.update_sms_campaign.0'; + $this->client->smsCampaigns->updateSmsCampaign( + 1000000, + new UpdateSmsCampaignRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.update_sms_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/smsCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteSmsCampaign(): void { + $testId = 'sms_campaigns.delete_sms_campaign.0'; + $this->client->smsCampaigns->deleteSmsCampaign( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.delete_sms_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/smsCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testRequestSmsRecipientExport(): void { + $testId = 'sms_campaigns.request_sms_recipient_export.0'; + $this->client->smsCampaigns->requestSmsRecipientExport( + 1000000, + new RequestSmsRecipientExportRequest([ + 'recipientsType' => RequestSmsRecipientExportRequestRecipientsType::All->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.request_sms_recipient_export.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smsCampaigns/1000000/exportRecipients", + null, + 1 + ); + } + + /** + */ + public function testSendSmsCampaignNow(): void { + $testId = 'sms_campaigns.send_sms_campaign_now.0'; + $this->client->smsCampaigns->sendSmsCampaignNow( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.send_sms_campaign_now.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smsCampaigns/1000000/sendNow", + null, + 1 + ); + } + + /** + */ + public function testSendSmsReport(): void { + $testId = 'sms_campaigns.send_sms_report.0'; + $this->client->smsCampaigns->sendSmsReport( + 1000000, + new SendSmsReportRequest([ + 'body' => new SendReport([ + 'email' => new SendReportEmail([ + 'body' => 'Please find attached the report of our last email campaign.', + 'to' => [ + 'jim.suehan@example.com', + ], + ]), + ]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.send_sms_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smsCampaigns/1000000/sendReport", + null, + 1 + ); + } + + /** + */ + public function testSendTestSms(): void { + $testId = 'sms_campaigns.send_test_sms.0'; + $this->client->smsCampaigns->sendTestSms( + 1000000, + new SendTestSmsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.send_test_sms.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smsCampaigns/1000000/sendTest", + null, + 1 + ); + } + + /** + */ + public function testUpdateSmsCampaignStatus(): void { + $testId = 'sms_campaigns.update_sms_campaign_status.0'; + $this->client->smsCampaigns->updateSmsCampaignStatus( + 1000000, + new UpdateSmsCampaignStatusRequest([ + 'body' => new UpdateCampaignStatus([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_campaigns.update_sms_campaign_status.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/smsCampaigns/1000000/status", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/SmsTemplatesWireTest.php b/tests/Wire/SmsTemplatesWireTest.php new file mode 100644 index 0000000..0c1ca23 --- /dev/null +++ b/tests/Wire/SmsTemplatesWireTest.php @@ -0,0 +1,49 @@ +client->smsTemplates->getSmsTemplates( + new GetSmsTemplatesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'sms_templates.get_sms_templates.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/transactionalSMS/templates", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/TasksWireTest.php b/tests/Wire/TasksWireTest.php new file mode 100644 index 0000000..03fdbbf --- /dev/null +++ b/tests/Wire/TasksWireTest.php @@ -0,0 +1,163 @@ +client->tasks->getAllTasks( + new GetCrmTasksRequest([ + 'sortBy' => 'name', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'tasks.get_all_tasks.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/tasks", + ['sortBy' => 'name'], + 1 + ); + } + + /** + */ + public function testCreateATask(): void { + $testId = 'tasks.create_a_task.0'; + $this->client->tasks->createATask( + new PostCrmTasksRequest([ + 'date' => new DateTime('2021-11-01T17:44:54Z'), + 'name' => 'Task: Connect with client_dev', + 'taskTypeId' => '61a5cd07ca1347c82306ad09', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'tasks.create_a_task.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/crm/tasks", + null, + 1 + ); + } + + /** + */ + public function testGetATask(): void { + $testId = 'tasks.get_a_task.0'; + $this->client->tasks->getATask( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'tasks.get_a_task.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/tasks/id", + null, + 1 + ); + } + + /** + */ + public function testDeleteATask(): void { + $testId = 'tasks.delete_a_task.0'; + $this->client->tasks->deleteATask( + 'id', + [ + 'headers' => [ + 'X-Test-Id' => 'tasks.delete_a_task.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/crm/tasks/id", + null, + 1 + ); + } + + /** + */ + public function testUpdateATask(): void { + $testId = 'tasks.update_a_task.0'; + $this->client->tasks->updateATask( + 'id', + new PatchCrmTasksIdRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'tasks.update_a_task.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PATCH", + "/crm/tasks/id", + null, + 1 + ); + } + + /** + */ + public function testGetAllTaskTypes(): void { + $testId = 'tasks.get_all_task_types.0'; + $this->client->tasks->getAllTaskTypes( + [ + 'headers' => [ + 'X-Test-Id' => 'tasks.get_all_task_types.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/crm/tasktypes", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/TierWireTest.php b/tests/Wire/TierWireTest.php new file mode 100644 index 0000000..e218e6f --- /dev/null +++ b/tests/Wire/TierWireTest.php @@ -0,0 +1,286 @@ +client->tier->addSubscriptionToTier( + 'pid', + 'cid', + 'tid', + [ + 'headers' => [ + 'X-Test-Id' => 'tier.add_subscription_to_tier.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/tier/programs/pid/contacts/cid/tiers/tid", + null, + 1 + ); + } + + /** + */ + public function testGetListOfTierGroups(): void { + $testId = 'tier.get_list_of_tier_groups.0'; + $this->client->tier->getListOfTierGroups( + 'pid', + new GetListOfTierGroupsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.get_list_of_tier_groups.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/tier/programs/pid/tier-groups", + null, + 1 + ); + } + + /** + */ + public function testCreateTierGroup(): void { + $testId = 'tier.create_tier_group.0'; + $this->client->tier->createTierGroup( + 'pid', + new CreateTierGroupRequest([ + 'name' => 'name', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.create_tier_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/tier/programs/pid/tier-groups", + null, + 1 + ); + } + + /** + */ + public function testGetTierGroup(): void { + $testId = 'tier.get_tier_group.0'; + $this->client->tier->getTierGroup( + 'pid', + 'gid', + new GetTierGroupRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.get_tier_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/tier/programs/pid/tier-groups/gid", + null, + 1 + ); + } + + /** + */ + public function testUpdateTierGroup(): void { + $testId = 'tier.update_tier_group.0'; + $this->client->tier->updateTierGroup( + 'pid', + 'gid', + new UpdateTierGroupRequest([ + 'downgradeStrategy' => UpdateTierGroupRequestDowngradeStrategy::RealTime->value, + 'name' => 'name', + 'tierOrder' => [ + 'tierOrder', + ], + 'upgradeStrategy' => UpdateTierGroupRequestUpgradeStrategy::RealTime->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.update_tier_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/loyalty/tier/programs/pid/tier-groups/gid", + null, + 1 + ); + } + + /** + */ + public function testDeleteTierGroup(): void { + $testId = 'tier.delete_tier_group.0'; + $this->client->tier->deleteTierGroup( + 'pid', + 'gid', + [ + 'headers' => [ + 'X-Test-Id' => 'tier.delete_tier_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/tier/programs/pid/tier-groups/gid", + null, + 1 + ); + } + + /** + */ + public function testCreateTierForTierGroup(): void { + $testId = 'tier.create_tier_for_tier_group.0'; + $this->client->tier->createTierForTierGroup( + 'pid', + 'gid', + new CreateTierForTierGroupRequest([ + 'accessConditions' => [ + new CreateTierForTierGroupRequestAccessConditionsItem([]), + ], + 'name' => 'name', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.create_tier_for_tier_group.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/loyalty/tier/programs/pid/tier-groups/gid/tiers", + null, + 1 + ); + } + + /** + */ + public function testGetLoyaltyProgramTier(): void { + $testId = 'tier.get_loyalty_program_tier.0'; + $this->client->tier->getLoyaltyProgramTier( + 'pid', + new GetLoyaltyProgramTierRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.get_loyalty_program_tier.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/loyalty/tier/programs/pid/tiers", + null, + 1 + ); + } + + /** + */ + public function testUpdateTier(): void { + $testId = 'tier.update_tier.0'; + $this->client->tier->updateTier( + 'pid', + 'tid', + new UpdateTierRequest([ + 'accessConditions' => [ + new UpdateTierRequestAccessConditionsItem([]), + ], + 'name' => 'name', + 'tierRewards' => [ + new UpdateTierRequestTierRewardsItem([]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'tier.update_tier.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/loyalty/tier/programs/pid/tiers/tid", + null, + 1 + ); + } + + /** + */ + public function testDeleteTier(): void { + $testId = 'tier.delete_tier.0'; + $this->client->tier->deleteTier( + 'pid', + 'tid', + [ + 'headers' => [ + 'X-Test-Id' => 'tier.delete_tier.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/loyalty/tier/programs/pid/tiers/tid", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/TransactionalEmailsWireTest.php b/tests/Wire/TransactionalEmailsWireTest.php new file mode 100644 index 0000000..4d9ceef --- /dev/null +++ b/tests/Wire/TransactionalEmailsWireTest.php @@ -0,0 +1,535 @@ +client->transactionalEmails->getTransacBlockedContacts( + new GetTransacBlockedContactsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_transac_blocked_contacts.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/blockedContacts", + null, + 1 + ); + } + + /** + */ + public function testUnblockOrResubscribeATransactionalContact(): void { + $testId = 'transactional_emails.unblock_or_resubscribe_a_transactional_contact.0'; + $this->client->transactionalEmails->unblockOrResubscribeATransactionalContact( + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.unblock_or_resubscribe_a_transactional_contact.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/smtp/blockedContacts/email", + null, + 1 + ); + } + + /** + */ + public function testGetBlockedDomains(): void { + $testId = 'transactional_emails.get_blocked_domains.0'; + $this->client->transactionalEmails->getBlockedDomains( + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_blocked_domains.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/blockedDomains", + null, + 1 + ); + } + + /** + */ + public function testBlockNewDomain(): void { + $testId = 'transactional_emails.block_new_domain.0'; + $this->client->transactionalEmails->blockNewDomain( + new BlockNewDomainRequest([ + 'domain' => 'example.com', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.block_new_domain.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smtp/blockedDomains", + null, + 1 + ); + } + + /** + */ + public function testDeleteBlockedDomain(): void { + $testId = 'transactional_emails.delete_blocked_domain.0'; + $this->client->transactionalEmails->deleteBlockedDomain( + 'domain', + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.delete_blocked_domain.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/smtp/blockedDomains/domain", + null, + 1 + ); + } + + /** + */ + public function testDeleteHardbounces(): void { + $testId = 'transactional_emails.delete_hardbounces.0'; + $this->client->transactionalEmails->deleteHardbounces( + new DeleteHardbouncesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.delete_hardbounces.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smtp/deleteHardbounces", + null, + 1 + ); + } + + /** + */ + public function testSendTransacEmail(): void { + $testId = 'transactional_emails.send_transac_email.0'; + $this->client->transactionalEmails->sendTransacEmail( + new SendTransacEmailRequest([ + 'htmlContent' => '

Hello,

This is my first transactional email sent from Brevo.

', + 'sender' => new SendTransacEmailRequestSender([ + 'email' => 'hello@brevo.com', + 'name' => 'Alex from Brevo', + ]), + 'subject' => 'Hello from Brevo!', + 'to' => [ + new SendTransacEmailRequestToItem([ + 'email' => 'johndoe@example.com', + 'name' => 'John Doe', + ]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.send_transac_email.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smtp/email", + null, + 1 + ); + } + + /** + */ + public function testDeleteScheduledEmailById(): void { + $testId = 'transactional_emails.delete_scheduled_email_by_id.0'; + $this->client->transactionalEmails->deleteScheduledEmailById( + '4320f270-a4e3-4a2e-b591-edfe30a5e627', + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.delete_scheduled_email_by_id.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/smtp/email/4320f270-a4e3-4a2e-b591-edfe30a5e627", + null, + 1 + ); + } + + /** + */ + public function testGetScheduledEmailById(): void { + $testId = 'transactional_emails.get_scheduled_email_by_id.0'; + $this->client->transactionalEmails->getScheduledEmailById( + '4320f270-a4e3-4a2e-b591-edfe30a5e627', + new GetScheduledEmailByIdRequest([ + 'startDate' => new DateTime('2022-02-02'), + 'endDate' => new DateTime('2022-03-02'), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_scheduled_email_by_id.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/emailStatus/4320f270-a4e3-4a2e-b591-edfe30a5e627", + ['startDate' => '2022-02-02', 'endDate' => '2022-03-02'], + 1 + ); + } + + /** + */ + public function testGetTransacEmailsList(): void { + $testId = 'transactional_emails.get_transac_emails_list.0'; + $this->client->transactionalEmails->getTransacEmailsList( + new GetTransacEmailsListRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_transac_emails_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/emails", + null, + 1 + ); + } + + /** + */ + public function testGetTransacEmailContent(): void { + $testId = 'transactional_emails.get_transac_email_content.0'; + $this->client->transactionalEmails->getTransacEmailContent( + 'uuid', + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_transac_email_content.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/emails/uuid", + null, + 1 + ); + } + + /** + */ + public function testDeleteAnSmtpTransactionalLog(): void { + $testId = 'transactional_emails.delete_an_smtp_transactional_log.0'; + $this->client->transactionalEmails->deleteAnSmtpTransactionalLog( + 'identifier', + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.delete_an_smtp_transactional_log.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/smtp/log/identifier", + null, + 1 + ); + } + + /** + */ + public function testGetAggregatedSmtpReport(): void { + $testId = 'transactional_emails.get_aggregated_smtp_report.0'; + $this->client->transactionalEmails->getAggregatedSmtpReport( + new GetAggregatedSmtpReportRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_aggregated_smtp_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/statistics/aggregatedReport", + null, + 1 + ); + } + + /** + */ + public function testGetEmailEventReport(): void { + $testId = 'transactional_emails.get_email_event_report.0'; + $this->client->transactionalEmails->getEmailEventReport( + new GetEmailEventReportRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_email_event_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/statistics/events", + null, + 1 + ); + } + + /** + */ + public function testGetSmtpReport(): void { + $testId = 'transactional_emails.get_smtp_report.0'; + $this->client->transactionalEmails->getSmtpReport( + new GetSmtpReportRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_smtp_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/statistics/reports", + null, + 1 + ); + } + + /** + */ + public function testPostPreviewSmtpEmailTemplates(): void { + $testId = 'transactional_emails.post_preview_smtp_email_templates.0'; + $this->client->transactionalEmails->postPreviewSmtpEmailTemplates( + [ + 'key' => "value", + ], + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.post_preview_smtp_email_templates.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smtp/template/preview", + null, + 1 + ); + } + + /** + */ + public function testGetSmtpTemplates(): void { + $testId = 'transactional_emails.get_smtp_templates.0'; + $this->client->transactionalEmails->getSmtpTemplates( + new GetSmtpTemplatesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_smtp_templates.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/templates", + null, + 1 + ); + } + + /** + */ + public function testCreateSmtpTemplate(): void { + $testId = 'transactional_emails.create_smtp_template.0'; + $this->client->transactionalEmails->createSmtpTemplate( + new CreateSmtpTemplateRequest([ + 'sender' => new CreateSmtpTemplateRequestSender([]), + 'subject' => 'Thanks for your purchase !', + 'templateName' => 'Order Confirmation - EN', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.create_smtp_template.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smtp/templates", + null, + 1 + ); + } + + /** + */ + public function testGetSmtpTemplate(): void { + $testId = 'transactional_emails.get_smtp_template.0'; + $this->client->transactionalEmails->getSmtpTemplate( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.get_smtp_template.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/smtp/templates/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateSmtpTemplate(): void { + $testId = 'transactional_emails.update_smtp_template.0'; + $this->client->transactionalEmails->updateSmtpTemplate( + 1000000, + new UpdateSmtpTemplateRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.update_smtp_template.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/smtp/templates/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteSmtpTemplate(): void { + $testId = 'transactional_emails.delete_smtp_template.0'; + $this->client->transactionalEmails->deleteSmtpTemplate( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.delete_smtp_template.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/smtp/templates/1000000", + null, + 1 + ); + } + + /** + */ + public function testSendTestTemplate(): void { + $testId = 'transactional_emails.send_test_template.0'; + $this->client->transactionalEmails->sendTestTemplate( + 1000000, + new SendTestTemplateRequest([ + 'body' => new SendTestEmail([]), + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_emails.send_test_template.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/smtp/templates/1000000/sendTest", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/TransactionalSmsWireTest.php b/tests/Wire/TransactionalSmsWireTest.php new file mode 100644 index 0000000..c4e39c5 --- /dev/null +++ b/tests/Wire/TransactionalSmsWireTest.php @@ -0,0 +1,142 @@ +client->transactionalSms->sendAsyncTransactionalSms( + new SendTransacSms([ + 'recipient' => '33689965433', + 'sender' => 'MyShop', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_sms.send_async_transactional_sms.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/transactionalSMS/send", + null, + 1 + ); + } + + /** + */ + public function testSendTransacSms(): void { + $testId = 'transactional_sms.send_transac_sms.0'; + $this->client->transactionalSms->sendTransacSms( + new SendTransacSms([ + 'recipient' => '33689965433', + 'sender' => 'MyShop', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_sms.send_transac_sms.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/transactionalSMS/sms", + null, + 1 + ); + } + + /** + */ + public function testGetTransacAggregatedSmsReport(): void { + $testId = 'transactional_sms.get_transac_aggregated_sms_report.0'; + $this->client->transactionalSms->getTransacAggregatedSmsReport( + new GetTransacAggregatedSmsReportRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_sms.get_transac_aggregated_sms_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/transactionalSMS/statistics/aggregatedReport", + null, + 1 + ); + } + + /** + */ + public function testGetSmsEvents(): void { + $testId = 'transactional_sms.get_sms_events.0'; + $this->client->transactionalSms->getSmsEvents( + new GetSmsEventsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_sms.get_sms_events.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/transactionalSMS/statistics/events", + null, + 1 + ); + } + + /** + */ + public function testGetTransacSmsReport(): void { + $testId = 'transactional_sms.get_transac_sms_report.0'; + $this->client->transactionalSms->getTransacSmsReport( + new GetTransacSmsReportRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_sms.get_transac_sms_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/transactionalSMS/statistics/reports", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/TransactionalWhatsAppWireTest.php b/tests/Wire/TransactionalWhatsAppWireTest.php new file mode 100644 index 0000000..c314a17 --- /dev/null +++ b/tests/Wire/TransactionalWhatsAppWireTest.php @@ -0,0 +1,77 @@ +client->transactionalWhatsApp->sendWhatsappMessage( + new SendWhatsappMessageRequestParams([ + 'contactNumbers' => [ + 'contactNumbers', + ], + 'senderNumber' => 'senderNumber', + 'templateId' => 123, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_whats_app.send_whatsapp_message.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/whatsapp/sendMessage", + null, + 1 + ); + } + + /** + */ + public function testGetWhatsappEventReport(): void { + $testId = 'transactional_whats_app.get_whatsapp_event_report.0'; + $this->client->transactionalWhatsApp->getWhatsappEventReport( + new GetWhatsappEventReportRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'transactional_whats_app.get_whatsapp_event_report.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/whatsapp/statistics/events", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/UserWireTest.php b/tests/Wire/UserWireTest.php new file mode 100644 index 0000000..1ec6df3 --- /dev/null +++ b/tests/Wire/UserWireTest.php @@ -0,0 +1,168 @@ +client->user->getInvitedUsersList( + [ + 'headers' => [ + 'X-Test-Id' => 'user.get_invited_users_list.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/organization/invited/users", + null, + 1 + ); + } + + /** + */ + public function testPutRevokeUserPermission(): void { + $testId = 'user.put_revoke_user_permission.0'; + $this->client->user->putRevokeUserPermission( + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'user.put_revoke_user_permission.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/organization/user/invitation/revoke/email", + null, + 1 + ); + } + + /** + */ + public function testInviteuser(): void { + $testId = 'user.inviteuser.0'; + $this->client->user->inviteuser( + new Inviteuser([ + 'allFeaturesAccess' => true, + 'email' => 'inviteuser@example.com', + 'privileges' => [ + new InviteuserPrivilegesItem([]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'user.inviteuser.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/organization/user/invitation/send", + null, + 1 + ); + } + + /** + */ + public function testPutresendcancelinvitation(): void { + $testId = 'user.putresendcancelinvitation.0'; + $this->client->user->putresendcancelinvitation( + PutresendcancelinvitationRequestAction::Resend->value, + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'user.putresendcancelinvitation.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/organization/user/invitation/resend/email", + null, + 1 + ); + } + + /** + */ + public function testEditUserPermission(): void { + $testId = 'user.edit_user_permission.0'; + $this->client->user->editUserPermission( + new Inviteuser([ + 'allFeaturesAccess' => true, + 'email' => 'inviteuser@example.com', + 'privileges' => [ + new InviteuserPrivilegesItem([]), + ], + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'user.edit_user_permission.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/organization/user/update/permissions", + null, + 1 + ); + } + + /** + */ + public function testGetUserPermission(): void { + $testId = 'user.get_user_permission.0'; + $this->client->user->getUserPermission( + 'email', + [ + 'headers' => [ + 'X-Test-Id' => 'user.get_user_permission.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/organization/user/email/permissions", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/WebhooksWireTest.php b/tests/Wire/WebhooksWireTest.php new file mode 100644 index 0000000..699e9b7 --- /dev/null +++ b/tests/Wire/WebhooksWireTest.php @@ -0,0 +1,170 @@ +client->webhooks->getWebhooks( + new GetWebhooksRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'webhooks.get_webhooks.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/webhooks", + null, + 1 + ); + } + + /** + */ + public function testCreateWebhook(): void { + $testId = 'webhooks.create_webhook.0'; + $this->client->webhooks->createWebhook( + new CreateWebhookRequest([ + 'events' => [ + CreateWebhookRequestEventsItem::Sent->value, + ], + 'url' => 'http://requestb.in/173lyyx1', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'webhooks.create_webhook.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/webhooks", + null, + 1 + ); + } + + /** + */ + public function testExportWebhooksHistory(): void { + $testId = 'webhooks.export_webhooks_history.0'; + $this->client->webhooks->exportWebhooksHistory( + new ExportWebhooksHistoryRequest([ + 'event' => ExportWebhooksHistoryRequestEvent::InvalidParameter->value, + 'notifyUrl' => 'https://brevo.com', + 'type' => ExportWebhooksHistoryRequestType::Transactional->value, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'webhooks.export_webhooks_history.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/webhooks/export", + null, + 1 + ); + } + + /** + */ + public function testGetWebhook(): void { + $testId = 'webhooks.get_webhook.0'; + $this->client->webhooks->getWebhook( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'webhooks.get_webhook.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/webhooks/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateWebhook(): void { + $testId = 'webhooks.update_webhook.0'; + $this->client->webhooks->updateWebhook( + 1000000, + new UpdateWebhookRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'webhooks.update_webhook.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/webhooks/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteWebhook(): void { + $testId = 'webhooks.delete_webhook.0'; + $this->client->webhooks->deleteWebhook( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'webhooks.delete_webhook.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/webhooks/1000000", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/WhatsAppCampaignsWireTest.php b/tests/Wire/WhatsAppCampaignsWireTest.php new file mode 100644 index 0000000..82d1ce2 --- /dev/null +++ b/tests/Wire/WhatsAppCampaignsWireTest.php @@ -0,0 +1,233 @@ +client->whatsAppCampaigns->getWhatsAppCampaigns( + new GetWhatsAppCampaignsRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.get_whats_app_campaigns.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/whatsappCampaigns", + null, + 1 + ); + } + + /** + */ + public function testCreateWhatsAppCampaign(): void { + $testId = 'whats_app_campaigns.create_whats_app_campaign.0'; + $this->client->whatsAppCampaigns->createWhatsAppCampaign( + new CreateWhatsAppCampaignRequest([ + 'name' => 'Test Campaign', + 'recipients' => new CreateWhatsAppCampaignRequestRecipients([]), + 'scheduledAt' => '2017-06-01T12:30:00+02:00', + 'templateId' => 19, + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.create_whats_app_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/whatsappCampaigns", + null, + 1 + ); + } + + /** + */ + public function testGetWhatsAppConfig(): void { + $testId = 'whats_app_campaigns.get_whats_app_config.0'; + $this->client->whatsAppCampaigns->getWhatsAppConfig( + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.get_whats_app_config.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/whatsappCampaigns/config", + null, + 1 + ); + } + + /** + */ + public function testCreateWhatsAppTemplate(): void { + $testId = 'whats_app_campaigns.create_whats_app_template.0'; + $this->client->whatsAppCampaigns->createWhatsAppTemplate( + new CreateWhatsAppTemplateRequest([ + 'bodyText' => 'making it look like readable English', + 'category' => CreateWhatsAppTemplateRequestCategory::Marketing->value, + 'language' => 'en', + 'name' => 'Test template', + ]), + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.create_whats_app_template.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/whatsappCampaigns/template", + null, + 1 + ); + } + + /** + */ + public function testGetWhatsAppTemplates(): void { + $testId = 'whats_app_campaigns.get_whats_app_templates.0'; + $this->client->whatsAppCampaigns->getWhatsAppTemplates( + new GetWhatsAppTemplatesRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.get_whats_app_templates.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/whatsappCampaigns/template-list", + null, + 1 + ); + } + + /** + */ + public function testSendWhatsAppTemplateApproval(): void { + $testId = 'whats_app_campaigns.send_whats_app_template_approval.0'; + $this->client->whatsAppCampaigns->sendWhatsAppTemplateApproval( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.send_whats_app_template_approval.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "POST", + "/whatsappCampaigns/template/approval/1000000", + null, + 1 + ); + } + + /** + */ + public function testGetWhatsAppCampaign(): void { + $testId = 'whats_app_campaigns.get_whats_app_campaign.0'; + $this->client->whatsAppCampaigns->getWhatsAppCampaign( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.get_whats_app_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "GET", + "/whatsappCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testUpdateWhatsAppCampaign(): void { + $testId = 'whats_app_campaigns.update_whats_app_campaign.0'; + $this->client->whatsAppCampaigns->updateWhatsAppCampaign( + 1000000, + new UpdateWhatsAppCampaignRequest([]), + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.update_whats_app_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "PUT", + "/whatsappCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + public function testDeleteWhatsAppCampaign(): void { + $testId = 'whats_app_campaigns.delete_whats_app_campaign.0'; + $this->client->whatsAppCampaigns->deleteWhatsAppCampaign( + 1000000, + [ + 'headers' => [ + 'X-Test-Id' => 'whats_app_campaigns.delete_whats_app_campaign.0', + ], + ], + ); + $this->verifyRequestCount( + $testId, + "DELETE", + "/whatsappCampaigns/1000000", + null, + 1 + ); + } + + /** + */ + protected function setUp(): void { + parent::setUp(); + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $this->client = new Brevo( + apiKey: 'test-apiKey', + options: [ + 'baseUrl' => $wiremockUrl, + ], + ); + } +} diff --git a/tests/Wire/WireMockTestCase.php b/tests/Wire/WireMockTestCase.php new file mode 100644 index 0000000..47d2307 --- /dev/null +++ b/tests/Wire/WireMockTestCase.php @@ -0,0 +1,80 @@ +|null $queryParams Query parameters to match + * @param int $expected Expected number of requests + */ + protected function verifyRequestCount( + string $testId, + string $method, + string $urlPath, + ?array $queryParams, + int $expected + ): void { + $client = Psr18ClientDiscovery::find(); + $requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + $streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + + $body = [ + 'method' => $method, + 'urlPath' => $urlPath, + 'headers' => [ + 'X-Test-Id' => ['equalTo' => $testId], + ], + ]; + if ($queryParams !== null && $queryParams !== []) { + $body['queryParameters'] = []; + foreach ($queryParams as $k => $v) { + $body['queryParameters'][$k] = ['equalTo' => (string) $v]; + } + } + + $wiremockUrl = getenv('WIREMOCK_URL') ?: 'http://localhost:8080'; + $request = $requestFactory->createRequest('POST', $wiremockUrl . '/__admin/requests/find') + ->withHeader('Content-Type', 'application/json') + ->withBody($streamFactory->createStream(JsonEncoder::encode($body))); + $response = $client->sendRequest($request); + + $this->assertSame(200, $response->getStatusCode(), 'Failed to query WireMock requests'); + + $json = json_decode((string) $response->getBody(), true); + + // Ensure we have an array; otherwise, fail the test. + if (!is_array($json)) { + $this->fail('Expected WireMock to return a JSON object.'); + } + + /** @var array $json */ + $requests = []; + if (isset($json['requests']) && is_array($json['requests'])) { + $requests = $json['requests']; + } + + /** @var array $requests */ + $this->assertCount( + $expected, + $requests, + sprintf('Expected %d requests, found %d', $expected, count($requests)) + ); + } +} diff --git a/tests/Wire/bootstrap.php b/tests/Wire/bootstrap.php new file mode 100644 index 0000000..2002666 --- /dev/null +++ b/tests/Wire/bootstrap.php @@ -0,0 +1,55 @@ +&1', + escapeshellarg($dockerComposeFile) +); +exec($cmd, $output, $exitCode); +if ($exitCode !== 0) { + throw new \RuntimeException("Failed to start WireMock: " . implode("\n", $output)); +} + +// Discover the dynamically assigned port +$portCmd = sprintf( + 'docker compose -f %s port wiremock 8080 2>&1', + escapeshellarg($dockerComposeFile) +); +exec($portCmd, $portOutput, $portExitCode); +if ($portExitCode === 0 && !empty($portOutput[0])) { + $parts = explode(':', $portOutput[0]); + $port = end($parts); + putenv("WIREMOCK_URL=http://localhost:{$port}"); + echo "WireMock container is ready on port {$port}\n"; +} else { + putenv('WIREMOCK_URL=http://localhost:8080'); + echo "WireMock container is ready (default port 8080)\n"; +} + +// Register shutdown function to stop the container after all tests complete +register_shutdown_function(function () use ($dockerComposeFile) { + echo "\nStopping WireMock container...\n"; + $cmd = sprintf( + 'docker compose -f %s down -v 2>&1', + escapeshellarg($dockerComposeFile) + ); + exec($cmd); +}); diff --git a/wiremock/docker-compose.test.yml b/wiremock/docker-compose.test.yml new file mode 100644 index 0000000..58747d5 --- /dev/null +++ b/wiremock/docker-compose.test.yml @@ -0,0 +1,14 @@ +services: + wiremock: + image: wiremock/wiremock:3.9.1 + ports: + - "0:8080" # Use dynamic port to avoid conflicts with concurrent tests + volumes: + - ./wiremock-mappings.json:/home/wiremock/mappings/wiremock-mappings.json + command: ["--global-response-templating", "--verbose"] + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/__admin/health"] + interval: 2s + timeout: 5s + retries: 15 + start_period: 5s