Skip to content

Commit

Permalink
Merge pull request #63 from UofS-Pulse-Binfo/calls-studies
Browse files Browse the repository at this point in the history
Creates unit test for studies call
  • Loading branch information
laceysanderson authored Jun 27, 2024
2 parents 4cce235 + 5804fed commit be9c993
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
11 changes: 10 additions & 1 deletion calls/v1/studies/TripalWebServiceBrapiV1Studies.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TripalWebServiceBrapiV1Studies extends TripalWebServiceDatabaseCall {
'programDbId' => 'int', // Program filter to only return studies associated with given program id.
'locationDbId' => 'int', // Filter by location.
'trialDbId' => 'int', // Filter by trial.
'studyDbId' => 'int', // Filter by study DbId.
'sortBy' => ['commonCropName', 'name', 'studyName'],
'sortOrder' => 'asc/desc',
'page' => 'int', // Which result page is requested.
Expand Down Expand Up @@ -163,6 +164,14 @@ class TripalWebServiceBrapiV1Studies extends TripalWebServiceDatabaseCall {
$args[':trialDbId'] = $call_asset['parameter']['trialDbId'];
}

// studyDbId.
if (isset($call_asset['parameter']['studyDbId'])
&& !empty($call_asset['parameter']['studyDbId'])) {

$filter[] = 'prj.project_id = :studyDbId';
$args[':studyDbId'] = $call_asset['parameter']['studyDbId'];
}

// Transform parameters into a string, as where clause in the query.
$where = '';
if (isset($filter) && count($filter) > 0) {
Expand Down Expand Up @@ -218,7 +227,7 @@ class TripalWebServiceBrapiV1Studies extends TripalWebServiceDatabaseCall {
category.value AS programname,
ARRAY_TO_JSON(ARRAY['n/a', 'n/a', year.value]) AS seasons,
'n/a' AS startdate,
'n/a' AS studydbid,
prj.project_id AS studydbid,
CONCAT(year.value, ' - ', loc.value) AS studyname,
'n/a' AS studytype,
'n/a' AS studytypedbid,
Expand Down
109 changes: 109 additions & 0 deletions tests/calls-v.13/studiesCallTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
namespace Tests\calls;

use StatonLab\TripalTestSuite\TripalTestCase;
use Tests\GenericHttpTestCase;

/**
* Studies Call (Version 1.3)
* https://brapi.docs.apiary.io/#reference/study/studies/get-studies
*/
class studiesCallTest extends GenericHttpTestCase {

/**
* The short name of the call for Assestion messages.
*/
public $callname = 'studies';

/**
* The URL for the call for requests.
* For example: web-services/brapi/v1/people
*/
public $url = 'web-services/brapi/v1/studies';

/**
* The structure of the data result.
* Each entry should be key => valuetype | array.
* Valid valuetypes are: string, integer, object, array.
*/
public $data_structure = [
'active' => 'string',
'additionalInfo' => 'object',
'commonCropName' => 'string',
'documentationURL' => 'string',
'endDate' => 'string',
'locationDbId' => 'string',
'locationName' => 'string',
'name' => 'string',
'programDbId' => 'string',
'programName' => 'string',
'seasons' => 'array',
'startDate' => 'string',
'studyDbId' => 'string',
'studyName' => 'string',
'studyType' => 'string',
'studyTypeDbId' => 'string',
'studyTypeName' => 'string',
'trialDbId' => 'string',
'trialName' => 'string',
];

/**
* CORE TEST.
*/
public function testCall() {

//---------------------------------
// 1. NO PARAMETERS.
$response = NULL;
$this->assertWithNoParameters($response);
$numOfResults = sizeof($response->result->data);

//---------------------------------
// 2. WITH PARAMETERS: pageSize
$response = NULL;
$this->assertPageSize($response, $numOfResults);
$page1_results = $response->result->data;

//---------------------------------
// 3. WITH PARAMETERS: page, pageSize
$response = NULL;
$this->assertPaging($response, $numOfResults, $page1_results);

//---------------------------------
// 4. WITH PARAMETERS: commonCropName
$response = NULL;
$this->assertWithParameter($response, [
'name' => 'commonCropName', // Parameter name.
'key' => 'commonCropName', // The response key the parameter name will match.
'value' => 'Tripalus', // Parameter value
]);

//---------------------------------
// 5. WITH PARAMETERS: programDbId
$response = NULL;
$this->assertWithParameter($response, [
'name' => 'programDbId', // Parameter name.
'key' => 'programDbId', // The response key the parameter name will match.
'value' => '', // Pick one.
], TRUE);

//---------------------------------
// 6. WITH PARAMETERS: locationDbId
$response = NULL;
$this->assertWithParameter($response, [
'name' => 'locationDbId', // Parameter name.
'key' => 'locationDbId', // The response key the parameter name will match.
'value' => '', // Pick one.
], TRUE);

//---------------------------------
// 7. WITH PARAMETERS: trialDbId
$response = NULL;
$this->assertWithParameter($response, [
'name' => 'trialDbId', // Parameter name.
'key' => 'trialDbId', // The response key the parameter name will match.
'value' => '', // Pick one.
], TRUE);
}
}

0 comments on commit be9c993

Please sign in to comment.