Skip to content

Commit 749fb70

Browse files
authored
Merge pull request #3145 from teohhanhui/test-update-embedded-relation-plain-id
Add test for updating embedded relation using plain identifier
2 parents c1b89a1 + b501e39 commit 749fb70

File tree

6 files changed

+236
-135
lines changed

6 files changed

+236
-135
lines changed

features/json/relation.feature

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
Feature: JSON relations support
2+
In order to use a hypermedia API
3+
As a client software developer
4+
I need to be able to update relations between resources
5+
6+
@createSchema
7+
Scenario: Create a third level
8+
When I add "Content-Type" header equal to "application/json"
9+
And I send a "POST" request to "/third_levels" with body:
10+
"""
11+
{
12+
"level": 3
13+
}
14+
"""
15+
Then the response status code should be 201
16+
And the response should be in JSON
17+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
18+
And the JSON should be equal to:
19+
"""
20+
{
21+
"@context": "/contexts/ThirdLevel",
22+
"@id": "/third_levels/1",
23+
"@type": "ThirdLevel",
24+
"fourthLevel": null,
25+
"badFourthLevel": null,
26+
"id": 1,
27+
"level": 3,
28+
"test": true
29+
}
30+
"""
31+
32+
Scenario: Create a new relation
33+
When I add "Content-Type" header equal to "application/json"
34+
And I send a "POST" request to "/relation_embedders" with body:
35+
"""
36+
{
37+
"anotherRelated": {
38+
"symfony": "laravel"
39+
}
40+
}
41+
"""
42+
Then the response status code should be 201
43+
And the response should be in JSON
44+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
45+
And the JSON should be equal to:
46+
"""
47+
{
48+
"@context": "/contexts/RelationEmbedder",
49+
"@id": "/relation_embedders/1",
50+
"@type": "RelationEmbedder",
51+
"krondstadt": "Krondstadt",
52+
"anotherRelated": {
53+
"@id": "/related_dummies/1",
54+
"@type": "https://schema.org/Product",
55+
"symfony": "laravel",
56+
"thirdLevel": null
57+
},
58+
"related": null
59+
}
60+
"""
61+
62+
Scenario: Update the relation with a new one
63+
When I add "Content-Type" header equal to "application/json"
64+
And I send a "PUT" request to "/relation_embedders/1" with body:
65+
"""
66+
{
67+
"anotherRelated": {
68+
"symfony": "laravel2"
69+
}
70+
}
71+
"""
72+
Then the response status code should be 200
73+
And the response should be in JSON
74+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
75+
And the JSON should be equal to:
76+
"""
77+
{
78+
"@context": "/contexts/RelationEmbedder",
79+
"@id": "/relation_embedders/1",
80+
"@type": "RelationEmbedder",
81+
"krondstadt": "Krondstadt",
82+
"anotherRelated": {
83+
"@id": "/related_dummies/2",
84+
"@type": "https://schema.org/Product",
85+
"symfony": "laravel2",
86+
"thirdLevel": null
87+
},
88+
"related": null
89+
}
90+
"""
91+
92+
Scenario: Update an embedded relation using an IRI
93+
When I add "Content-Type" header equal to "application/json"
94+
And I send a "PUT" request to "/relation_embedders/1" with body:
95+
"""
96+
{
97+
"anotherRelated": {
98+
"id": "/related_dummies/1",
99+
"symfony": "API Platform"
100+
}
101+
}
102+
"""
103+
Then the response status code should be 200
104+
And the response should be in JSON
105+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
106+
And the JSON should be equal to:
107+
"""
108+
{
109+
"@context": "/contexts/RelationEmbedder",
110+
"@id": "/relation_embedders/1",
111+
"@type": "RelationEmbedder",
112+
"krondstadt": "Krondstadt",
113+
"anotherRelated": {
114+
"@id": "/related_dummies/1",
115+
"@type": "https://schema.org/Product",
116+
"symfony": "API Platform",
117+
"thirdLevel": null
118+
},
119+
"related": null
120+
}
121+
"""
122+
123+
Scenario: Update an embedded relation using plain identifiers
124+
When I add "Content-Type" header equal to "application/json"
125+
And I send a "PUT" request to "/relation_embedders/1" with body:
126+
"""
127+
{
128+
"anotherRelated": {
129+
"id": 1,
130+
"symfony": "API Platform 2"
131+
}
132+
}
133+
"""
134+
Then the response status code should be 200
135+
And the response should be in JSON
136+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
137+
And the JSON should be equal to:
138+
"""
139+
{
140+
"@context": "/contexts/RelationEmbedder",
141+
"@id": "/relation_embedders/1",
142+
"@type": "RelationEmbedder",
143+
"krondstadt": "Krondstadt",
144+
"anotherRelated": {
145+
"@id": "/related_dummies/1",
146+
"@type": "https://schema.org/Product",
147+
"symfony": "API Platform 2",
148+
"thirdLevel": null
149+
},
150+
"related": null
151+
}
152+
"""
153+
154+
Scenario: Create a related dummy with a relation
155+
When I add "Content-Type" header equal to "application/json"
156+
And I send a "POST" request to "/related_dummies" with body:
157+
"""
158+
{
159+
"thirdLevel": "1"
160+
}
161+
"""
162+
Then the response status code should be 201
163+
And the response should be in JSON
164+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
165+
And the JSON should be equal to:
166+
"""
167+
{
168+
"@context": "/contexts/RelatedDummy",
169+
"@id": "/related_dummies/3",
170+
"@type": "https://schema.org/Product",
171+
"id": 3,
172+
"name": null,
173+
"symfony": "symfony",
174+
"dummyDate": null,
175+
"thirdLevel": {
176+
"@id": "/third_levels/1",
177+
"@type": "ThirdLevel",
178+
"fourthLevel": null
179+
},
180+
"relatedToDummyFriend": [],
181+
"dummyBoolean": null,
182+
"embeddedDummy": [],
183+
"age": null
184+
}
185+
"""
186+
187+
Scenario: Passing a (valid) plain identifier on a relation
188+
When I add "Content-Type" header equal to "application/json"
189+
And I send a "POST" request to "/dummies" with body:
190+
"""
191+
{
192+
"relatedDummy": "1",
193+
"relatedDummies": [
194+
"1"
195+
],
196+
"name": "Dummy with plain relations"
197+
}
198+
"""
199+
Then the response status code should be 201
200+
And the response should be in JSON
201+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
202+
And the JSON should be equal to:
203+
"""
204+
{
205+
"@context": "/contexts/Dummy",
206+
"@id": "/dummies/1",
207+
"@type": "Dummy",
208+
"description": null,
209+
"dummy": null,
210+
"dummyBoolean": null,
211+
"dummyDate": null,
212+
"dummyFloat": null,
213+
"dummyPrice": null,
214+
"relatedDummy": "/related_dummies/1",
215+
"relatedDummies": [
216+
"/related_dummies/1"
217+
],
218+
"jsonData": [],
219+
"arrayData": [],
220+
"name_converted": null,
221+
"relatedOwnedDummy": null,
222+
"relatedOwningDummy": null,
223+
"id": 1,
224+
"name": "Dummy with plain relations",
225+
"alias": null,
226+
"foo": null
227+
}
228+
"""

