Skip to content

Commit cf894ec

Browse files
committed
Remove resource relationship from queue jobs resource
1 parent 13e5ef9 commit cf894ec

File tree

6 files changed

+15
-50
lines changed

6 files changed

+15
-50
lines changed

src/Queue/ClientJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function getResource()
184184
}
185185

186186
return $this->getApi()->getStore()->find(
187-
ResourceIdentifier::create($this->resource_type, $this->resource_id)
187+
ResourceIdentifier::create($this->resource_type, (string) $this->resource_id)
188188
);
189189
}
190190

src/Queue/ClientJobSchema.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,6 @@ public function getAttributes($resource)
5151
];
5252
}
5353

54-
/**
55-
* @param ClientJob $resource
56-
* @param bool $isPrimary
57-
* @param array $includeRelationships
58-
* @return array
59-
*/
60-
public function getRelationships($resource, $isPrimary, array $includeRelationships)
61-
{
62-
return [
63-
'resource' => [
64-
self::SHOW_SELF => true,
65-
self::SHOW_RELATED => true,
66-
self::SHOW_DATA => isset($includeRelationships['resource']),
67-
self::DATA => function () use ($resource) {
68-
return $resource->getResource();
69-
},
70-
],
71-
];
72-
}
73-
7454
/**
7555
* @param ClientJob|null $resource
7656
* @return string

src/Queue/ClientJobValidators.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ClientJobValidators extends AbstractValidators
1111
/**
1212
* @var array
1313
*/
14-
protected $allowedIncludePaths = ['resource'];
14+
protected $allowedIncludePaths = [];
1515

1616
/**
1717
* @inheritDoc

tests/dummy/database/factories/ClientJobFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
use CloudCreativity\LaravelJsonApi\Queue\ClientJob;
19+
use DummyApp\Download;
1920
use Faker\Generator as Faker;
2021
use Illuminate\Database\Eloquent\Factory;
2122

@@ -35,5 +36,6 @@
3536
'completed_at' => $faker->dateTimeBetween('-10 minutes', 'now'),
3637
'failed' => false,
3738
'attempts' => $faker->numberBetween(1, 3),
39+
'resource_id' => factory(Download::class)->create()->getRouteKey(),
3840
];
3941
});

tests/lib/Integration/Queue/ClientDispatchTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,12 @@ public function testUpdate()
157157
'timeout-at' => Carbon::now()->addSeconds(25)->format('Y-m-d\TH:i:s.uP'),
158158
'tries' => null,
159159
],
160-
'relationships' => [
161-
'resource' => [
162-
'data' => [
163-
'type' => 'downloads',
164-
'id' => (string) $download->getRouteKey(),
165-
],
166-
],
167-
],
168160
];
169161

170-
$this->doUpdate($data, ['include' => 'resource'])->assertAcceptedWithId(
162+
$this->doUpdate($data)->assertAcceptedWithId(
171163
'http://localhost/api/v1/downloads/queue-jobs',
172164
$expected
173-
)->assertIsIncluded('downloads', $download);
165+
);
174166

175167
$job = $this->assertDispatchedReplace();
176168

tests/lib/Integration/Queue/QueueJobsTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ public function testReadPending()
3838
*/
3939
public function testReadNotPending()
4040
{
41-
$job = factory(ClientJob::class)->states('success')->create([
42-
'resource_id' => '5b08ebcb-114b-4f9e-a0db-bd8bd046e74c',
43-
]);
44-
45-
$location = "http://localhost/api/v1/downloads/5b08ebcb-114b-4f9e-a0db-bd8bd046e74c";
41+
$job = factory(ClientJob::class)->states('success')->create();
42+
$location = "http://localhost/api/v1/downloads/{$job->resource_id}";
4643

4744
$this->getJsonApi($this->jobUrl($job))
4845
->assertStatus(303)
@@ -55,7 +52,7 @@ public function testReadNotPending()
5552
*/
5653
public function testReadNotPendingCannotSeeOther()
5754
{
58-
$job = factory(ClientJob::class)->states('success')->create();
55+
$job = factory(ClientJob::class)->states('success')->create(['resource_id' => null]);
5956
$expected = $this->serialize($job);
6057

6158
$this->getJsonApi($this->jobUrl($job))
@@ -78,9 +75,11 @@ public function testReadNotFound()
7875
*/
7976
private function jobUrl(ClientJob $job, string $resourceType = null): string
8077
{
81-
$resourceType = $resourceType ?: $job->resource_type;
82-
83-
return "/api/v1/{$resourceType}/queue-jobs/{$job->getRouteKey()}";
78+
return url('/api/v1', [
79+
$resourceType ?: $job->resource_type,
80+
'queue-jobs',
81+
$job
82+
]);
8483
}
8584

8685
/**
@@ -91,7 +90,7 @@ private function jobUrl(ClientJob $job, string $resourceType = null): string
9190
*/
9291
private function serialize(ClientJob $job): array
9392
{
94-
$self = "http://localhost" . $this->jobUrl($job);
93+
$self = $this->jobUrl($job);
9594
$format = 'Y-m-d\TH:i:s.uP';
9695

9796
return [
@@ -108,14 +107,6 @@ private function serialize(ClientJob $job): array
108107
'tries' => $job->tries,
109108
'updated-at' => $job->updated_at->format($format),
110109
],
111-
'relationships' => [
112-
'resource' => [
113-
'links' => [
114-
'self' => "{$self}/relationships/resource",
115-
'related' => "{$self}/resource",
116-
],
117-
],
118-
],
119110
'links' => [
120111
'self' => $self,
121112
],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy