|
| 1 | +Feature: Create-Retrieve-Update-Delete on abstract resource |
| 2 | + In order to use an hypermedia API |
| 3 | + As a client software developer |
| 4 | + I need to be able to retrieve, create, update and delete JSON-LD encoded resources even if they are abstract. |
| 5 | + |
| 6 | + @createSchema |
| 7 | + Scenario: Create an abstract resource |
| 8 | + When I send a "POST" request to "/abstract_dummies" with body: |
| 9 | + """ |
| 10 | + { |
| 11 | + "instance": "Concrete", |
| 12 | + "name": "My Dummy" |
| 13 | + } |
| 14 | + """ |
| 15 | + Then the response status code should be 400 |
| 16 | + And the response should be in JSON |
| 17 | + And the header "Content-Type" should be equal to "application/ld+json" |
| 18 | + And the JSON node "@context" should be equal to "/contexts/Error" |
| 19 | + And the JSON node "@type" should be equal to "Error" |
| 20 | + And the JSON node "hydra:title" should be equal to "An error occurred" |
| 21 | + And the JSON node "hydra:description" should be equal to "Cannot create an instance of Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\AbstractDummy from serialized data because it is an abstract resource" |
| 22 | + And the JSON node "trace" should exist |
| 23 | + |
| 24 | + Scenario: Create a concrete resource |
| 25 | + When I send a "POST" request to "/concrete_dummies" with body: |
| 26 | + """ |
| 27 | + { |
| 28 | + "instance": "Concrete", |
| 29 | + "name": "My Dummy" |
| 30 | + } |
| 31 | + """ |
| 32 | + Then the response status code should be 201 |
| 33 | + And the response should be in JSON |
| 34 | + And the header "Content-Type" should be equal to "application/ld+json" |
| 35 | + And the JSON should be equal to: |
| 36 | + """ |
| 37 | + { |
| 38 | + "@context": "/contexts/ConcreteDummy", |
| 39 | + "@id": "/concrete_dummies/1", |
| 40 | + "@type": "ConcreteDummy", |
| 41 | + "instance": "Concrete", |
| 42 | + "name": "My Dummy" |
| 43 | + } |
| 44 | + """ |
| 45 | + |
| 46 | + Scenario: Get a resource |
| 47 | + When I send a "GET" request to "/abstract_dummies/1" |
| 48 | + Then the response status code should be 200 |
| 49 | + And the response should be in JSON |
| 50 | + And the header "Content-Type" should be equal to "application/ld+json" |
| 51 | + And the JSON should be equal to: |
| 52 | + """ |
| 53 | + { |
| 54 | + "@context": "/contexts/ConcreteDummy", |
| 55 | + "@id": "/concrete_dummies/1", |
| 56 | + "@type": "ConcreteDummy", |
| 57 | + "instance": "Concrete", |
| 58 | + "name": "My Dummy" |
| 59 | + } |
| 60 | + """ |
| 61 | + |
| 62 | + Scenario: Get a collection |
| 63 | + When I send a "GET" request to "/abstract_dummies" |
| 64 | + Then the response status code should be 200 |
| 65 | + And the response should be in JSON |
| 66 | + And the header "Content-Type" should be equal to "application/ld+json" |
| 67 | + And the JSON should be equal to: |
| 68 | + """ |
| 69 | + { |
| 70 | + "@context": "/contexts/AbstractDummy", |
| 71 | + "@id": "/abstract_dummies", |
| 72 | + "@type": "hydra:PagedCollection", |
| 73 | + "hydra:totalItems": 1, |
| 74 | + "hydra:itemsPerPage": 3, |
| 75 | + "hydra:firstPage": "/abstract_dummies", |
| 76 | + "hydra:lastPage": "/abstract_dummies", |
| 77 | + "hydra:member": [ |
| 78 | + { |
| 79 | + "@id":"/concrete_dummies/1", |
| 80 | + "@type":"ConcreteDummy", |
| 81 | + "instance": "Concrete", |
| 82 | + "name": "My Dummy" |
| 83 | + } |
| 84 | + ], |
| 85 | + "hydra:search": { |
| 86 | + "@type": "hydra:IriTemplate", |
| 87 | + "hydra:template": "\/abstract_dummies{?id,name,order[id],order[name]}", |
| 88 | + "hydra:variableRepresentation": "BasicRepresentation", |
| 89 | + "hydra:mapping": [ |
| 90 | + { |
| 91 | + "@type": "IriTemplateMapping", |
| 92 | + "variable": "id", |
| 93 | + "property": "id", |
| 94 | + "required": false |
| 95 | + }, |
| 96 | + { |
| 97 | + "@type": "IriTemplateMapping", |
| 98 | + "variable": "name", |
| 99 | + "property": "name", |
| 100 | + "required": false |
| 101 | + }, |
| 102 | + { |
| 103 | + "@type": "IriTemplateMapping", |
| 104 | + "variable": "order[id]", |
| 105 | + "property": "id", |
| 106 | + "required": false |
| 107 | + }, |
| 108 | + { |
| 109 | + "@type": "IriTemplateMapping", |
| 110 | + "variable": "order[name]", |
| 111 | + "property": "name", |
| 112 | + "required": false |
| 113 | + } |
| 114 | + ] |
| 115 | + } |
| 116 | + } |
| 117 | + """ |
| 118 | + |
| 119 | + Scenario: Update an abstract resource |
| 120 | + When I send a "PUT" request to "/abstract_dummies/1" with body: |
| 121 | + """ |
| 122 | + { |
| 123 | + "@id": "/concrete_dummies/1", |
| 124 | + "instance": "Become real", |
| 125 | + "name": "A nice dummy" |
| 126 | + } |
| 127 | + """ |
| 128 | + Then the response status code should be 400 |
| 129 | + And the response should be in JSON |
| 130 | + And the header "Content-Type" should be equal to "application/ld+json" |
| 131 | + And the JSON node "@context" should be equal to "/contexts/Error" |
| 132 | + And the JSON node "@type" should be equal to "Error" |
| 133 | + And the JSON node "hydra:title" should be equal to "An error occurred" |
| 134 | + And the JSON node "hydra:description" should be equal to "Cannot create an instance of Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\AbstractDummy from serialized data because it is an abstract resource" |
| 135 | + And the JSON node "trace" should exist |
| 136 | + |
| 137 | + Scenario: Update a concrete resource |
| 138 | + When I send a "PUT" request to "/concrete_dummies/1" with body: |
| 139 | + """ |
| 140 | + { |
| 141 | + "@id": "/concrete_dummies/1", |
| 142 | + "instance": "Become real", |
| 143 | + "name": "A nice dummy" |
| 144 | + } |
| 145 | + """ |
| 146 | + Then the response status code should be 200 |
| 147 | + And the response should be in JSON |
| 148 | + And the header "Content-Type" should be equal to "application/ld+json" |
| 149 | + And the JSON should be equal to: |
| 150 | + """ |
| 151 | + { |
| 152 | + "@context": "/contexts/ConcreteDummy", |
| 153 | + "@id": "/concrete_dummies/1", |
| 154 | + "@type": "ConcreteDummy", |
| 155 | + "instance": "Become real", |
| 156 | + "name": "A nice dummy" |
| 157 | + } |
| 158 | + """ |
| 159 | + |
| 160 | + @dropSchema |
| 161 | + Scenario: Delete a resource |
| 162 | + When I send a "DELETE" request to "/abstract_dummies/1" |
| 163 | + Then the response status code should be 204 |
| 164 | + And the response should be empty |
0 commit comments