Files
openstackid-resources/tests/OAuth2TrackQuestionsTemplateTest.php
Sebastian Marcet 10e1b1c424 Track Extra Questions Endpoints
Get all track questions

GET /api/v1/track-question-templates

params

'page'     => 'integer|min:1'
'per_page' => 'required_with:page|integer|min:5|max:100'

filter

'name'  => ['=@', '==']
'label' => ['=@', '==']
'class_name' => ['==']

order

* id
* name
* label

expand
* tracks

scopes

%s/summits/read/all

Add track question

POST /api/v1/track-question-templates

payload

'name' => 'sometimes|alpha_dash|max:255'
'label' => 'sometimes|string'
'is_mandatory' => 'sometimes|boolean'
'is_read_only' => 'sometimes|boolean'
'tracks' => 'sometimes|int_array'

for
TrackCheckBoxQuestionTemplate and TrackTextBoxQuestionTemplate

'initial_value' => 'string|sometimes'

for
TrackDropDownQuestionTemplate

'is_multiselect' => 'sometimes|boolean'
'is_country_selector' => 'sometimes|boolean'

scopes

%s/summits/write
%s/track-question-templates/write

PUT /api/v1/track-question-templates/{track_question_template_id}

payload same as POST

scopes

%s/summits/write
%s/track-question-templates/write

delete track question

DELETE /api/v1/track-question-templates/{track_question_template_id}

scopes

%s/summits/write
%s/track-question-templates/write

get track question metadata

GET /api/v1/track-question-templates/metadata

scopes

%s/summits/read/all

add track question value

POST /api/v1/track-question-templates/{track_question_template_id}/values

payload

'value' => 'required|string|max:255'
'label' => 'required|string'

scopes

%s/summits/write
%s/track-question-templates/write

update track question value

/api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}

payload

'value' => 'sometimes|string|max:255'
'label' => 'sometimes|string'
'order' => 'sometimes|integer|min:1'

delete track question value

DELETE /api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}

scopes

%s/summits/write
%s/track-question-templates/write

get track question template value

GET /api/v1/track-question-templates/{track_question_template_id}/values/{track_question_template_value_id}

scopes

'%s/summits/read/all'

Change-Id: I663bccf3987cb0b7e337e0fe5b92f3723fac5cd6
2018-09-14 14:50:13 -03:00

331 lines
10 KiB
PHP

