Skip to content

Commit

Permalink
try to fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Nov 7, 2024
1 parent 184a7fd commit 12df9c5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function getQuestion(int $formId, int $questionId): DataResponse {
#[CORS()]
#[NoAdminRequired()]
#[ApiRoute(verb: 'POST', url: '/api/v3/forms/{formId}/questions')]
public function newQuestion(int $formId, string $type, string $text = '', ?int $fromId = null): DataResponse {
public function newQuestion(int $formId, ?string $type = null, string $text = '', ?int $fromId = null): DataResponse {
$form = $this->getFormIfAllowed($formId);
if ($this->formsService->isFormArchived($form)) {
$this->logger->debug('This form is archived and can not be modified');
Expand Down
10 changes: 6 additions & 4 deletions lib/Db/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@

/**
* @psalm-import-type FormsQuestionExtraSettings from ResponseDefinitions
* @psalm-import-type FormsQuestionType from ResponseDefinitions
* @method int getFormId()
* @method void setFormId(integer $value)
* @method int getOrder()
* @method void setOrder(integer $value)
* @psalm-method FormsQuestionType getType()
* @method string getType()
* @psalm-method 'date'|'dropdown'|'file'|'long'|'multiple'|'multiple_unique'|'short'|'time' getType()
* @psalm-method 'date'|'datetime'|'dropdown'|'file'|'long'|'multiple'|'multiple_unique'|'short'|'time' getType()
* @method void setType(string $value)
* @psalm-method void setType('date'|'dropdown'|'file'|'long'|'multiple'|'multiple_unique'|'short'|'time' $value)
* @psalm-method void setType('date'|'datetime'|'dropdown'|'file'|'long'|'multiple'|'multiple_unique'|'short'|'time' $value)
* @method bool getIsRequired()
* @method void setIsRequired(bool $value)
* @method string getText()
Expand Down Expand Up @@ -77,7 +79,7 @@ public function __construct() {
* @return FormsQuestionExtraSettings
*/
public function getExtraSettings(): array {
return json_decode($this->getExtraSettingsJson() ?: '{}', false, 512, JSON_THROW_ON_ERROR);
return json_decode($this->getExtraSettingsJson() ?: '{}', true, 512, JSON_THROW_ON_ERROR);
}

/**
Expand All @@ -99,7 +101,7 @@ public function setExtraSettings(array $extraSettings) {
* id: int,
* formId: int,
* order: int,
* type: "dropdown"|"multiple"|"multiple_unique"|"date"|"time"|"short"|"long"|"file",
* type: FormsQuestionType,
* isRequired: bool,
* text: string,
* name: string,
Expand Down
2 changes: 1 addition & 1 deletion lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* validationType?: ?string
* }
*
* @psalm-type FormsQuestionType = "dropdown"|"multiple"|"multiple_unique"|"date"|"time"|"short"|"long"|"file"
* @psalm-type FormsQuestionType = "dropdown"|"multiple"|"multiple_unique"|"date"|"time"|"short"|"long"|"file"|"datetime"
*
* @psalm-type FormsQuestion = array{
* id: int,
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public function getQuestions(int $formId): array {
}
}

if (empty($question['extraSettings'])) {
$question['extraSettings'] = new \stdClass();
}

$questionList[] = $question;
}
} catch (DoesNotExistException $e) {
Expand Down
8 changes: 3 additions & 5 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@
"time",
"short",
"long",
"file"
"file",
"datetime"
]
},
"Share": {
Expand Down Expand Up @@ -1347,14 +1348,11 @@
}
],
"requestBody": {
"required": true,
"required": false,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"$ref": "#/components/schemas/QuestionType",
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function dataGetForm() {
'order' => 2,
'type' => 'short',
'isRequired' => true,
'extraSettings' => [],
'extraSettings' => new \stdClass,
'text' => 'Question 2',
'description' => '',
'name' => 'city',
Expand Down

0 comments on commit 12df9c5

Please sign in to comment.