Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
[#30] Rename "problems" to "conditions"
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbaptista committed May 18, 2016
1 parent 566a607 commit 68b6457
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 121 deletions.
6 changes: 3 additions & 3 deletions agents/problems.js → agents/conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

const opentrialsApi = require('../config').opentrialsApi;

function getProblem(problemId) {
function getCondition(conditionId) {
return opentrialsApi
.then((client) => client.problems.get({ id: problemId }))
.then((client) => client.conditions.get({ id: conditionId }))
.then((response) => response.obj);
}

module.exports = {
get: getProblem,
get: getCondition,
};
2 changes: 1 addition & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ $(document).ready(function() {
.removeAttr('selected');
});

setupSelect2For('problem');
setupSelect2For('condition');
setupSelect2For('intervention');
setupSelect2For('person');
setupSelect2For('organisation');
Expand Down
23 changes: 23 additions & 0 deletions handlers/condition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const Boom = require('boom');
const conditions = require('../agents/conditions');

function conditionsDetails(request, reply) {
const conditionId = request.params.id;

conditions.get(conditionId).then((_condition) => {
reply.view('conditions-details', {
title: _condition.name,
condition: _condition,
});
}).catch((err) => {
if (err.status === 404) {
reply(Boom.notFound('Condition not found.', err));
} else {
reply(Boom.badGateway('Error accessing OpenTrials API.', err));
}
});
}

module.exports = conditionsDetails;
23 changes: 0 additions & 23 deletions handlers/problem.js

This file was deleted.

6 changes: 3 additions & 3 deletions handlers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ function getFilters(query) {
values.map((val) => `"${val}"`)
);

if (query.problem) {
filters.problem = quoteElements(query.problem);
if (query.condition) {
filters.condition = quoteElements(query.condition);
}
if (query.intervention) {
filters.intervention = quoteElements(query.intervention);
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = {
registration_date_end: Joi.date().format('YYYY-MM-DD').empty('').raw(),
location: Joi.array().single(true).items(Joi.string().empty('')),
q: Joi.string().empty(''),
problem: Joi.array().single(true).items(Joi.string().empty('')),
condition: Joi.array().single(true).items(Joi.string().empty('')),
intervention: Joi.array().single(true).items(Joi.string().empty('')),
person: Joi.array().single(true).items(Joi.string().empty('')),
organisation: Joi.array().single(true).items(Joi.string().empty('')),
Expand Down
4 changes: 2 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const routes = [
config: require('../handlers/search'),
},
{
path: '/problems/{id}',
path: '/conditions/{id}',
method: 'GET',
handler: require('../handlers/problem'),
handler: require('../handlers/condition'),
},
{
path: '/interventions/{id}',
Expand Down
23 changes: 23 additions & 0 deletions test/agents/conditions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const conditions = require('../../agents/conditions');

describe('Conditions', () => {
describe('#get', () => {
it('returns the condition', () => {
const data = {
id: 1,
name: 'foo',
};
apiServer.get('/conditions/1').reply(200, data);
return conditions.get(1).should.be.fulfilledWith(data);
});

it('rejects if conditionId is inexistent', () => {
apiServer.get('/conditions/1').reply(404);

return conditions.get(1).should.be.rejectedWith({
errObj: { status: 404 },
});
});
});
});
23 changes: 0 additions & 23 deletions test/agents/problems.js

This file was deleted.

31 changes: 13 additions & 18 deletions test/fixtures/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ paths:
description: The entity to search for
type: string
enum:
- problem
- condition
- intervention
- location
- person
Expand Down Expand Up @@ -122,26 +122,26 @@ paths:
schema:
$ref: "#/definitions/ErrorResponse"

/problems/{id}:
x-swagger-router-controller: problems
/conditions/{id}:
x-swagger-router-controller: conditions
get:
tags:
- problems
description: Returns problem details
- conditions
description: Returns condition details
operationId: get
parameters:
- name: id
in: path
description: ID of the problem
description: ID of the condition
required: true
type: string
responses:
"200":
description: Success
schema:
$ref: "#/definitions/Problem"
$ref: "#/definitions/Condition"
"404":
description: Problem not found
description: Condition not found
default:
description: Error
schema:
Expand Down Expand Up @@ -377,10 +377,10 @@ definitions:
type: array
items:
$ref: '#/definitions/TrialIntervention'
problems:
conditions:
type: array
items:
$ref: '#/definitions/TrialProblem'
$ref: '#/definitions/TrialCondition'
persons:
type: array
items:
Expand Down Expand Up @@ -446,7 +446,7 @@ definitions:
- drug
- other

TrialProblem:
TrialCondition:
required:
- attributes
properties:
Expand All @@ -455,8 +455,8 @@ definitions:
enum:
- other
attributes:
$ref: '#/definitions/Problem'
Problem:
$ref: '#/definitions/Condition'
Condition:
required:
- id
- name
Expand All @@ -465,11 +465,6 @@ definitions:
type: string
name:
type: string
type:
type: string
enum:
- condition
- other

TrialPerson:
required:
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/conditions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const uuid = require('node-uuid');

function getCondition() {
const condition = {
id: uuid.v1(),
name: 'test condition',
};

return condition;
}

module.exports = getCondition;
2 changes: 1 addition & 1 deletion test/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fixtures = {
getProblem: require('./problems'),
getCondition: require('./conditions'),
getPerson: require('./persons'),
getOrganisation: require('./organisations'),
getIntervention: require('./interventions'),
Expand Down
12 changes: 0 additions & 12 deletions test/fixtures/problems.js

This file was deleted.

34 changes: 17 additions & 17 deletions test/handlers/problems.js → test/handlers/conditions.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';
const server = require('../../server');

describe('problems handler', () => {
describe('GET /problems/{id}', () => {
describe('conditions handler', () => {
describe('GET /conditions/{id}', () => {
describe('API is OK', () => {
const problem = JSON.parse(JSON.stringify(
fixtures.getProblem()
const condition = JSON.parse(JSON.stringify(
fixtures.getCondition()
));
let response;

before(() => {
apiServer.get('/problems/'+problem.id).reply(200, problem);
apiServer.get('/conditions/'+condition.id).reply(200, condition);

return server.inject('/problems/'+problem.id)
return server.inject('/conditions/'+condition.id)
.then((_response) => {
response = _response;
});
Expand All @@ -22,24 +22,24 @@ describe('problems handler', () => {
response.statusCode.should.equal(200)
});

it('uses the "problems-list" template', () => (
response.request.response.source.template.should.equal('problems-details')
it('uses the "conditions-list" template', () => (
response.request.response.source.template.should.equal('conditions-details')
));

it('adds the requested problem to the context', () => {
it('adds the requested condition to the context', () => {
const context = response.request.response.source.context;
context.problem.should.deepEqual(problem);
context.condition.should.deepEqual(condition);
});

it('sets the title to the problem.name', () => {
it('sets the title to the condition.name', () => {
const context = response.request.response.source.context;
context.title.should.equal(problem.name);
context.title.should.equal(condition.name);
});

it('returns 404 when problem doesnt exist', () => {
apiServer.get('/problems/foo').reply(404);
it('returns 404 when condition doesnt exist', () => {
apiServer.get('/conditions/foo').reply(404);

return server.inject('/problems/foo')
return server.inject('/conditions/foo')
.then((_response) => {
_response.statusCode.should.equal(404);
});
Expand All @@ -48,9 +48,9 @@ describe('problems handler', () => {

describe('API is not OK', () => {
it('returns error 502', () => {
apiServer.get('/problems/foo').reply(500);
apiServer.get('/conditions/foo').reply(500);

return server.inject('/problems/foo')
return server.inject('/conditions/foo')
.then((_response) => {
_response.statusCode.should.equal(502);
});
Expand Down

0 comments on commit 68b6457

Please sign in to comment.