diff --git a/src/__tests__/fillRequestObject.spec.ts b/src/__tests__/fillRequestObject.spec.ts new file mode 100644 index 0000000..a9c29da --- /dev/null +++ b/src/__tests__/fillRequestObject.spec.ts @@ -0,0 +1,59 @@ +import Client from '../internal'; +import { CheckParametersTypes } from '../internal/internal.types'; + +it('should return an object with input type, input set, and logical operator when only the required arguments are provided', () => { + const inputType: string = 'cell'; + const outputType: string = 'organ'; + const inputSet: string[] = ['fake']; + + const testObj: CheckParametersTypes = { + inputType, + outputType, + inputSet, + }; + expect(Client.fillRequestObject(testObj)).toEqual({ + input_type: inputType, + input_set: inputSet, + logical_operator: 'and', + }); +}); + +it('should return an object with a p value when input type is organ or gene and output type is gene', () => { + const inputType: string = 'organ'; + const outputType: string = 'gene'; + const inputSet: string[] = ['fake']; + const pValue: number = 0.4; + + const testObj: CheckParametersTypes = { + inputType, + outputType, + pValue, + inputSet, + }; + expect(Client.fillRequestObject(testObj)).toEqual({ + input_type: inputType, + input_set: inputSet, + p_value: pValue, + logical_operator: 'and', + }); +}); + +it('should return an object with a genomic modality if it is defined', () => { + const inputType: string = 'organ'; + const outputType: string = 'cell'; + const inputSet: string[] = ['fake']; + const genomicModality: string = 'fake'; + + const testObj: CheckParametersTypes = { + inputType, + outputType, + genomicModality, + inputSet, + }; + expect(Client.fillRequestObject(testObj)).toEqual({ + input_type: inputType, + input_set: inputSet, + genomic_modality: genomicModality, + logical_operator: 'and', + }); +}); diff --git a/src/internal/index.ts b/src/internal/index.ts index 8bcccec..bfd4d2f 100644 --- a/src/internal/index.ts +++ b/src/internal/index.ts @@ -1,4 +1,4 @@ -import { CheckParametersTypes } from './internal.types'; +import { CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes } from './internal.types'; import { outputTypes, inputTypes, genomicModalities } from './internal.config'; class Client { @@ -37,9 +37,27 @@ class Client { } } - /* - fillRequestObject() {} + static fillRequestObject({ + inputType, + outputType, + inputSet, + genomicModality, + pValue, + }: RequestObjectParametersTypes): RequestObjectTypes { + const requestObject = { input_type: inputType, input_set: inputSet }; + + if (['organ', 'gene'].includes(inputType) && outputType === 'gene') { + requestObject.p_value = pValue; + } + + if (genomicModality) { + requestObject.genomic_modality = genomicModality; + } + requestObject.logical_operator = 'and'; + return requestObject; + } + /* hubmapQuery() {} setIntersection() {} diff --git a/src/internal/internal.types.ts b/src/internal/internal.types.ts index d072c14..1ed95ad 100644 --- a/src/internal/internal.types.ts +++ b/src/internal/internal.types.ts @@ -8,9 +8,26 @@ interface InputTypes { interface CheckParametersTypes { inputType: string; outputType: keyof InputTypes; - // inputSet: string[]; - genomicModality: string; + inputSet?: string[]; + genomicModality?: string; pValue?: number; } -export { InputTypes, CheckParametersTypes }; +interface RequestObjectParametersTypes { + inputType: string; + outputType: keyof InputTypes; + inputSet: string[]; + genomicModality?: string; + pValue?: number; +} +interface RequestObjectTypes { + /* eslint-disable camelcase */ + input_type: string; + input_set: string[]; + genomic_modality?: string; + p_value?: number; + logical_operator: 'and'; + /* eslint-enable camelcase */ +} + +export { InputTypes, CheckParametersTypes, RequestObjectParametersTypes, RequestObjectTypes };