features/main/relation.feature

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -365,66 +365,6 @@ Feature: Relations support
365365
And the response should be in JSON
366366
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
367367

368-
Scenario: Create a new relation (json)
369-
When I add "Content-Type" header equal to "application/json"
370-
And I send a "POST" request to "/relation_embedders" with body:
371-
"""
372-
{
373-
"anotherRelated": {
374-
"symfony": "laravel"
375-
}
376-
}
377-
"""
378-
Then the response status code should be 201
379-
And the response should be in JSON
380-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
381-
And the JSON should be equal to:
382-
"""
383-
{
384-
"@context": "/contexts/RelationEmbedder",
385-
"@id": "/relation_embedders/3",
386-
"@type": "RelationEmbedder",
387-
"krondstadt": "Krondstadt",
388-
"anotherRelated": {
389-
"@id": "/related_dummies/4",
390-
"@type": "https://schema.org/Product",
391-
"symfony": "laravel",
392-
"thirdLevel": null
393-
},
394-
"related": null
395-
}
396-
"""
397-
398-
Scenario: Update the relation with a new one (json)
399-
When I add "Content-Type" header equal to "application/json"
400-
And I send a "PUT" request to "/relation_embedders/3" with body:
401-
"""
402-
{
403-
"anotherRelated": {
404-
"symfony": "laravel2"
405-
}
406-
}
407-
"""
408-
Then the response status code should be 200
409-
And the response should be in JSON
410-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
411-
And the JSON should be equal to:
412-
"""
413-
{
414-
"@context": "/contexts/RelationEmbedder",
415-
"@id": "/relation_embedders/3",
416-
"@type": "RelationEmbedder",
417-
"krondstadt": "Krondstadt",
418-
"anotherRelated": {
419-
"@id": "/related_dummies/5",
420-
"@type": "https://schema.org/Product",
421-
"symfony": "laravel2",
422-
"thirdLevel": null
423-
},
424-
"related": null
425-
}
426-
"""
427-
428368
Scenario: Update an embedded relation
429369
When I add "Content-Type" header equal to "application/ld+json"
430370
And I send a "PUT" request to "/relation_embedders/2" with body:
@@ -456,37 +396,6 @@ Feature: Relations support
456396
}
457397
"""
458398

459-
Scenario: Create a related dummy with a relation (json)
460-
When I add "Content-Type" header equal to "application/json"
461-
And I send a "POST" request to "/related_dummies" with body:
462-
"""
463-
{"thirdLevel": "1"}
464-
"""
465-
Then the response status code should be 201
466-
And the response should be in JSON
467-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
468-
And the JSON should be equal to:
469-
"""
470-
{
471-
"@context": "/contexts/RelatedDummy",
472-
"@id": "/related_dummies/6",
473-
"@type": "https://schema.org/Product",
474-
"id": 6,
475-
"name": null,
476-
"symfony": "symfony",
477-
"dummyDate": null,
478-
"thirdLevel": {
479-
"@id": "/third_levels/1",
480-
"@type": "ThirdLevel",
481-
"fourthLevel": null
482-
},
483-
"relatedToDummyFriend": [],
484-
"dummyBoolean": null,
485-
"embeddedDummy": [],
486-
"age": null
487-
}
488-
"""
489-
490399
Scenario: Issue #1222
491400
Given there are people having pets
492401
When I add "Content-Type" header equal to "application/ld+json"
@@ -519,45 +428,6 @@ Feature: Relations support
519428
}
520429
"""
521430

