|
| 1 | +@!mongodb |
| 2 | +Feature: DTO input and output |
| 3 | + In order to use an hypermedia API |
| 4 | + As a client software developer |
| 5 | + I need to be able to use DTOs on my resources as Input or Output objects. |
| 6 | + |
| 7 | + @createSchema |
| 8 | + Scenario: Create a resource with a custom Input. |
| 9 | + When I add "Content-Type" header equal to "application/ld+json" |
| 10 | + And I send a "POST" request to "/dummy_dto_customs" with body: |
| 11 | + """ |
| 12 | + { |
| 13 | + "foo": "test", |
| 14 | + "bar": 1 |
| 15 | + } |
| 16 | + """ |
| 17 | + Then the response status code should be 201 |
| 18 | + And the response should be in JSON |
| 19 | + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
| 20 | + And the JSON should be equal to: |
| 21 | + """ |
| 22 | + { |
| 23 | + "@context": "/contexts/DummyDtoCustom", |
| 24 | + "@id": "/dummy_dto_customs/1", |
| 25 | + "@type": "DummyDtoCustom", |
| 26 | + "lorem": "test", |
| 27 | + "ipsum": "1", |
| 28 | + "id": 1 |
| 29 | + } |
| 30 | + """ |
| 31 | + |
| 32 | + @createSchema |
| 33 | + Scenario: Get an item with a custom output |
| 34 | + Given there is a DummyCustomDto |
| 35 | + When I send a "GET" request to "/dummy_dto_custom_output/1" |
| 36 | + Then the response status code should be 200 |
| 37 | + And the response should be in JSON |
| 38 | + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
| 39 | + And the JSON should be a superset of: |
| 40 | + """ |
| 41 | + { |
| 42 | + "@context": { |
| 43 | + "@vocab": "http://example.com/docs.jsonld#", |
| 44 | + "hydra": "http://www.w3.org/ns/hydra/core#", |
| 45 | + "foo": { |
| 46 | + "@type": "@id" |
| 47 | + }, |
| 48 | + "bar": { |
| 49 | + "@type": "@id" |
| 50 | + } |
| 51 | + }, |
| 52 | + "@type": "CustomOutputDto", |
| 53 | + "foo": "test", |
| 54 | + "bar": 0 |
| 55 | + } |
| 56 | + """ |
| 57 | + |
| 58 | + @createSchema |
| 59 | + Scenario: Get a collection with a custom output |
| 60 | + Given there are 2 DummyCustomDto |
| 61 | + When I send a "GET" request to "/dummy_dto_custom_output" |
| 62 | + Then the response status code should be 200 |
| 63 | + And the response should be in JSON |
| 64 | + And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
| 65 | + And the JSON should be a superset of: |
| 66 | + """ |
| 67 | + { |
| 68 | + "@context": "/contexts/DummyDtoCustom", |
| 69 | + "@id": "/dummy_dto_customs", |
| 70 | + "@type": "hydra:Collection", |
| 71 | + "hydra:member": [ |
| 72 | + { |
| 73 | + "foo": "test", |
| 74 | + "bar": 1 |
| 75 | + }, |
| 76 | + { |
| 77 | + "foo": "test", |
| 78 | + "bar": 2 |
| 79 | + } |
| 80 | + ], |
| 81 | + "hydra:totalItems": 2 |
| 82 | + } |
| 83 | + """ |
| 84 | + |
| 85 | + @createSchema |
| 86 | + Scenario: Create a DummyCustomDto object without output |
| 87 | + When I add "Content-Type" header equal to "application/ld+json" |
| 88 | + And I send a "POST" request to "/dummy_dto_custom_post_without_output" with body: |
| 89 | + """ |
| 90 | + { |
| 91 | + "lorem": "test", |
| 92 | + "ipsum": "1" |
| 93 | + } |
| 94 | + """ |
| 95 | + Then the response status code should be 201 |
| 96 | + And the response should be empty |
| 97 | + |
| 98 | + @createSchema |
| 99 | + Scenario: Create and update a DummyInputOutput |
| 100 | + When I add "Content-Type" header equal to "application/ld+json" |
| 101 | + And I send a "POST" request to "/dummy_dto_input_outputs" with body: |
| 102 | + """ |
| 103 | + { |
| 104 | + "foo": "test", |
| 105 | + "bar": 1 |
| 106 | + } |
| 107 | + """ |
| 108 | + Then the response status code should be 201 |
| 109 | + And the JSON should be a superset of: |
| 110 | + """ |
| 111 | + { |
| 112 | + "@context": { |
| 113 | + "@vocab": "http://example.com/docs.jsonld#", |
| 114 | + "hydra": "http://www.w3.org/ns/hydra/core#", |
| 115 | + "baz": { |
| 116 | + "@type": "@id" |
| 117 | + }, |
| 118 | + "bat": { |
| 119 | + "@type": "@id" |
| 120 | + } |
| 121 | + }, |
| 122 | + "@type": "OutputDto", |
| 123 | + "baz": 1, |
| 124 | + "bat": "test" |
| 125 | + } |
| 126 | + """ |
| 127 | + Then I add "Content-Type" header equal to "application/ld+json" |
| 128 | + And I send a "PUT" request to "/dummy_dto_input_outputs/1" with body: |
| 129 | + """ |
| 130 | + { |
| 131 | + "foo": "test", |
| 132 | + "bar": 2 |
| 133 | + } |
| 134 | + """ |
| 135 | + Then the response status code should be 200 |
| 136 | + And the JSON should be a superset of: |
| 137 | + """ |
| 138 | + { |
| 139 | + "@context": { |
| 140 | + "@vocab": "http:\/\/example.com\/docs.jsonld#", |
| 141 | + "hydra": "http:\/\/www.w3.org\/ns\/hydra\/core#", |
| 142 | + "baz": { |
| 143 | + "@type": "@id" |
| 144 | + }, |
| 145 | + "bat": { |
| 146 | + "@type": "@id" |
| 147 | + } |
| 148 | + }, |
| 149 | + "@type": "OutputDto", |
| 150 | + "baz": 2, |
| 151 | + "bat": "test" |
| 152 | + } |
| 153 | + """ |
| 154 | + |
| 155 | + @createSchema |
| 156 | + Scenario: Use DTO with relations on User |
| 157 | + When I add "Content-Type" header equal to "application/ld+json" |
| 158 | + And I send a "POST" request to "/users" with body: |
| 159 | + """ |
| 160 | + { |
| 161 | + "username": "soyuka", |
| 162 | + "plainPassword": "a real password", |
| 163 | + |
| 164 | + } |
| 165 | + """ |
| 166 | + Then the response status code should be 201 |
| 167 | + Then I add "Content-Type" header equal to "application/ld+json" |
| 168 | + And I send a "PUT" request to "/users/recover/1" with body: |
| 169 | + """ |
| 170 | + { |
| 171 | + "user": "/users/1" |
| 172 | + } |
| 173 | + """ |
| 174 | + Then the response status code should be 200 |
| 175 | + And the JSON should be a superset of: |
| 176 | + """ |
| 177 | + { |
| 178 | + "@context": { |
| 179 | + "@vocab": "http://example.com/docs.jsonld#", |
| 180 | + "hydra": "http://www.w3.org/ns/hydra/core#", |
| 181 | + "user": { |
| 182 | + "@type": "@id" |
| 183 | + } |
| 184 | + }, |
| 185 | + "@type": "RecoverPasswordOutput", |
| 186 | + "user": { |
| 187 | + "@id": "/users/1", |
| 188 | + "@type": "User", |
| 189 | + |
| 190 | + "fullname": null, |
| 191 | + "username": "soyuka" |
| 192 | + } |
| 193 | + } |
| 194 | + """ |
| 195 | + |
| 196 | +# @createSchema |
| 197 | +# Scenario: Execute a GraphQL query on DTO |
| 198 | +# Given there are 2 DummyCustomDto |
| 199 | +# When I send the following GraphQL request: |
| 200 | +# """ |
| 201 | +# { |
| 202 | +# dummyDtoCustom(id: "/dummy_dto_customs/1") { |
| 203 | +# lorem |
| 204 | +# ipsum |
| 205 | +# } |
| 206 | +# } |
| 207 | +# """ |
| 208 | +# Then the response status code should be 200 |
| 209 | +# And the response should be in JSON |
| 210 | +# And the header "Content-Type" should be equal to "application/json" |
| 211 | +# Then print last JSON response |
| 212 | +# And the JSON node "data.dummy.id" should be equal to "/dummies/1" |
| 213 | +# And the JSON node "data.dummy.name" should be equal to "Dummy #1" |
0 commit comments