Skip to content

Commit

Permalink
Refactor tests, add readme section and changelog about merging
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubTesarek committed Aug 19, 2021
1 parent 1de9e9a commit 396b624
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
### Added
- Added optional argument timestamp to UserMerge command.


## 4.0.0 - 2020-12-17
### Added
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ $response = $matej->request()
->addItemProperty(ItemProperty::create('item-id', ['valid_from' => time(), 'title' => 'Title']))
->addItemProperties([/* array of ItemProperty objects */])
// Merge user
->addUserMerge(UserMerge::mergeInto('target-user-id', 'source-user-id'), time())
->addUserMerge(UserMerge::mergeInto('target-user-id', 'source-user-id', 1629361884))
->addUserMerges([/* array of UserMerge objects */])
->send();
```
Expand All @@ -186,6 +186,16 @@ If that happens, you should resend the entire request later, as no commands were

This has been implemented so that we don't lose any pushed data. Simple sleep of 100ms should be enough.

### Merging users

You can merge users using the `UserMerge` command. The first argument is the target user ID and the second argument is the ID
of source user. When you merge two users, Matej will move all interactions and history of the source user and assign them to
the target user. The source user is then removed.

Optionally, you may send a third argument with a timestamp of when the merge happened.

**The timestamp will be required in the future. We reccommend you to send it which will make future upgrades of the Matej client easier for you.**

### Requesting recommendations

You can request 4 types of recommendations from Matej. Each of them is represented by a specific recommendation command class:
Expand All @@ -205,7 +215,7 @@ $matej = new Matej('accountId', 'apikey');
$response = $matej->request()
->recommendation(UserItemRecommendation::create('user-id', 'test-scenario'))
->setInteraction(Interaction::withItem('purchases', 'user-id', 'item-id')) // optional
->setUserMerge(UserMerge::mergeInto('user-id', 'source-id', time())) // optional
->setUserMerge(UserMerge::mergeInto('user-id', 'source-id')) // optional
->send();

$recommendations = $response->getRecommendation()->getData();
Expand Down Expand Up @@ -330,7 +340,7 @@ $matej = new Matej('accountId', 'apikey');
$response = $matej->request()
->sorting(ItemSorting::create('user-id', ['item-id-1', 'item-id-2', 'item-id-3']))
->setInteraction(Interaction::withItem('purchases', 'user-id', 'item-id')) // optional
->setUserMerge(UserMerge::mergeInto('user-id', 'source-id', time())) // optional
->setUserMerge(UserMerge::mergeInto('user-id', 'source-id')) // optional
->send();

$sortedItems = $response->getSorting()->getData();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Http/RequestManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function shouldSendAndDecodeRequest(): void
// Assert properties of the send request
$recordedRequests = $mockClient->getRequests();
$this->assertCount(1, $recordedRequests);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'~https\://account\-id\.matej\.lmc\.cz/foo/endpoint\?hmac_timestamp\=[0-9]+&hmac_sign\=[[:alnum:]]~',
$recordedRequests[0]->getUri()->__toString()
);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Model/Command/UserMergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function shouldGenerateCorrectSignature(): void
{
$sourceUserId = 'source-user';
$targetUserId = 'target-user';
$timestamp = time();
$timestamp = 1629362296;

$command = UserMerge::mergeInto($targetUserId, $sourceUserId, $timestamp);
$this->assertUserMergeCommand($command, $sourceUserId, $targetUserId, $timestamp);
Expand Down

0 comments on commit 396b624

Please sign in to comment.