|
15 | 15 | }); |
16 | 16 |
|
17 | 17 | describe('StateCollectionResource', function () { |
| 18 | + /** |
| 19 | + * Scenario: Generate collection resource for all states of a model |
| 20 | + * Setup: Use Post model class with configured states |
| 21 | + * Assertions: Returns non-empty array of state resources |
| 22 | + */ |
18 | 23 | it('creates collection for model class', function () { |
19 | 24 | $request = Request::create('/'); |
20 | 25 | $resource = StateCollectionResource::forModel(Post::class); |
|
25 | 30 | expect($array)->not->toBeEmpty(); |
26 | 31 | }); |
27 | 32 |
|
| 33 | + /** |
| 34 | + * Scenario: Non-stateful models return empty collection |
| 35 | + * Setup: Use User model which doesn't have state management |
| 36 | + * Assertions: Returns empty array |
| 37 | + */ |
28 | 38 | it('creates empty collection for non-stateable model', function () { |
29 | 39 | $request = Request::create('/'); |
30 | 40 | $resource = StateCollectionResource::forModel(User::class); |
|
35 | 45 | expect($array)->toBeEmpty(); |
36 | 46 | }); |
37 | 47 |
|
| 48 | + /** |
| 49 | + * Scenario: Generate collection of available next states for a model instance |
| 50 | + * Setup: Create draft post with configured transitions |
| 51 | + * Assertions: Returns array with at least one next state |
| 52 | + */ |
38 | 53 | it('creates collection for next states', function () { |
39 | 54 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
40 | 55 | $request = Request::create('/'); |
|
46 | 61 | expect(count($array))->toBeGreaterThan(0); |
47 | 62 | }); |
48 | 63 |
|
| 64 | + /** |
| 65 | + * Scenario: Filter next states based on user permissions |
| 66 | + * Setup: Create admin user and draft post |
| 67 | + * Assertions: Collection respects user's permission context |
| 68 | + */ |
49 | 69 | it('creates collection with user context', function () { |
50 | 70 | $user = new User(['id' => 1, 'role' => 'admin']); |
51 | 71 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
|
57 | 77 | expect($array)->toBeArray(); |
58 | 78 | }); |
59 | 79 |
|
| 80 | + /** |
| 81 | + * Scenario: Return only essential state data to reduce API payload size |
| 82 | + * Setup: Create draft post, request next states in minimal format |
| 83 | + * Assertions: Array items contain only name and title, no color or metadata |
| 84 | + */ |
60 | 85 | it('supports minimal format', function () { |
61 | 86 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
62 | 87 | $request = Request::create('/'); |
|
70 | 95 | } |
71 | 96 | }); |
72 | 97 |
|
| 98 | + /** |
| 99 | + * Scenario: Return UI-optimized state data with visual metadata but without transition flags |
| 100 | + * Setup: Create draft post, request next states in UI format |
| 101 | + * Assertions: Items include name, title, color, icon, description but exclude is_current/can_transition_to |
| 102 | + */ |
73 | 103 | it('supports ui format', function () { |
74 | 104 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
75 | 105 | $request = Request::create('/'); |
|
83 | 113 | } |
84 | 114 | }); |
85 | 115 |
|
| 116 | + /** |
| 117 | + * Scenario: Return complete state data including all metadata and transition capabilities |
| 118 | + * Setup: Create draft post, request next states in full format |
| 119 | + * Assertions: Items contain all fields including is_default, is_current, can_transition_to |
| 120 | + */ |
86 | 121 | it('supports full format', function () { |
87 | 122 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
88 | 123 | $request = Request::create('/'); |
|
102 | 137 | } |
103 | 138 | }); |
104 | 139 |
|
| 140 | + /** |
| 141 | + * Scenario: Provide model context to collection so it can mark the current state correctly |
| 142 | + * Setup: Create post in draft state, build collection with Draft and Review states |
| 143 | + * Assertions: Draft state is marked as is_current=true since post is in draft |
| 144 | + */ |
105 | 145 | it('sets model context with withModel', function () { |
106 | 146 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
107 | 147 | $request = Request::create('/'); |
|
116 | 156 | expect($draftItem['is_current'])->toBeTrue(); |
117 | 157 | }); |
118 | 158 |
|
| 159 | + /** |
| 160 | + * Scenario: Pass user context to enable permission-based filtering of available states |
| 161 | + * Setup: Create admin user and draft post, build Review state collection with user context |
| 162 | + * Assertions: Collection is successfully built with user permission context applied |
| 163 | + */ |
119 | 164 | it('sets user context with withUser', function () { |
120 | 165 | $user = new User(['id' => 1, 'role' => 'admin']); |
121 | 166 | $post = Post::create(['title' => 'Test', 'state' => 'draft']); |
|
130 | 175 | expect($array)->toBeArray(); |
131 | 176 | }); |
132 | 177 |
|
| 178 | + /** |
| 179 | + * Scenario: Get complete list of all possible states for a given model type |
| 180 | + * Setup: Use Post model class which has draft, review, published, rejected states |
| 181 | + * Assertions: Returned array contains all configured state names for Post model |
| 182 | + */ |
133 | 183 | it('returns states for model from all states', function () { |
134 | 184 | $request = Request::create('/'); |
135 | 185 | $resource = StateCollectionResource::forModel(Post::class); |
|
0 commit comments