feat: Add a person as an offer field type - #5
Conversation
A provider can declare a field of type user, and the console searches its own directory for an address while still taking one typed in full.
Code Review Summary✨ Adds a new 💡 Minor Suggestions
|
| type: 'user', | ||
| ); | ||
|
|
||
| $this->assertSame('user', $field->toArray()['type']); |
There was a problem hiding this comment.
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.
| $this->assertSame('user', $field->toArray()['type']); | |
| $this->assertSame([ | |
| 'name' => 'for_email', | |
| 'label' => 'Only for', | |
| 'type' => 'user', | |
| 'required' => false, | |
| 'help' => null, | |
| 'options' => [], | |
| ], $field->toArray()); |
| ]; | ||
| } | ||
|
|
||
| public function test_a_field_may_ask_for_a_person(): void |
There was a problem hiding this comment.
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.
| 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()); | |
| } |
A provider can declare a field of type user, and the console searches its own directory for an address while still taking one typed in full.