Skip to content

Commit

Permalink
fix(response): add missing available include relationships to the res…
Browse files Browse the repository at this point in the history
…ponse (#54)
  • Loading branch information
nicolasalexandre9 authored May 12, 2023
1 parent 59f5f7b commit d098cd2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Agent/Routes/Resources/Related/CountRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function handleRequest(array $args = []): array
$this->caller,
$this->filter,
new Aggregation(operation: 'Count')
);
)[0]['value'] ?? 0;

return [
'content' => compact('count'),
Expand Down
1 change: 1 addition & 0 deletions src/Agent/Services/JsonApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function renderCollection($class, TransformerAbstract $transformer, strin
public function renderItem($data, TransformerAbstract $transformer, string $name)
{
$this->fractal->setSerializer(new JsonApiSerializer());
$transformer->setAvailableIncludes(ForestSchema::getRelatedData($name));

return $this->fractal->createData(new Item($data, $transformer, $name))->toArray();
}
Expand Down
16 changes: 4 additions & 12 deletions tests/Agent/Routes/Resources/Related/CountRelatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function factoryCountRelated($args = []): CountRelated
$collectionCar = mock($collectionCar)
->shouldReceive('aggregate')
->with(\Mockery::type(Caller::class), \Mockery::type(Filter::class), \Mockery::type(Aggregation::class), null)
->andReturn(count($args['count']))
->andReturn($args['count'])
->getMock();
}

Expand Down Expand Up @@ -108,16 +108,8 @@ function factoryCountRelated($args = []): CountRelated
test('handleRequest() should return a response 200', function () {
$data = [
[
'id' => 1,
'model' => 'F8',
'brand' => 'Ferrari',
'user_id' => 1,
],
[
'id' => 2,
'model' => 'Aventador',
'brand' => 'Lamborghini',
'user_id' => 1,
'value' => 2,
'group' => [],
],
];

Expand All @@ -128,7 +120,7 @@ function factoryCountRelated($args = []): CountRelated
->toEqual(
[
'content' => [
'count' => count($data),
'count' => $data[0]['value'],
],
]
);
Expand Down

0 comments on commit d098cd2

Please sign in to comment.