-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for /users/merge endpoint
- Loading branch information
1 parent
228be73
commit f7c30ad
Showing
9 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Object\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Exception\ValidationException; | ||
use ImmobiliareLabs\BrazeSDK\Object\BaseObject; | ||
use ImmobiliareLabs\BrazeSDK\Object\UserAlias; | ||
|
||
class MergeIdentifier extends BaseObject | ||
{ | ||
public ?string $external_id = null; | ||
|
||
public ?UserAlias $user_alias = null; | ||
|
||
public function validate(bool $strict): void | ||
{ | ||
parent::validate($strict); | ||
|
||
if (null === $this->external_id && null === $this->user_alias) { | ||
throw new ValidationException('One of "external_id" or "user_alias" fields is required'); | ||
} | ||
|
||
if (null !== $this->external_id && null !== $this->user_alias) { | ||
throw new ValidationException('Only one of "external_id" and "user_alias" fields must be set'); | ||
} | ||
|
||
$this->user_alias?->validate($strict); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Object\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Exception\ValidationException; | ||
use ImmobiliareLabs\BrazeSDK\Object\BaseObject; | ||
|
||
class MergeUpdate extends BaseObject | ||
{ | ||
public ?MergeIdentifier $identifier_to_merge = null; | ||
|
||
public ?MergeIdentifier $identifier_to_keep = null; | ||
|
||
public function validate(bool $strict): void | ||
{ | ||
parent::validate($strict); | ||
|
||
if (null === $this->identifier_to_merge) { | ||
throw new ValidationException('The "identifier_to_merge" field is required'); | ||
} | ||
|
||
if (null === $this->identifier_to_keep) { | ||
throw new ValidationException('The "identifier_to_keep" field is required'); | ||
} | ||
|
||
$this->identifier_to_merge->validate($strict); | ||
$this->identifier_to_keep->validate($strict); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Request\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Exception\ValidationException; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\MergeUpdate; | ||
use ImmobiliareLabs\BrazeSDK\Request\BaseRequest; | ||
|
||
class MergeRequest extends BaseRequest | ||
{ | ||
/** @var ?MergeUpdate[] */ | ||
public ?array $merge_updates = null; | ||
|
||
public function validate(bool $strict): void | ||
{ | ||
parent::validate($strict); | ||
|
||
if (empty($this->merge_updates)) { | ||
throw new ValidationException('The "merge_updates" field must be non empty'); | ||
} | ||
|
||
foreach ($this->merge_updates as $merge_update) { | ||
$merge_update->validate($strict); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Response\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Response\BaseResponse; | ||
|
||
class MergeResponse extends BaseResponse | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Test\Object\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Exception\ValidationException; | ||
use ImmobiliareLabs\BrazeSDK\Object\UserAlias; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\MergeIdentifier; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\NewUserAlias; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MergeIdentifierTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider validProvider | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function testValid(MergeIdentifier $mergeIdentifier): void | ||
{ | ||
$mergeIdentifier->validate(true); | ||
} | ||
|
||
/** | ||
* @dataProvider validProvider | ||
*/ | ||
public function testNoIdentifier(MergeIdentifier $mergeIdentifier): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
|
||
$mergeIdentifier->external_id = null; | ||
|
||
$mergeIdentifier->validate(false); | ||
} | ||
|
||
/** | ||
* @dataProvider validProvider | ||
*/ | ||
public function testBothIdentifier(MergeIdentifier $mergeIdentifier): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
|
||
$mergeIdentifier->user_alias = new UserAlias(); | ||
|
||
$mergeIdentifier->validate(false); | ||
} | ||
|
||
public function validProvider(): array | ||
{ | ||
$mergeIdentifier = new MergeIdentifier(); | ||
$mergeIdentifier->external_id = 'external_id'; | ||
|
||
return [ | ||
[$mergeIdentifier], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Test\Object\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Exception\ValidationException; | ||
use ImmobiliareLabs\BrazeSDK\Object\UserAlias; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\MergeIdentifier; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\MergeUpdate; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\NewUserAlias; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MergeUpdateTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider validProvider | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function testValid(MergeUpdate $mergeUpdate): void | ||
{ | ||
$mergeUpdate->validate(true); | ||
} | ||
|
||
/** | ||
* @dataProvider validProvider | ||
*/ | ||
public function testNoIdentifierToMerge(MergeUpdate $mergeUpdate): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
|
||
$mergeUpdate->identifier_to_merge = null; | ||
|
||
$mergeUpdate->validate(false); | ||
} | ||
|
||
/** | ||
* @dataProvider validProvider | ||
*/ | ||
public function testNoIdentifierToKeep(MergeUpdate $mergeUpdate): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
|
||
$mergeUpdate->identifier_to_keep = null; | ||
|
||
$mergeUpdate->validate(false); | ||
} | ||
|
||
public function validProvider(): array | ||
{ | ||
$mergeUpdate = new MergeUpdate(); | ||
|
||
$mergeUpdate->identifier_to_merge = new MergeIdentifier(); | ||
$mergeUpdate->identifier_to_merge->user_alias = new UserAlias(); | ||
$mergeUpdate->identifier_to_merge->user_alias->alias_label = 'label'; | ||
$mergeUpdate->identifier_to_merge->user_alias->alias_name = 'name'; | ||
|
||
$mergeUpdate->identifier_to_keep = new MergeIdentifier(); | ||
$mergeUpdate->identifier_to_keep->external_id = 'external-id-to-keep'; | ||
|
||
|
||
return [ | ||
[$mergeUpdate], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace ImmobiliareLabs\BrazeSDK\Test\Request\Users; | ||
|
||
use ImmobiliareLabs\BrazeSDK\Exception\ValidationException; | ||
use ImmobiliareLabs\BrazeSDK\Object\UserAlias; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\MergeIdentifier; | ||
use ImmobiliareLabs\BrazeSDK\Object\Users\MergeUpdate; | ||
use ImmobiliareLabs\BrazeSDK\Request\Users\IdentifyRequest; | ||
use ImmobiliareLabs\BrazeSDK\Request\Users\MergeRequest; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MergeRequestTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider validProvider | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function testValid(MergeRequest $mergeRequest): void | ||
{ | ||
$mergeRequest->validate(true); | ||
} | ||
|
||
/** | ||
* @dataProvider validProvider | ||
*/ | ||
public function testMergeUpdatesNull(MergeRequest $mergeRequest): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
|
||
$mergeRequest->merge_updates = null; | ||
|
||
$mergeRequest->validate(false); | ||
} | ||
|
||
/** | ||
* @dataProvider validProvider | ||
*/ | ||
public function testMergeUpdatesEmpty(MergeRequest $mergeRequest): void | ||
{ | ||
$this->expectException(ValidationException::class); | ||
|
||
$mergeRequest->merge_updates = []; | ||
|
||
$mergeRequest->validate(false); | ||
} | ||
|
||
public function validProvider(): array | ||
{ | ||
$mergeUpdate = new MergeUpdate(); | ||
|
||
$mergeUpdate->identifier_to_merge = new MergeIdentifier(); | ||
$mergeUpdate->identifier_to_merge->user_alias = new UserAlias(); | ||
$mergeUpdate->identifier_to_merge->user_alias->alias_label = 'label'; | ||
$mergeUpdate->identifier_to_merge->user_alias->alias_name = 'name'; | ||
|
||
$mergeUpdate->identifier_to_keep = new MergeIdentifier(); | ||
$mergeUpdate->identifier_to_keep->external_id = 'external-id-to-keep'; | ||
|
||
$mergeRequest = new MergeRequest(); | ||
$mergeRequest->merge_updates = [$mergeUpdate]; | ||
|
||
return [ | ||
[$mergeRequest], | ||
]; | ||
} | ||
} |