|
2 | 2 |
|
3 | 3 | use Code16\Sharp\Auth\SharpEntityPolicy; |
4 | 4 | use Code16\Sharp\Tests\Fixtures\Entities\PersonEntity; |
| 5 | +use Code16\Sharp\Tests\Fixtures\User; |
5 | 6 | use Code16\Sharp\Tests\Http\Api\Embeds\Fixtures\ApiEmbedsFormControllerTestEmbed; |
6 | 7 | use Illuminate\Support\Str; |
7 | 8 |
|
@@ -191,3 +192,37 @@ public function view($user, $instanceId): bool |
191 | 192 | ) |
192 | 193 | ->assertJsonValidationErrorFor('name'); |
193 | 194 | }); |
| 195 | + |
| 196 | +it('fails if class is not an embed', function () { |
| 197 | + $this->withoutExceptionHandling(); |
| 198 | + |
| 199 | + expect(function () { |
| 200 | + $this |
| 201 | + ->postJson( |
| 202 | + route('code16.sharp.api.embed.instance.form.show', [ |
| 203 | + 'embedKey' => str(User::class)->replace('\\', '.'), |
| 204 | + 'entityKey' => 'person', |
| 205 | + 'instanceId' => 1, |
| 206 | + ]), |
| 207 | + [ |
| 208 | + 'name' => 'aaa', |
| 209 | + ] |
| 210 | + ); |
| 211 | + })->toThrow(Exception::class, sprintf('Embed class %s is not a SharpFormEditorEmbed', User::class)); |
| 212 | + |
| 213 | + expect(function () { |
| 214 | + $this |
| 215 | + ->postJson( |
| 216 | + route('code16.sharp.api.embed.instance.form.update', [ |
| 217 | + 'embedKey' => str(User::class)->replace('\\', '.'), |
| 218 | + 'entityKey' => 'person', |
| 219 | + 'instanceId' => 1, |
| 220 | + ]), |
| 221 | + [ |
| 222 | + 'name' => 'aaa', |
| 223 | + 'bio' => ['text' => 'aaa'], |
| 224 | + ] |
| 225 | + ); |
| 226 | + })->toThrow(Exception::class, sprintf('Embed class %s is not a SharpFormEditorEmbed', User::class)); |
| 227 | + |
| 228 | +}); |
0 commit comments