|
3 | 3 | use Illuminate\Support\Facades\Route;
|
4 | 4 | use Oddvalue\LaravelDrafts\Http\Middleware\WithDraftsMiddleware;
|
5 | 5 | use Oddvalue\LaravelDrafts\Tests\Post;
|
| 6 | +use function Pest\Laravel\get; |
6 | 7 |
|
7 | 8 | beforeEach(function () {
|
8 |
| - Post::create(['title' => 'Hello World']); |
9 |
| - Post::createDraft(['title' => 'Hello World draft']); |
| 9 | + test()->post = Post::create(['title' => 'Hello World']); |
| 10 | + test()->draftPost = Post::createDraft(['title' => 'Hello World draft']); |
10 | 11 |
|
11 | 12 | Route::middleware(['web'])->group(function () {
|
12 | 13 | Route::get('/default', function () {
|
|
17 | 18 | return Post::all();
|
18 | 19 | })->middleware(WithDraftsMiddleware::class);
|
19 | 20 |
|
20 |
| - Route::withDrafts(fn () => Route::get('/with-drafts-macro', function () { |
21 |
| - return Post::all(); |
22 |
| - })); |
| 21 | + Route::get('/with-drafts-middleware/{post}', function (Post $post) { |
| 22 | + return $post; |
| 23 | + })->middleware(WithDraftsMiddleware::class); |
| 24 | + |
| 25 | + Route::withDrafts(function () { |
| 26 | + Route::get('/with-drafts-macro', function () { |
| 27 | + return Post::all(); |
| 28 | + }); |
| 29 | + Route::get('/with-drafts-macro/{post}', function (Post $post) { |
| 30 | + return $post; |
| 31 | + }); |
| 32 | + }); |
23 | 33 | });
|
24 | 34 | });
|
25 | 35 |
|
26 |
| -it('can use with drsft middleware to include drafts on a route', function () { |
27 |
| - $this->get('/with-drafts-middleware')->assertJsonCount(2); |
| 36 | +it('can use with draft middleware to include drafts on a route', function () { |
| 37 | + get('/with-drafts-middleware')->assertJsonCount(2); |
28 | 38 | });
|
29 | 39 |
|
30 |
| -it('can use with drsft macro to include drafts on a route', function () { |
31 |
| - $this->get('/with-drafts-macro')->assertJsonCount(2); |
| 40 | +it('can use with draft macro to include drafts on a route', function () { |
| 41 | + get('/with-drafts-macro')->assertJsonCount(2); |
32 | 42 | });
|
33 | 43 |
|
34 | 44 | it('doesnt include drafts by default', function () {
|
35 |
| - $this->get('/default')->assertJsonCount(1); |
| 45 | + get('/default')->assertJsonCount(1); |
| 46 | +}); |
| 47 | + |
| 48 | +it('can use with draft middleware to include drafts on a model binding', function () { |
| 49 | + get('/with-drafts-middleware/' . test()->draftPost->id) |
| 50 | + ->assertJsonFragment(['title' => 'Hello World draft']); |
| 51 | +}); |
| 52 | + |
| 53 | +it('can use with draft macro to include drafts on a model binding', function () { |
| 54 | + get('/with-drafts-macro/' . test()->draftPost->id) |
| 55 | + ->assertJsonFragment(['title' => 'Hello World draft']); |
36 | 56 | });
|
0 commit comments