Skip to content

Commit

Permalink
Merge pull request #80 from voucherifyio/ma/custom-events-tests
Browse files Browse the repository at this point in the history
Custom-Events Tests
  • Loading branch information
mandraszyk authored Jun 16, 2022
2 parents e81a928 + 0bacece commit 2751901
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ API:
|
<a href="#segments-api">Segments</a>
|
<a href="#events-api">Events</a>
|
<a href="#promotions-api">Promotions</a>
|
<a href="#async-actions-api">Async Actions</a>
|
<a href="#utils">Utils</a>
</p>

Expand Down Expand Up @@ -529,6 +533,18 @@ $client->segments->get($segment_id);
$client->segments->delete($segment_id);
```

---
### Events API
Methods are provided within `$client->customEvents->*` namespace.
- [Track Custom Event](#track-custom-event)

Check [event object](https://docs.voucherify.io/reference/the-custom-event-object?utm_source=github&utm_medium=sdk&utm_campaign=acq).

#### [Track Custom Event]
```php
$client->customEvent->track($event, $customer);
```

---

### Promotions API
Expand Down Expand Up @@ -587,6 +603,8 @@ $client->promotions->tiers->delete($promotionTierId);
$client->promotions->tiers->getAvailable();
```

---

### Async Actions API
Methods are provided within `$client->asyncActions->*` namespace.
- [Get Async Action](#get-async-action)
Expand Down Expand Up @@ -747,6 +765,7 @@ class Voucher extends CI_Controller {
Bug reports and pull requests are welcome through [GitHub Issues](https://github.com/rspective/voucherify-php-sdk/issues).

### Changelog
- **2022-05-16** - `2.2.0` - Add CustomEvents support
- **2022-03-11** - `2.1.0` - Add AsyncActions support and a `$customHeaders` param
- **2019-07-19** - `2.0.0` - Hide API versioning in `$apiUrl` param
- **2018-12-28** - `1.7.10` - Add Validation Rule Assignments
Expand Down Expand Up @@ -869,3 +888,5 @@ Bug reports and pull requests are welcome through [GitHub Issues](https://github
[Update Promotion's Tier]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-promotion
[Delete Promotion's Tier]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-promotion
[List Available Promotion Tiers]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#introduction-1

[Track Custom Event]: https://docs.voucherify.io/reference/create-custom-event?utm_source=github&utm_medium=sdk&utm_campaign=acq
12 changes: 6 additions & 6 deletions src/CustomEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public function __construct($client)
public function track($event, $customer, $metadata = null, $referral = null, $loyalty = null)
{
$params = [
'event' => $event,
'customer' => $customer,
"event" => $event,
"customer" => $customer
];

if ($metadata) {
$params['metadata'] = (object)$metadata;
$params["metadata"] = (object)$metadata;
}

if ($referral) {
$params['referral'] = (object)$referral;
$params["referral"] = (object)$referral;
}

if ($loyalty) {
$params['loyalty'] = (object)$loyalty;
$params["loyalty"] = (object)$loyalty;
}

return $this->client->post("/events", $params);
return $this->client->post("/events/", $params);
}
}
8 changes: 4 additions & 4 deletions test/AsyncActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public static function setUpBeforeClass()
self::$apiId = "c70a6f00-cf91-4756-9df5-47628850002b";
self::$apiKey = "3266b9f8-e246-4f79-bdf0-833929b1380c";
self::$headers = [
"Content-Type: application/json",
"X-App-Id: " . self::$apiId,
"X-App-Token: " . self::$apiKey,
"X-Voucherify-Channel: PHP-SDK"
"content-type: application/json",
"x-app-id: " . self::$apiId,
"x-app-token: " . self::$apiKey,
"x-voucherify-channel: PHP-SDK"
];
self::$client = new VoucherifyClient(self::$apiId, self::$apiKey);

Expand Down
54 changes: 54 additions & 0 deletions test/CustomEventsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

use Voucherify\Test\Helpers\CurlMock;

use Voucherify\VoucherifyClient;
use Voucherify\ClientException;

class CustomEventsTest extends PHPUnit_Framework_TestCase
{
protected static $headers;
protected static $apiId;
protected static $apiKey;
protected static $client;

public static function setUpBeforeClass()
{
self::$apiId = "c70a6f00-cf91-4756-9df5-47628850002b";
self::$apiKey = "3266b9f8-e246-4f79-bdf0-833929b1380c";
self::$headers = [
"content-type: application/json",
"x-app-id: " . self::$apiId,
"x-app-token: " . self::$apiKey,
"x-voucherify-channel: PHP-SDK"
];
self::$client = new VoucherifyClient(self::$apiId, self::$apiKey);

CurlMock::enable();
}

public static function tearDownAfterClass()
{
CurlMock::disable();
}

public function testTrack()
{
CurlMock::register("https://api.voucherify.io/v1", self::$headers)
->post("/events/", [
"event" => "php-event",
"customer" => [
"source_id" => "php-test-customer"
]
])
->reply(200, [ "status" => "ok" ]);

$result = self::$client->customEvents->track("php-event", (object)[
"source_id" => "php-test-customer"
]);

$this->assertEquals($result, (object)[ "status" => "ok" ]);

CurlMock::done();
}
}

0 comments on commit 2751901

Please sign in to comment.