Skip to content

Commit

Permalink
fix: Adjust API version and fix API test
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Dec 18, 2023
1 parent 2928d33 commit 5d1fb2e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
64 changes: 32 additions & 32 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'verb' => 'OPTIONS',
'requirements' => [
'path' => '.+',
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],

Expand All @@ -83,31 +83,31 @@
'url' => '/api/{apiVersion}/forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#newForm',
'url' => '/api/{apiVersion}/form',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#getForm',
'url' => '/api/{apiVersion}/form/{id}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#cloneForm',
'url' => '/api/{apiVersion}/form/clone/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -116,47 +116,47 @@
'url' => '/api/{apiVersion}/form/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#updateForm',
'url' => '/api/{apiVersion}/form/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#transferOwner',
'url' => '/api/{apiVersion}/form/transfer',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#deleteForm',
'url' => '/api/{apiVersion}/form/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#getPartialForm',
'url' => '/api/{apiVersion}/partial_form/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#getSharedForms',
'url' => '/api/{apiVersion}/shared_forms',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],

Expand All @@ -166,7 +166,7 @@
'url' => '/api/{apiVersion}/question',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -175,15 +175,15 @@
'url' => '/api/{apiVersion}/question/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#updateQuestion',
'url' => '/api/{apiVersion}/question/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
// TODO: Remove POST in next API release
Expand All @@ -192,31 +192,31 @@
'url' => '/api/{apiVersion}/question/reorder',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#reorderQuestions',
'url' => '/api/{apiVersion}/question/reorder',
'verb' => 'PUT',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#deleteQuestion',
'url' => '/api/{apiVersion}/question/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#duplicateQuestion',
'name' => 'api#cloneQuestion',
'url' => '/api/{apiVersion}/question/clone/{id}',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2.1'
'apiVersion' => 'v2.3'
]
],

Expand All @@ -226,7 +226,7 @@
'url' => '/api/{apiVersion}/option',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -235,23 +235,23 @@
'url' => '/api/{apiVersion}/option/update',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#updateOption',
'url' => '/api/{apiVersion}/option/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],
[
'name' => 'api#deleteOption',
'url' => '/api/{apiVersion}/option/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],

Expand All @@ -261,15 +261,15 @@
'url' => '/api/{apiVersion}/share',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'shareApi#deleteShare',
'url' => '/api/{apiVersion}/share/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
// TODO: Remove POST in next API release
Expand All @@ -286,7 +286,7 @@
'url' => '/api/{apiVersion}/share/update',
'verb' => 'PATCH',
'requirements' => [
'apiVersion' => 'v2.2'
'apiVersion' => 'v2\.[2-3]'
]
],

Expand All @@ -296,47 +296,47 @@
'url' => '/api/{apiVersion}/submissions/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#exportSubmissions',
'url' => '/api/{apiVersion}/submissions/export/{hash}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#exportSubmissionsToCloud',
'url' => '/api/{apiVersion}/submissions/export',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#deleteAllSubmissions',
'url' => '/api/{apiVersion}/submissions/{formId}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#insertSubmission',
'url' => '/api/{apiVersion}/submission/insert',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
[
'name' => 'api#deleteSubmission',
'url' => '/api/{apiVersion}/submission/{id}',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v2(\.[1-2])?'
'apiVersion' => 'v2(\.[1-3])?'
]
],
]
Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,14 @@ public function deleteQuestion(int $id): DataResponse {
* @CORS
* @NoAdminRequired
*
* Duplicate a question
* Clone a question
*
* @param int $id the question id
* @return DataResponse
* @throws OCSBadRequestException|OCSForbiddenException
*/
public function duplicateQuestion(int $id): DataResponse {
$this->logger->debug('Question to be duplicated: {id}', [
public function cloneQuestion(int $id): DataResponse {
$this->logger->debug('Question to be cloned: {id}', [
'id' => $id
]);

Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/Api/ApiV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,23 +930,23 @@ public function testDeleteQuestion(array $fullFormExpected) {
$this->testGetFullForm($fullFormExpected);
}

public function dataDuplicateQuestion() {
public function dataCloneQuestion() {
$fullFormExpected = $this->dataGetFullForm()['getFullForm']['expected'];
array_splice($fullFormExpected['questions'][1]['options'], 0, 1);

return [
'duplicateQuestion' => [
'clonedQuestion' => [
'fullFormExpected' => $fullFormExpected
]
];
}

/**
* @dataProvider dataDuplicateQuestion
* @dataProvider dataCloneQuestion
* @param array $fullFormExpected
*/
public function testDuplicateQuestion(array $fullFormExpected) {
$resp = $this->http->request('POST', "api/v2/question/{$this->testForms[0]['questions'][0]['id']}");
public function testCloneQuestion(array $fullFormExpected) {
$resp = $this->http->request('POST', 'api/v2.3/question/' . $this->testForms[0]['questions'][0]['id']);
$data = $this->OcsResponse2Data($resp);

$this->assertEquals(200, $resp->getStatusCode());
Expand Down

0 comments on commit 5d1fb2e

Please sign in to comment.