<?php
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackRadioButtonListQuestionTemplate;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackDropDownQuestionTemplate;
/**
* Class OAuth2TrackQuestionsTemplateTest
*/
final class OAuth2TrackQuestionsTemplateTest
extends ProtectedApiTest
{
/**
* @param int $summit_id
* @return mixed
*/
public function testGetTrackQuestionTemplateByClassName()
{
$params = [
'expand' => 'tracks',
'filter' => 'class_name==TrackTextBoxQuestionTemplate',
];
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
$response = $this->action(
"GET",
"OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplates",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$track_question_templates = json_decode($content);
$this->assertTrue(!is_null($track_question_templates));
$this->assertResponseStatus(200);
return $track_question_templates;
}
/**
* @param string $class_name
* @return mixed
*/
public function testAddTrackQuestionTemplate(
$class_name = TrackTextBoxQuestionTemplate::ClassName, $extra_data = []){
$params = [
'expand' => 'tracks'
];
$name = str_random(16).'_track_question_template_name';
$label = str_random(16).'_track_question_template_label';
$initial_value = str_random(16).'_initial_value';
$data = [
'name' => $name,
'label' => $label,
'class_name' => $class_name,
'initial_value' => $initial_value,
'is_mandatory' => true,
'is_read_only' => true,
'tracks' => [1, 2 , 3]
];
if(count($extra_data) > 0){
$data = array_merge($data, $extra_data);
}
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"POST",
"OAuth2TrackQuestionsTemplateApiController@addTrackQuestionTemplate",
$params,
[],
[],
[],
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$track_question_template = json_decode($content);
$this->assertTrue(!is_null($track_question_template));
$this->assertTrue($track_question_template->name == $name);
$this->assertTrue($track_question_template->label == $label);
return $track_question_template;
}
/**
* @return mixed
*/
public function testUpdateTrackQuestionTemplate(){
$new_track_question_template = $this->testAddTrackQuestionTemplate();
$params = [
'track_question_template_id' => $new_track_question_template->id,
'expand' => 'tracks'
];
$name = str_random(16).'_track_question_template_name_update';
$label = str_random(16).'_track_question_template_label_update';
$initial_value = str_random(16).'_initial_value_update';
$data = [
'name' => $name,
'label' => $label,
'class_name' => \App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackTextBoxQuestionTemplate::ClassName,
'initial_value' => $initial_value,
'is_mandatory' => false,
'is_read_only' => false,
'tracks' => [1, 3]
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"PUT",
"OAuth2TrackQuestionsTemplateApiController@updateTrackQuestionTemplate",
$params,
[],
[],
[],
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$track_question_template = json_decode($content);
$this->assertTrue(!is_null($track_question_template));
$this->assertTrue($track_question_template->name == $name);
$this->assertTrue($track_question_template->label == $label);
return $track_question_template;
}
public function testDeleteTrackQuestionTemplate(){
$new_track_question_template = $this->testAddTrackQuestionTemplate();
$params = [
'track_question_template_id' => $new_track_question_template->id,
];
$headers =
[
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action
(
"DELETE",
"OAuth2TrackQuestionsTemplateApiController@deleteTrackQuestionTemplate",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(204);
}
public function testGetTrackQuestionTemplateMetadata(){
$params = [
];
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
$response = $this->action(
"GET",
"OAuth2TrackQuestionsTemplateApiController@getTrackQuestionTemplateMetadata",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$metadata = json_decode($content);
$this->assertTrue(!is_null($metadata));
$this->assertResponseStatus(200);
return $metadata;
}
public function testAddTrackQuestionTemplateValue(){
$new_track_question_template = $this->testAddTrackQuestionTemplate(
TrackDropDownQuestionTemplate::ClassName,
[
'empty_string' => '-- select a value --'
]
);
$params = [
'expand' => 'tracks',
'track_question_template_id' => $new_track_question_template->id
];
$value = str_random(16).'_track_question_template_value_value';
$label = str_random(16).'_track_question_template_value_label';
$data = [
'value' => $value,
'label' => $label,
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"POST",
"OAuth2TrackQuestionsTemplateApiController@addTrackQuestionTemplateValue",
$params,
[],
[],
[],
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$track_question_template_value = json_decode($content);
$this->assertTrue(!is_null($track_question_template_value));
$this->assertTrue($track_question_template_value->value == $value);
$this->assertTrue($track_question_template_value->label == $label);
return $track_question_template_value;
}
public function testUpdateTrackQuestionTemplateValue(){
$new_track_question_template_value = $this->testAddTrackQuestionTemplateValue();
$params = [
'expand' => 'tracks',
'track_question_template_id' => $new_track_question_template_value->owner_id,
'track_question_template_value_id' => $new_track_question_template_value->id
];
$value = str_random(16).'_track_question_template_value_value_update';
$label = str_random(16).'_track_question_template_value_label_update';
$data = [
'value' => $value,
'label' => $label,
'order' => 1
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"PUT",
"OAuth2TrackQuestionsTemplateApiController@updateTrackQuestionTemplateValue",
$params,
[],
[],
[],
$headers,
json_encode($data)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$track_question_template_value = json_decode($content);
$this->assertTrue(!is_null($track_question_template_value));
$this->assertTrue($track_question_template_value->value == $value);
$this->assertTrue($track_question_template_value->label == $label);
return $track_question_template_value;
}
public function testDeleteTrackQuestionTemplateValue(){
$new_track_question_template_value = $this->testAddTrackQuestionTemplateValue();
$params = [
'track_question_template_id' => $new_track_question_template_value->owner_id,
'track_question_template_value_id' => $new_track_question_template_value->id
];
$headers =
[
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action
(
"DELETE",
"OAuth2TrackQuestionsTemplateApiController@deleteTrackQuestionTemplateValue",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(204);
}
}