This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(DICOMWeb): adding tests for DICOMWeb files
* test(getAttribute.test.js): adding unit tests for getAttribute * feat(getAuthorizationHeader.test.js): including getAuthorizationHeader.test.js * feat(getName.test.js): adding getName tests * feat(getNumber.test.js): adding getNumber.test.js * feat(getString.test.js): adding getString.test.js * feat(index.test.js): adding index.test.js file * feat(index.test.js): improviments on index test file * feat(getModalities.test.js): adding getModalities tests * feat(index.test.js): emoving call tests since the expect test already covers it
- Loading branch information
Showing
9 changed files
with
424 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import getAttribute from './getAttribute'; | ||
|
||
describe('getAttribute', () => { | ||
it('should return a default value if element is null or undefined', () => { | ||
const defaultValue = '0000'; | ||
const nullElement = null; | ||
const undefinedElement = undefined; | ||
|
||
expect(getAttribute(nullElement, defaultValue)).toEqual(defaultValue); | ||
expect(getAttribute(undefinedElement, defaultValue)).toEqual(defaultValue); | ||
}); | ||
|
||
it('should return a default value if element.Value is null, undefined or not present', () => { | ||
const defaultValue = '0000'; | ||
const nullElement = { | ||
id: 0, | ||
Value: null, | ||
}; | ||
const undefinedElement = { | ||
id: 0, | ||
Value: undefined, | ||
}; | ||
const noValuePresentElement = { | ||
id: 0, | ||
}; | ||
|
||
expect(getAttribute(nullElement, defaultValue)).toEqual(defaultValue); | ||
expect(getAttribute(undefinedElement, defaultValue)).toEqual(defaultValue); | ||
expect(getAttribute(noValuePresentElement, defaultValue)).toEqual( | ||
defaultValue | ||
); | ||
}); | ||
|
||
it('should return 48 for element with value 0', () => { | ||
const returnValue = 48; | ||
const element = { | ||
Value: '0', | ||
}; | ||
expect(getAttribute(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return 3211313 for element with value 11', () => { | ||
const returnValue = 3211313; | ||
const element = { | ||
Value: '11', | ||
}; | ||
expect(getAttribute(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return 2.4923405222191973e+35 for element with value 00280009', () => { | ||
const returnValue = 2.4923405222191973e35; | ||
const element = { | ||
id: 0, | ||
Value: '00280009', | ||
}; | ||
expect(getAttribute(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return 2949169 for element with value -1', () => { | ||
const returnValue = 2949169; | ||
const element = { | ||
id: 0, | ||
Value: '-1', | ||
}; | ||
expect(getAttribute(element, null)).toEqual(returnValue); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import getAuthorizationHeader from './getAuthorizationHeader'; | ||
import user from './../user'; | ||
|
||
jest.mock('./../user.js'); | ||
|
||
describe('getAuthorizationHeader', () => { | ||
it('should return a HTTP Basic Auth when server contains requestOptions.auth', () => { | ||
const validServer = { | ||
requestOptions: { | ||
auth: { | ||
user: 'dummy_user', | ||
password: 'dummy_password', | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedAuthorizationHeader = { | ||
Authorization: `Basic ${btoa(validServer.requestOptions.auth)}`, | ||
}; | ||
|
||
const authentication = getAuthorizationHeader(validServer); | ||
|
||
expect(authentication).toEqual(expectedAuthorizationHeader); | ||
}); | ||
|
||
it('should return a HTTP Basic Auth when server contains requestOptions.auth even though there is no password', () => { | ||
const validServerWithoutPassword = { | ||
requestOptions: { | ||
auth: { | ||
user: 'dummy_user', | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedAuthorizationHeader = { | ||
Authorization: `Basic ${btoa( | ||
validServerWithoutPassword.requestOptions.auth | ||
)}`, | ||
}; | ||
|
||
const authentication = getAuthorizationHeader(validServerWithoutPassword); | ||
|
||
expect(authentication).toEqual(expectedAuthorizationHeader); | ||
}); | ||
|
||
it('should return a HTTP Basic Auth when server contains requestOptions.auth even though there is no username', () => { | ||
const validServerWithoutPassword = { | ||
requestOptions: { | ||
auth: { | ||
user: 'dummy_user', | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedAuthorizationHeader = { | ||
Authorization: `Basic ${btoa( | ||
validServerWithoutPassword.requestOptions.auth | ||
)}`, | ||
}; | ||
|
||
const authentication = getAuthorizationHeader(validServerWithoutPassword); | ||
|
||
expect(authentication).toEqual(expectedAuthorizationHeader); | ||
}); | ||
|
||
it('should return an empty object when there is no either server.requestOptions.auth or accessToken', () => { | ||
const authentication = getAuthorizationHeader({}); | ||
|
||
expect(authentication).toEqual({}); | ||
}); | ||
|
||
it('should return an Authorization with accessToken when server is not defined and there is an accessToken', () => { | ||
user.getAccessToken.mockImplementationOnce(() => 'MOCKED_TOKEN'); | ||
|
||
const authentication = getAuthorizationHeader({}); | ||
const exptecteHeaderBasedOnUserAccessToekn = { | ||
Authorization: 'Bearer MOCKED_TOKEN', | ||
}; | ||
|
||
expect(authentication).toEqual(exptecteHeaderBasedOnUserAccessToekn); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import getModalities from './getModalities'; | ||
|
||
describe('getModalities', () => { | ||
test('should return an empty object when modality and modalitiesInStudy are not present', () => { | ||
const modality = null; | ||
const modalitiesInStudy = null; | ||
|
||
expect(getModalities(modality, modalitiesInStudy)).toEqual({}); | ||
}); | ||
|
||
test('should return an empty object when modality and modalitiesInStudy are not present', () => { | ||
const modality = null; | ||
const modalitiesInStudy = null; | ||
|
||
expect(getModalities(modality, modalitiesInStudy)).toEqual({}); | ||
}); | ||
|
||
test('should return modalities in Study when modality is not defined', () => { | ||
const modality = null; | ||
|
||
const modalitiesInStudy = { | ||
Value: ['MOCKED_VALUE'], | ||
vr: 'MOCKED_VALUE', | ||
}; | ||
|
||
expect(getModalities(modality, modalitiesInStudy)).toEqual( | ||
modalitiesInStudy | ||
); | ||
}); | ||
|
||
test('should return only the modalitues that exists in modalitiesInStudy', () => { | ||
const modality = { | ||
Value: ['DESIRED_VALUE'], | ||
vr: 'DESIRED_VR', | ||
}; | ||
|
||
const modalitiesInStudy = { | ||
Value: ['DESIRED_VALUE', 'NOT_DESIRED_VALUE'], | ||
vr: 'DESIRED_VR', | ||
}; | ||
|
||
expect(getModalities(modality, modalitiesInStudy)).toEqual(modality); | ||
}); | ||
|
||
test('should return the seek modality when the desired modality does not exist in modalitiesInStudy', () => { | ||
const modality = { | ||
Value: ['DESIRED_VALUE'], | ||
vr: 'DESIRED_VR', | ||
}; | ||
|
||
const modalitiesInStudy = { | ||
Value: ['NOT_DESIRED_VALUE'], | ||
vr: 'DESIRED_VR', | ||
}; | ||
|
||
expect(getModalities(modality, modalitiesInStudy)).toEqual(modality); | ||
}); | ||
|
||
test('should return the seek modality when the desired modality does not exist in modalitiesInStudy VR', () => { | ||
const modality = { | ||
Value: ['DESIRED_VALUE'], | ||
vr: 'DESIRED_VR', | ||
}; | ||
|
||
const modalitiesInStudy = { | ||
Value: ['NOT_DESIRED_VALUE'], | ||
vr: 'ANOTHER_VR', | ||
}; | ||
|
||
expect(getModalities(modality, modalitiesInStudy)).toEqual( | ||
modalitiesInStudy | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import getName from './getName'; | ||
|
||
describe('getName', () => { | ||
it('should return a default value if element is null or undefined', () => { | ||
const defaultValue = 'DEFAULT_NAME'; | ||
const nullElement = null; | ||
const undefinedElement = undefined; | ||
|
||
expect(getName(nullElement, defaultValue)).toEqual(defaultValue); | ||
expect(getName(undefinedElement, defaultValue)).toEqual(defaultValue); | ||
}); | ||
|
||
it('should return a default value if element.Value is null, undefined or not present', () => { | ||
const defaultValue = 'DEFAULT_NAME'; | ||
const nullElement = { | ||
id: 0, | ||
Value: null, | ||
}; | ||
const undefinedElement = { | ||
id: 0, | ||
Value: undefined, | ||
}; | ||
const noValuePresentElement = { | ||
id: 0, | ||
}; | ||
|
||
expect(getName(nullElement, defaultValue)).toEqual(defaultValue); | ||
expect(getName(undefinedElement, defaultValue)).toEqual(defaultValue); | ||
expect(getName(noValuePresentElement, defaultValue)).toEqual(defaultValue); | ||
}); | ||
|
||
it('should return A for element when Alphabetic is [A, B, C, D]', () => { | ||
const returnValue = 'A'; | ||
const element = { | ||
Value: [ | ||
{ Alphabetic: 'A' }, | ||
{ Alphabetic: 'B' }, | ||
{ Alphabetic: 'C' }, | ||
{ Alphabetic: 'D' }, | ||
], | ||
}; | ||
expect(getName(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return FIRST for element when Alphabetic is [FIRST, SECOND]', () => { | ||
const returnValue = 'FIRST'; | ||
const element = { | ||
Value: [{ Alphabetic: 'FIRST' }, { Alphabetic: 'SECOND' }], | ||
}; | ||
expect(getName(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return element.value[0] for element with not Alphabetic and when there is at least on element.Value', () => { | ||
const returnValue = { | ||
anyOtherProperty: 'FIRST', | ||
}; | ||
const element = { | ||
Value: [{ anyOtherProperty: 'FIRST' }, { Alphabetic: 'SECOND' }], | ||
}; | ||
expect(getName(element, null)).toEqual(returnValue); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import getNumber from './getNumber'; | ||
|
||
describe('getNumber', () => { | ||
it('should return a default value if element is null or undefined', () => { | ||
const defaultValue = 1.0; | ||
const nullElement = null; | ||
const undefinedElement = undefined; | ||
|
||
expect(getNumber(nullElement, defaultValue)).toEqual(defaultValue); | ||
expect(getNumber(undefinedElement, defaultValue)).toEqual(defaultValue); | ||
}); | ||
|
||
it('should return a default value if element.Value is null, undefined or not present', () => { | ||
const defaultValue = 1.0; | ||
const nullElement = { | ||
id: 0, | ||
Value: null, | ||
}; | ||
const undefinedElement = { | ||
id: 0, | ||
Value: undefined, | ||
}; | ||
const noValuePresentElement = { | ||
id: 0, | ||
}; | ||
|
||
expect(getNumber(nullElement, defaultValue)).toEqual(defaultValue); | ||
expect(getNumber(undefinedElement, defaultValue)).toEqual(defaultValue); | ||
expect(getNumber(noValuePresentElement, defaultValue)).toEqual( | ||
defaultValue | ||
); | ||
}); | ||
|
||
it('should return 2.0 for element when element.Value[0] = 2', () => { | ||
const returnValue = 2.0; | ||
const element = { | ||
Value: ['2'], | ||
}; | ||
expect(getNumber(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return -1.0 for element when element.Value[0] is -1', () => { | ||
const returnValue = -1.0; | ||
const element = { | ||
Value: ['-1'], | ||
}; | ||
expect(getNumber(element, null)).toEqual(returnValue); | ||
}); | ||
|
||
it('should return -1.0 for element when element.Value is [-1, 2, 5, -10] ', () => { | ||
const returnValue = -1.0; | ||
const element = { | ||
Value: ['-1', '2', '5', '-10'], | ||
}; | ||
expect(getNumber(element, null)).toEqual(returnValue); | ||
}); | ||
}); |
Oops, something went wrong.