File tree Expand file tree Collapse file tree
Http/Controllers/Apis/Protected/Summit/Factories
database/migrations/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public static function buildForAdd(array $payload = []): array
3030 public static function buildForUpdate (array $ payload = []): array
3131 {
3232 return [
33- 'name ' => 'sometimes|string|max:255 ' ,
33+ 'name ' => 'sometimes|required| string|max:255 ' ,
3434 ];
3535 }
3636}
Original file line number Diff line number Diff line change 2323final class SummitSponsorshipAddOnSerializer extends SilverStripeSerializer
2424{
2525 protected static $ array_mappings = [
26- 'Name ' => 'name:json_string ' ,
27- 'TypeId ' => 'type_id:json_int ' ,
26+ 'Name ' => 'name:json_string ' ,
27+ 'TypeId ' => 'type_id:json_int ' ,
28+ 'TypeName ' => 'type_name:json_string ' ,
2829 'SponsorshipId ' => 'sponsorship_id:json_int ' ,
2930 ];
3031
Original file line number Diff line number Diff line change @@ -72,6 +72,11 @@ public function getType(): ?SummitSponsorshipAddOnType
7272 return $ this ->type ;
7373 }
7474
75+ public function getTypeName (): ?string
76+ {
77+ return $ this ->type ?->getName();
78+ }
79+
7580 public function setType (SummitSponsorshipAddOnType $ type ): void
7681 {
7782 $ this ->type = $ type ;
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ protected function getOrderMappings(): array
6767 return [
6868 'id ' => 'e.id ' ,
6969 'name ' => 'e.name ' ,
70+ 'type ' => 'at.name ' ,
7071 ];
7172 }
7273
@@ -98,4 +99,4 @@ public function countByAddOnType(int $type_id): int
9899 ->setParameter ('type_id ' , $ type_id )
99100 ->getSingleScalarResult ();
100101 }
101- }
102+ }
Original file line number Diff line number Diff line change @@ -52,8 +52,9 @@ public function up(Schema $schema): void
5252 }
5353
5454 // Seed the four types that correspond to the old string constants.
55+ // INSERT IGNORE makes this safe to re-run (unique constraint on Name).
5556 $ this ->addSql (<<<SQL
56- INSERT INTO `SummitSponsorshipAddOnType` (`Created`, `LastEdited`, `Name`) VALUES
57+ INSERT IGNORE INTO `SummitSponsorshipAddOnType` (`Created`, `LastEdited`, `Name`) VALUES
5758 (NOW(), NOW(), 'Booth'),
5859 (NOW(), NOW(), 'Meeting_Room'),
5960 (NOW(), NOW(), 'Schedule_Spot'),
Original file line number Diff line number Diff line change @@ -227,6 +227,24 @@ public function testUpdate(): void
227227 $ this ->assertEquals ($ new_name , $ type ->name );
228228 }
229229
230+ public function testUpdateWithEmptyName (): void
231+ {
232+ $ params = ['id ' => self ::$ default_type ->getId ()];
233+
234+ $ this ->action (
235+ "PUT " ,
236+ "OAuth2SummitSponsorshipAddOnTypesApiController@update " ,
237+ $ params ,
238+ [],
239+ [],
240+ [],
241+ $ this ->getAuthHeaders (),
242+ json_encode (['name ' => '' ])
243+ );
244+
245+ $ this ->assertResponseStatus (412 );
246+ }
247+
230248 public function testUpdateNotFound (): void
231249 {
232250 $ params = ['id ' => PHP_INT_MAX ];
You can’t perform that action at this time.
0 commit comments