522-
Scenario: Passing a (valid) plain identifier on a relation
523-
When I add "Content-Type" header equal to "application/json"
524-
And I send a "POST" request to "/dummies" with body:
525-
"""
526-
{
527-
"relatedDummy": "1",
528-
"relatedDummies": ["1"],
529-
"name": "Dummy with plain relations"
530-
}
531-
"""
532-
Then the response status code should be 201
533-
And the response should be in JSON
534-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
535-
And the JSON should be equal to:
536-
"""
537-
{
538-
"@context":"/contexts/Dummy",
539-
"@id":"/dummies/2",
540-
"@type":"Dummy",
541-
"description":null,
542-
"dummy":null,
543-
"dummyBoolean":null,
544-
"dummyDate":null,
545-
"dummyFloat":null,
546-
"dummyPrice":null,
547-
"relatedDummy":"/related_dummies/1",
548-
"relatedDummies":["/related_dummies/1"],
549-
"jsonData":[],
550-
"arrayData":[],
551-
"name_converted":null,
552-
"relatedOwnedDummy": null,
553-
"relatedOwningDummy": null,
554-
"id":2,
555-
"name":"Dummy with plain relations",
556-
"alias":null,
557-
"foo":null
558-
}
559-
"""
560-
561431
Scenario: Eager load relations should not be duplicated
562432
Given there is an order with same customer and recipient
563433
When I add "Content-Type" header equal to "application/ld+json"

src/Bridge/Symfony/Bundle/Resources/config/metadata/xml.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</service>
2727

2828
<service id="api_platform.metadata.property.metadata_factory" alias="api_platform.metadata.property.metadata_factory.xml" />
29-
<service id="api_platform.metadata.property.metadata_factory.xml" class="ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory" decoration-priority="20" public="false">
29+
<service id="api_platform.metadata.property.metadata_factory.xml" class="ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory" public="false">
3030
<argument type="service" id="api_platform.metadata.extractor.xml" />
3131
</service>
3232
</services>

0 commit comments

Comments
 (0)