Skip to content

Add test for updating embedded relation using plain identifier #3145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions features/json/relation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
Feature: JSON relations support
In order to use a hypermedia API
As a client software developer
I need to be able to update relations between resources

@createSchema
Scenario: Create a third level
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/third_levels" with body:
"""
{
"level": 3
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/ThirdLevel",
"@id": "/third_levels/1",
"@type": "ThirdLevel",
"fourthLevel": null,
"badFourthLevel": null,
"id": 1,
"level": 3,
"test": true
}
"""

Scenario: Create a new relation
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/relation_embedders" with body:
"""
{
"anotherRelated": {
"symfony": "laravel"
}
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelationEmbedder",
"@id": "/relation_embedders/1",
"@type": "RelationEmbedder",
"krondstadt": "Krondstadt",
"anotherRelated": {
"@id": "/related_dummies/1",
"@type": "https://schema.org/Product",
"symfony": "laravel",
"thirdLevel": null
},
"related": null
}
"""

Scenario: Update the relation with a new one
When I add "Content-Type" header equal to "application/json"
And I send a "PUT" request to "/relation_embedders/1" with body:
"""
{
"anotherRelated": {
"symfony": "laravel2"
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelationEmbedder",
"@id": "/relation_embedders/1",
"@type": "RelationEmbedder",
"krondstadt": "Krondstadt",
"anotherRelated": {
"@id": "/related_dummies/2",
"@type": "https://schema.org/Product",
"symfony": "laravel2",
"thirdLevel": null
},
"related": null
}
"""

Scenario: Update an embedded relation using an IRI
When I add "Content-Type" header equal to "application/json"
And I send a "PUT" request to "/relation_embedders/1" with body:
"""
{
"anotherRelated": {
"id": "/related_dummies/1",
"symfony": "API Platform"
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelationEmbedder",
"@id": "/relation_embedders/1",
"@type": "RelationEmbedder",
"krondstadt": "Krondstadt",
"anotherRelated": {
"@id": "/related_dummies/1",
"@type": "https://schema.org/Product",
"symfony": "API Platform",
"thirdLevel": null
},
"related": null
}
"""

Scenario: Update an embedded relation using plain identifiers
When I add "Content-Type" header equal to "application/json"
And I send a "PUT" request to "/relation_embedders/1" with body:
"""
{
"anotherRelated": {
"id": 1,
"symfony": "API Platform 2"
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelationEmbedder",
"@id": "/relation_embedders/1",
"@type": "RelationEmbedder",
"krondstadt": "Krondstadt",
"anotherRelated": {
"@id": "/related_dummies/1",
"@type": "https://schema.org/Product",
"symfony": "API Platform 2",
"thirdLevel": null
},
"related": null
}
"""

Scenario: Create a related dummy with a relation
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/related_dummies" with body:
"""
{
"thirdLevel": "1"
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelatedDummy",
"@id": "/related_dummies/3",
"@type": "https://schema.org/Product",
"id": 3,
"name": null,
"symfony": "symfony",
"dummyDate": null,
"thirdLevel": {
"@id": "/third_levels/1",
"@type": "ThirdLevel",
"fourthLevel": null
},
"relatedToDummyFriend": [],
"dummyBoolean": null,
"embeddedDummy": [],
"age": null
}
"""

Scenario: Passing a (valid) plain identifier on a relation
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/dummies" with body:
"""
{
"relatedDummy": "1",
"relatedDummies": [
"1"
],
"name": "Dummy with plain relations"
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/Dummy",
"@id": "/dummies/1",
"@type": "Dummy",
"description": null,
"dummy": null,
"dummyBoolean": null,
"dummyDate": null,
"dummyFloat": null,
"dummyPrice": null,
"relatedDummy": "/related_dummies/1",
"relatedDummies": [
"/related_dummies/1"
],
"jsonData": [],
"arrayData": [],
"name_converted": null,
"relatedOwnedDummy": null,
"relatedOwningDummy": null,
"id": 1,
"name": "Dummy with plain relations",
"alias": null,
"foo": null
}
"""
130 changes: 0 additions & 130 deletions features/main/relation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -365,66 +365,6 @@ Feature: Relations support
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"

