|
20 | 20 | use Tempest\Http\Status; |
21 | 21 | use Tempest\Idempotency\Attributes\Idempotent; |
22 | 22 | use Tempest\Idempotency\Config\IdempotencyConfig; |
| 23 | +use Tempest\Idempotency\Exceptions\UnsupportedIdempotencyMethod; |
23 | 24 | use Tempest\Idempotency\Fingerprint\RequestFingerprintGenerator; |
24 | 25 | use Tempest\Idempotency\Middleware\IdempotencyMiddleware; |
25 | 26 | use Tempest\Idempotency\Store\CacheIdempotencyStore; |
@@ -129,7 +130,7 @@ public function rejects_the_same_key_when_the_payload_changes(): void |
129 | 130 | $next, |
130 | 131 | ); |
131 | 132 |
|
132 | | - $this->assertSame(Status::CONFLICT, $secondResponse->status); |
| 133 | + $this->assertSame(Status::UNPROCESSABLE_CONTENT, $secondResponse->status); |
133 | 134 | $this->assertSame(1, $calls); |
134 | 135 | } |
135 | 136 |
|
@@ -241,6 +242,69 @@ public function idempotent_decorator_does_not_add_duplicate_middleware_entries() |
241 | 242 | ); |
242 | 243 | } |
243 | 244 |
|
| 245 | + #[Test] |
| 246 | + public function idempotent_decorator_adds_middleware_for_patch_routes(): void |
| 247 | + { |
| 248 | + $route = new FakeRoute(); |
| 249 | + $route->method = Method::PATCH; |
| 250 | + $attribute = new Idempotent(); |
| 251 | + |
| 252 | + $attribute->decorate($route); |
| 253 | + |
| 254 | + $this->assertContains(IdempotencyMiddleware::class, $route->middleware); |
| 255 | + } |
| 256 | + |
| 257 | + #[Test] |
| 258 | + public function idempotent_decorator_throws_for_get_routes(): void |
| 259 | + { |
| 260 | + $route = new FakeRoute(); |
| 261 | + $route->method = Method::GET; |
| 262 | + |
| 263 | + $this->expectException(UnsupportedIdempotencyMethod::class); |
| 264 | + |
| 265 | + new Idempotent()->decorate($route); |
| 266 | + } |
| 267 | + |
| 268 | + #[Test] |
| 269 | + public function idempotent_decorator_throws_for_put_routes(): void |
| 270 | + { |
| 271 | + $route = new FakeRoute(); |
| 272 | + $route->method = Method::PUT; |
| 273 | + |
| 274 | + $this->expectException(UnsupportedIdempotencyMethod::class); |
| 275 | + |
| 276 | + new Idempotent()->decorate($route); |
| 277 | + } |
| 278 | + |
| 279 | + #[Test] |
| 280 | + public function idempotent_decorator_throws_for_delete_routes(): void |
| 281 | + { |
| 282 | + $route = new FakeRoute(); |
| 283 | + $route->method = Method::DELETE; |
| 284 | + |
| 285 | + $this->expectException(UnsupportedIdempotencyMethod::class); |
| 286 | + |
| 287 | + new Idempotent()->decorate($route); |
| 288 | + } |
| 289 | + |
| 290 | + #[Test] |
| 291 | + public function throws_for_non_post_and_patch_methods(): void |
| 292 | + { |
| 293 | + $middleware = $this->createMiddleware('create'); |
| 294 | + |
| 295 | + $this->expectException(UnsupportedIdempotencyMethod::class); |
| 296 | + |
| 297 | + $middleware( |
| 298 | + new GenericRequest( |
| 299 | + Method::PUT, |
| 300 | + '/orders', |
| 301 | + body: ['amount' => 100], |
| 302 | + headers: ['Idempotency-Key' => 'order-100'], |
| 303 | + ), |
| 304 | + new HttpMiddlewareCallable(static fn (Request $_): Response => new GenericResponse(Status::OK, ['ok' => true])), |
| 305 | + ); |
| 306 | + } |
| 307 | + |
244 | 308 | #[Test] |
245 | 309 | public function uses_pending_ttl_for_lock_and_completion_ttl_for_pending_record(): void |
246 | 310 | { |
|
0 commit comments