Skip to content

Commit

Permalink
[FIX] Remove attributes with a NULL label (#124)
Browse files Browse the repository at this point in the history
* [FIX] Remove attributes with a NULL label

* [CI] Add regression test for the null label attribute response

* Update cypress/e2e/APIRequests.cy.ts

Co-authored-by: Arman Jahanpour <[email protected]>

---------

Co-authored-by: Arman Jahanpour <[email protected]>
  • Loading branch information
surchs and rmanaem committed Apr 12, 2024
1 parent e05c823 commit 439bc21
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cypress/e2e/APIRequests.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
nodeOptions,
diagnosisOptions,
emptyDiagnosisOptions,
badDiagnosisOptions,
partiallyFailedDiagnosisToolOptions,
failedDiagnosisToolOptions,
assessmentToolOptions,
Expand Down Expand Up @@ -200,6 +201,44 @@ describe('Successful API query requests', () => {
});
});

// Bad things that should no longer happen
describe('Regression Tests', () => {
it('App can start if attributes have null values and filters out bad attributes', () => {
cy.intercept(
{
method: 'GET',
url: '/nodes/',
},
nodeOptions
).as('getNodes');

cy.intercept(
{
method: 'GET',
url: '/attributes/nb:Diagnosis',
},
badDiagnosisOptions
).as('getDiagnosisOptions');

cy.intercept(
{
method: 'GET',
url: '/attributes/nb:Assessment',
},
assessmentToolOptions
).as('getAssessmentToolOptions');

cy.visit('/');
cy.wait(['@getNodes', '@getDiagnosisOptions', '@getAssessmentToolOptions']);

cy.get('[data-cy="Diagnosis-categorical-field"]').type('parkin{downarrow}{enter}');
cy.get('[data-cy="Diagnosis-categorical-field"] input').should(
'have.value',
"Parkinson's disease"
);
});
});

describe('Partially successful API query requests', () => {
beforeEach(() => {
cy.intercept(
Expand Down
37 changes: 37 additions & 0 deletions cypress/fixtures/mocked-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,43 @@ export const failedDiagnosisToolOptions = {
],
};

// Real example of a bad response where some attributes
// did not have labels in the federated nodes
export const badDiagnosisOptions = {
errors: [
{
node_name: 'International Neuroimaging Data-sharing Initiative',
error:
'Bad Gateway: <html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body>\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx/1.18.0 (Ubuntu)</center>\r\n</body>\r\n</html>\r\n',
},
],
responses: {
'nb:Diagnosis': [
{
TermURL: 'snomed:49049000',
Label: "Parkinson's disease",
},
{
TermURL: 'snomed:77176002',
Label: null,
},
{
TermURL: 'snomed:197480006',
Label: 'Anxiety disorder',
},
{
TermURL: 'snomed:37796009',
Label: null,
},
{
TermURL: 'snomed:82838007',
Label: null,
},
],
},
nodes_response_status: 'partial success',
};

export const assessmentToolOptions = {
errors: [],
responses: {
Expand Down
8 changes: 8 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ function App() {
enqueueSnackbar(`No ${dataElementURI.slice(3)} options were available`, {
variant: 'info',
});
} else if (response.data.responses[dataElementURI].some((item) => item.Label === null)) {
enqueueSnackbar(
`Warning: Missing labels were removed for ${dataElementURI.slice(3)} `,
{ variant: 'warning' }
);
response.data.responses[dataElementURI] = response.data.responses[
dataElementURI
].filter((item) => item.Label !== null);
}
}
return response.data.responses[dataElementURI];
Expand Down

0 comments on commit 439bc21

Please sign in to comment.