Scenario: Create a new relation (json)
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/relation_embedders" with body:
"""
{
"anotherRelated": {
"symfony": "laravel"
}
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelationEmbedder",
"@id": "/relation_embedders/3",
"@type": "RelationEmbedder",
"krondstadt": "Krondstadt",
"anotherRelated": {
"@id": "/related_dummies/4",
"@type": "https://schema.org/Product",
"symfony": "laravel",
"thirdLevel": null
},
"related": null
}
"""

Scenario: Update the relation with a new one (json)
When I add "Content-Type" header equal to "application/json"
And I send a "PUT" request to "/relation_embedders/3" with body:
"""
{
"anotherRelated": {
"symfony": "laravel2"
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelationEmbedder",
"@id": "/relation_embedders/3",
"@type": "RelationEmbedder",
"krondstadt": "Krondstadt",
"anotherRelated": {
"@id": "/related_dummies/5",
"@type": "https://schema.org/Product",
"symfony": "laravel2",
"thirdLevel": null
},
"related": null
}
"""

Scenario: Update an embedded relation
When I add "Content-Type" header equal to "application/ld+json"
And I send a "PUT" request to "/relation_embedders/2" with body:
Expand Down Expand Up @@ -456,37 +396,6 @@ Feature: Relations support
}
"""

Scenario: Create a related dummy with a relation (json)
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/related_dummies" with body:
"""
{"thirdLevel": "1"}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context": "/contexts/RelatedDummy",
"@id": "/related_dummies/6",
"@type": "https://schema.org/Product",
"id": 6,
"name": null,
"symfony": "symfony",
"dummyDate": null,
"thirdLevel": {
"@id": "/third_levels/1",
"@type": "ThirdLevel",
"fourthLevel": null
},
"relatedToDummyFriend": [],
"dummyBoolean": null,
"embeddedDummy": [],
"age": null
}
"""

Scenario: Issue #1222
Given there are people having pets
When I add "Content-Type" header equal to "application/ld+json"
Expand Down Expand Up @@ -519,45 +428,6 @@ Feature: Relations support
}
"""

Scenario: Passing a (valid) plain identifier on a relation
When I add "Content-Type" header equal to "application/json"
And I send a "POST" request to "/dummies" with body:
"""
{
"relatedDummy": "1",
"relatedDummies": ["1"],
"name": "Dummy with plain relations"
}
"""
Then the response status code should be 201
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON should be equal to:
"""
{
"@context":"/contexts/Dummy",
"@id":"/dummies/2",
"@type":"Dummy",
"description":null,
"dummy":null,
"dummyBoolean":null,
"dummyDate":null,
"dummyFloat":null,
"dummyPrice":null,
"relatedDummy":"/related_dummies/1",
"relatedDummies":["/related_dummies/1"],
"jsonData":[],
"arrayData":[],
"name_converted":null,
"relatedOwnedDummy": null,
"relatedOwningDummy": null,
"id":2,
"name":"Dummy with plain relations",
"alias":null,
"foo":null
}
"""

Scenario: Eager load relations should not be duplicated
Given there is an order with same customer and recipient
When I add "Content-Type" header equal to "application/ld+json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</service>

<service id="api_platform.metadata.property.metadata_factory" alias="api_platform.metadata.property.metadata_factory.xml" />
<service id="api_platform.metadata.property.metadata_factory.xml" class="ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory" decoration-priority="20" public="false">
<service id="api_platform.metadata.property.metadata_factory.xml" class="ApiPlatform\Core\Metadata\Property\Factory\ExtractorPropertyMetadataFactory" public="false">
<argument type="service" id="api_platform.metadata.extractor.xml" />
</service>
</services>
Expand Down
Loading