Skip to content

Commit

Permalink
✨ Deal with sparse arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Apr 5, 2021
1 parent 954bc27 commit e8b4641
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ function (array $user) {
),
];
},
$account["members"]
array_values($account["members"])
);
}

Expand Down
45 changes: 45 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,51 @@ public function test_it_upserts_account_without_account_id()
}
}

public function test_it_deals_with_sparse_arrays()
{
$factory = new Psr17Factory();
$json = '{"message":"The data is correctly stored.","meta":{"status":201,"requestId":"01ETG3HQ4JY4HNNZ84FBJM3CSC"}}';
$http = new HttpClientFixed(new Response(201, [], $json));
$client = new Client($http, $factory, $factory, ["apiKey" => "key"]);
$now = new DateTimeImmutable("now");

$this->assertEquals(
new CallResult(true, false, 0, 0, [], null),
$client->upsertAccount(
[
"accountId" => "1",
"members" => [
1 => ["userId" => "1"],
2 => ["userId" => "2"],
],
]
)
);

$request = $http->getLastRequest();
$this->assertInstanceOf(RequestInterface::class, $request);
if ($request instanceof RequestInterface) {
$request->getBody()->rewind();
$body = $request->getBody()->getContents();
$payload = json_decode($body, true);
$this->assertEquals(
[
"identification" => [
"accountId" => "1",
],
"members" => [
[
"identification" => ["userId" => "1"],
],
[
"identification" => ["userId" => "2"],
],
],
],
$payload
);
}
}

public function test_it_triggers_event_for_user()
{
Expand Down

0 comments on commit e8b4641

Please sign in to comment.