|
213 | 213 | ->assertJsonPath('data.attributes.order_type', Location::COLLECTION); |
214 | 214 | }); |
215 | 215 |
|
| 216 | +it('updates order status', function(): void { |
| 217 | + Sanctum::actingAs(User::factory()->create(), ['orders:*']); |
| 218 | + $order = Order::factory()->create(); |
| 219 | + $newStatus = Status::isForOrder()->first(); |
| 220 | + |
| 221 | + $this |
| 222 | + ->patch(route('igniter.api.orders.update_status', [$order->getKey()]), [ |
| 223 | + 'status_id' => $newStatus->getKey(), |
| 224 | + ]) |
| 225 | + ->assertOk() |
| 226 | + ->assertJsonPath('data.id', (string)$order->getKey()) |
| 227 | + ->assertJsonPath('data.attributes.status_id', $newStatus->getKey()); |
| 228 | +}); |
| 229 | + |
| 230 | +it('updates order status with comment', function(): void { |
| 231 | + Sanctum::actingAs(User::factory()->create(), ['orders:*']); |
| 232 | + $order = Order::factory()->create(); |
| 233 | + $newStatus = Status::isForOrder()->first(); |
| 234 | + |
| 235 | + $this |
| 236 | + ->patch(route('igniter.api.orders.update_status', [$order->getKey()]), [ |
| 237 | + 'status_id' => $newStatus->getKey(), |
| 238 | + 'status_comment' => 'Ready for collection', |
| 239 | + ]) |
| 240 | + ->assertOk() |
| 241 | + ->assertJsonPath('data.attributes.status_id', $newStatus->getKey()); |
| 242 | +}); |
| 243 | + |
| 244 | +it('fails to update order status when status_id is missing', function(): void { |
| 245 | + Sanctum::actingAs(User::factory()->create(), ['orders:*']); |
| 246 | + $order = Order::factory()->create(); |
| 247 | + |
| 248 | + $this |
| 249 | + ->patch(route('igniter.api.orders.update_status', [$order->getKey()]), [ |
| 250 | + 'status_comment' => 'Comment only', |
| 251 | + ]) |
| 252 | + ->assertStatus(422); |
| 253 | +}); |
| 254 | + |
| 255 | +it('can not update order status as customer', function(): void { |
| 256 | + $customer = Sanctum::actingAs(Customer::factory()->create(), ['orders:*']); |
| 257 | + $customer->currentAccessToken()->shouldReceive('isForCustomer')->andReturnTrue(); |
| 258 | + $order = Order::factory()->create(); |
| 259 | + $newStatus = Status::isForOrder()->first(); |
| 260 | + |
| 261 | + $this |
| 262 | + ->patch(route('igniter.api.orders.update_status', [$order->getKey()]), [ |
| 263 | + 'status_id' => $newStatus->getKey(), |
| 264 | + ]) |
| 265 | + ->assertStatus(403); |
| 266 | +}); |
| 267 | + |
216 | 268 | it('deletes an order', function(): void { |
217 | 269 | Sanctum::actingAs(User::factory()->create(), ['orders:*']); |
218 | 270 | $order = Order::factory()->create(); |
|
0 commit comments