Skip to content

Commit

Permalink
Merge pull request #65 from UofS-Pulse-Binfo/calls-trials
Browse files Browse the repository at this point in the history
Creates unit test for trials call
  • Loading branch information
laceysanderson authored Jun 27, 2024
2 parents 0e4b9bd + cbd23a0 commit 4cce235
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 4 deletions.
10 changes: 6 additions & 4 deletions calls/v1/trials/TripalWebServiceBrapiV1Trials.inc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class TripalWebServiceBrapiV1Trials extends TripalWebServiceDatabaseCall {
if (isset($call_asset['parameter']['programDbId'])
&& !empty($call_asset['parameter']['programDbId'])) {

$filter[] = 'category.projectprop_id = :programDbId';
$filter[] = 'program.project_id = :programDbId';
$args[':programDbId'] = $call_asset['parameter']['programDbId'];
}

Expand Down Expand Up @@ -181,8 +181,10 @@ class TripalWebServiceBrapiV1Trials extends TripalWebServiceDatabaseCall {
LEFT JOIN {project_relationship} AS category ON project.project_id = category.subject_project_id AND category.type_id = %d
LEFT JOIN {project} AS program ON category.object_project_id = program.project_id
WHERE is_research_area.value::int = 0 OR is_research_area.value IS NULL %s
%s
WHERE
project.project_id IN (SELECT project_id FROM {phenotype} GROUP BY project_id) AND
is_research_area.value::int = 0 OR is_research_area.value IS NULL %s
%s
LIMIT %d OFFSET %d
";

Expand Down Expand Up @@ -233,7 +235,7 @@ class TripalWebServiceBrapiV1Trials extends TripalWebServiceDatabaseCall {
}
}

$project->studies = [ $all_studies ];
$project->studies = (array) ['set' => $all_studies];

// Dates (year range).
if (preg_match('/^[0-9]{4}-{1}[0-9]{4}$/', $project->startdate)) {
Expand Down
83 changes: 83 additions & 0 deletions tests/calls-v.13/trialsCallTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
namespace Tests\calls;

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

/**
* Trials Call (Version 1.3)
* https://brapi.docs.apiary.io/#reference/trials/get-trials
*/
class trialsCallTest extends GenericHttpTestCase {

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

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

/**
* 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',
'programDbId' => 'string',
'programName' => 'string',
'studies' => 'array',
'trialDbId' => 'string',
'trialName' => 'string',
'endDate' => 'string',
'startDate' => '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' => 'Brapus', // 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);
}
}

0 comments on commit 4cce235

Please sign in to comment.