Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/__tests__/fillRequestObject.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
});
});
24 changes: 21 additions & 3 deletions src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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() {}
Expand Down
23 changes: 20 additions & 3 deletions src/internal/internal.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };