fix(api+frontend): ensure storyboard has min. 1 section#2995
Conversation
BacLuc
left a comment
There was a problem hiding this comment.
Creating a new StoryBoard is now not possible.
But you will fix that fast.
|
|
||
| $this->assertCount(1, $response->toArray()['data']['sections']); // populated with 1 default section | ||
| } | ||
|
|
There was a problem hiding this comment.
This test fails now when you don't add the content as default of the field:
public function testCreateStoryboardAcceptsNotExistingJson() {
$response = $this->create($this->getExampleWritePayload([], ['data']));
$this->assertResponseStatusCodeSame(201);
$this->assertCount(1, $response->toArray()['data']['sections']); // populated with 1 default section
}
Maybe set the value in the constructor of StoryBoard?
There was a problem hiding this comment.
Ah good catch. Constructor doesn't work (tried before), because in the constructor I don't know if the $data property will be populated later. That's why I put the default value into setData. Didn't recognize that setData is not called at all though if the property doesn't even exist in the payload.
Was anyway an odd design decision, so moved the default fallback now back into the data persister where it also should be.
Fixed with 0f70e58
There was a problem hiding this comment.
We have a similar case in the relation Camp -> Periods, where a camp always must have at least one period. How is this problem solved there?
There was a problem hiding this comment.
There we enforce that the create payload contains a Period.
testCreateCampValidatesMissingPeriods
| throw new UnexpectedTypeException($constraint, AssertJsonSchema::class); | ||
| } | ||
|
|
||
| if (null === $value) { |
There was a problem hiding this comment.
Wieso ist $value === null automatisch ok?
There was a problem hiding this comment.
Ist ein Konzept was Symfony bei den eigenen Validators auch so einsetzt: null-Wert wird normalerweise als ok angesehen (bzw. vom Validator nicht überprüft) und man steuert separat via Assert\IsNull oder Assert\NotNull, wenn man null-Wert explizit vermeiden oder erzwingen will.
So is es nun möglich, dass wir null-Werte beim Erstellen erlauben, und in diesem Fall im DataPersister mit einem Default-Wert befüllen.
Based on #2971
Show relevant diff only: https://github.com/ecamp/ecamp3/pull/2995/files/033f8f3a039f8f99a818a9a0d7c6faaeb4aecfcd..8262ae47a82ece54b897914472c8940e7add9d05
Fixes #2969
Fixes #2933
Only 1 section, delete button disabled
More than 1 section, dialog before section is removed