|
| 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 | + """ |
0 commit comments