Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Contracts/OfferField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
final class OfferField
{
/**
* @param 'text'|'number'|'date'|'select'|'boolean' $type
* @param 'text'|'number'|'date'|'select'|'boolean'|'user' $type 'user' is
* an address the console can search its own directory for,
* while still accepting one typed in full.
* @param array<int|string, string> $options For 'select', value => label.
*/
public function __construct(
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/OfferProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Tests\Support\StrictCreateOfferRequest;
use Tests\Support\User;
use Tests\TestCase;
use Whilesmart\Admin\Contracts\OfferField;
use Whilesmart\Admin\Http\Requests\UpdateMailTemplateRequest;
use Whilesmart\Admin\Support\Offer;
use Whilesmart\Admin\Support\OfferRegistry;
Expand Down Expand Up @@ -200,4 +201,15 @@ public static function unknownProvider(): array
'revoking' => ['DELETE', 'api/admin/offers/credits/1'],
];
}

public function test_a_field_may_ask_for_a_person(): void

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new test verifies the contract at the producer boundary only through toArray()['type']. Asserting the full toArray() shape pins the output schema that the consumer (offer/field JSON) depends on, so any future change to the field keys or defaults is caught here rather than silently changing what consumers receive. This keeps the producer contract explicit without introducing a second formatter.

Suggested change
public function test_a_field_may_ask_for_a_person(): void
public function test_a_field_may_ask_for_a_person(): void
{
$field = new OfferField(
name: 'for_email',
label: 'Only for',
type: 'user',
);
$this->assertSame([
'name' => 'for_email',
'label' => 'Only for',
'type' => 'user',
'required' => false,
'help' => null,
'options' => [],
], $field->toArray());
}

{
$field = new OfferField(
name: 'for_email',
label: 'Only for',
type: 'user',
);

$this->assertSame('user', $field->toArray()['type']);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, the assertion only verifies that the constructor echoes back the value it was given, so it would still pass for any string (e.g. a typo like 'usr'). Asserting the complete toArray() payload makes the test a real regression guard for the DTO shape and the newly advertised 'user' type.

Suggested change
$this->assertSame('user', $field->toArray()['type']);
$this->assertSame([
'name' => 'for_email',
'label' => 'Only for',
'type' => 'user',
'required' => false,
'help' => null,
'options' => [],
], $field->toArray());

}
}
Loading