Skip to content

Commit

Permalink
🔥 Remove code related to portal-legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
evans-g-crsj committed Jun 27, 2024
1 parent 9d08981 commit b8a8a8d
Show file tree
Hide file tree
Showing 34 changed files with 2,302 additions and 7,271 deletions.
6 changes: 0 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ MAX_NUMBER_OF_GF_SUGGESTIONS=
GENES_SUGGESTIONS_INDEX_NAME=
VARIANTS_SUGGESTIONS_INDEX_NAME=

# SQS configuration
SEND_UPDATE_TO_SQS=
SQS_QUEUE_URL=
MAX_SET_CONTENT_SIZE=

# Riff
RIFF_URL=

# Index names
ES_FILE_INDEX=
ES_STUDY_INDEX=
Expand Down
7,266 changes: 2,240 additions & 5,026 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@arranger/middleware": "^2.16.0",
"@arranger/server": "^2.16.1",
"@awaitjs/express": "^0.8.0",
"@aws-sdk/client-sqs": "^3.438.0",
"@elastic/elasticsearch": "^7.9.1",
"ajv": "^8.12.0",
"cors": "2.8.5",
Expand Down
2 changes: 0 additions & 2 deletions src/ElasticSearchClientInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class EsInstance {
constructor() {
if (!this.instance) {
if (esUser && esPass) {
console.debug('Using basic auth');
this.instance = new Client({ node: esHost, auth: { username: esUser, password: esPass } });
} else {
console.debug('Not using basic auth');
this.instance = new Client({ node: esHost });
}
}
Expand Down
48 changes: 0 additions & 48 deletions src/SQS/eventTypes.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/SQS/sendEvent.ts

This file was deleted.

109 changes: 3 additions & 106 deletions src/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { SQSClient } from '@aws-sdk/client-sqs';
import { Express } from 'express';
import Keycloak from 'keycloak-connect';
import request from 'supertest';

import { fakeKeycloakClient, fakeKeycloakRealm, fakeKeycloakUrl, getToken, publicKey } from '../test/authTestUtils';
import buildApp from './app';
import { ArrangerProject } from './arrangerUtils';
import { searchAllSources } from './endpoints/searchByIds/searchAllSources';
import { SetNotFoundError } from './endpoints/sets/setError';
import {
createSet,
Expand All @@ -18,11 +16,9 @@ import {
} from './endpoints/sets/setsFeature';
import { Set, UpdateSetContentBody, UpdateSetTagBody } from './endpoints/sets/setsTypes';
import { getStatistics, getStudiesStatistics, Statistics } from './endpoints/statistics';
import { RiffError } from './riff/riffError';

jest.mock('./endpoints/sets/setsFeature');
jest.mock('./endpoints/statistics');
jest.mock('./endpoints/searchByIds/searchAllSources');

describe('Express app (without Arranger)', () => {
let app: Express;
Expand All @@ -31,7 +27,6 @@ describe('Express app (without Arranger)', () => {
const getProject = (_s: string) => ({} as ArrangerProject);

beforeEach(() => {
const sqs = new SQSClient({});
const publicKeyToVerify = publicKey;
keycloakFakeConfig = {
realm: fakeKeycloakRealm,
Expand All @@ -43,7 +38,7 @@ describe('Express app (without Arranger)', () => {
'realm-public-key': publicKeyToVerify, // For test purpose, we use public key to validate token.
};
const keycloak = new Keycloak({}, keycloakFakeConfig);
app = buildApp(keycloak, sqs, getProject); // Re-create app between each test to ensure isolation between tests.
app = buildApp(keycloak, getProject); // Re-create app between each test to ensure isolation between tests.
});

it('GET /status (public) should responds with json', async () => {
Expand Down Expand Up @@ -274,21 +269,6 @@ describe('Express app (without Arranger)', () => {
.expect(200, expectedSets);
expect((getSets as jest.Mock).mock.calls.length).toEqual(1);
});

it('should return 500 if Authorization header contains valid token but an error occurs', async () => {
const expectedError = new RiffError(404, { message: 'OOPS' });
(getSets as jest.Mock).mockImplementation(() => {
throw expectedError;
});

const token = getToken();

await request(app)
.get('/sets')
.set({ Authorization: `Bearer ${token}` })
.expect(500, { error: 'Internal Server Error' });
expect((getSets as jest.Mock).mock.calls.length).toEqual(1);
});
});

describe('POST /sets', () => {
Expand Down Expand Up @@ -344,23 +324,6 @@ describe('Express app (without Arranger)', () => {
.expect(200);
expect((createSet as jest.Mock).mock.calls.length).toEqual(1);
});

it('should return 500 if Authorization header contains valid token but an error occurs', async () => {
const expectedError = new RiffError(400, { message: 'OOPS' });
(createSet as jest.Mock).mockImplementation(() => {
throw expectedError;
});

const token = getToken();

await request(app)
.post('/sets')
.send(requestBody)
.set('Content-type', 'application/json')
.set({ Authorization: `Bearer ${token}` })
.expect(500, { error: 'Internal Server Error' });
expect((createSet as jest.Mock).mock.calls.length).toEqual(1);
});
});

describe('PUT /sets/:setId', () => {
Expand Down Expand Up @@ -420,11 +383,11 @@ describe('Express app (without Arranger)', () => {
.set({ Authorization: `Bearer ${token}` })
.expect(checkRes)
.expect(200);

expect((updateSetTag as jest.Mock).mock.calls.length).toEqual(1);
expect((updateSetTag as jest.Mock).mock.calls[0][0]).toEqual(updateSetTagBody);
expect((updateSetTag as jest.Mock).mock.calls[0][1]).toEqual(`Bearer ${token}`);
expect((updateSetTag as jest.Mock).mock.calls[0][2]).toEqual(userId);
expect((updateSetTag as jest.Mock).mock.calls[0][3]).toEqual('1eh');
expect((updateSetTag as jest.Mock).mock.calls[0][2]).toEqual('1eh');
});

it('should return 200 if Authorization header contains valid token and no error occurs - update content', async () => {
Expand Down Expand Up @@ -496,71 +459,5 @@ describe('Express app (without Arranger)', () => {
.expect(200, 'true');
expect((deleteSet as jest.Mock).mock.calls.length).toEqual(1);
});

it('should return 500 if Authorization header contains valid token but an error occurs', async () => {
const expectedError = new RiffError(404, { message: 'OOPS' });
(deleteSet as jest.Mock).mockImplementation(() => {
throw expectedError;
});

const token = getToken();

await request(app)
.delete('/sets/1ei')
.set('Content-type', 'application/json')
.set({ Authorization: `Bearer ${token}` })
.expect(500, { error: 'Internal Server Error' });
expect((deleteSet as jest.Mock).mock.calls.length).toEqual(1);
});
});

describe('POST /searchByIds', () => {
const requestBody = {
project: '2021_05_03_v2',
ids: ['PT_HXDR3ZX6'],
};

beforeEach(() => {
(searchAllSources as jest.Mock).mockReset();
});

it('should return 403 if no Authorization header', () =>
request(app)
.post('/searchByIds')
.expect(403));

it('should return 200 if Authorization header contains valid token and no error occurs', async () => {
const mockSearchByIdsResponse = [
{ search: 'PT_HXDR3ZX6', type: 'PARTICIPANT', participantIds: ['PT_HXDR3ZX6'] },
];
(searchAllSources as jest.Mock).mockImplementation(() => mockSearchByIdsResponse);

const token = getToken();

await request(app)
.post('/searchByIds')
.send(requestBody)
.set('Content-type', 'application/json')
.set({ Authorization: `Bearer ${token}` })
.expect(200, { participants: mockSearchByIdsResponse });
expect((searchAllSources as jest.Mock).mock.calls.length).toEqual(1);
});

it('should return 500 if Authorization header contains valid token but an error occurs', async () => {
const expectedError = new Error('OOPS');
(searchAllSources as jest.Mock).mockImplementation(() => {
throw expectedError;
});

const token = getToken();

await request(app)
.post('/searchByIds')
.send(requestBody)
.set('Content-type', 'application/json')
.set({ Authorization: `Bearer ${token}` })
.expect(500, { error: 'Internal Server Error' });
expect((searchAllSources as jest.Mock).mock.calls.length).toEqual(1);
});
});
});
26 changes: 5 additions & 21 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import addAsync from '@awaitjs/express';
import { SQSClient } from '@aws-sdk/client-sqs';
import cors from 'cors';
import express, { Express } from 'express';
import { Keycloak } from 'keycloak-connect';
Expand All @@ -10,8 +9,6 @@ import { ArrangerProject } from './arrangerUtils';
import { computeAuthorizedStudiesForAllFences } from './endpoints/authorizedStudies/computeAuthorizedStudies';
import genomicFeatureSuggestions, { SUGGESTIONS_TYPES } from './endpoints/genomicFeatureSuggestions';
import { getPhenotypesNodes } from './endpoints/phenotypes';
import { searchAllSources } from './endpoints/searchByIds/searchAllSources';
import { SearchByIdsResult } from './endpoints/searchByIds/searchByIdsTypes';
import {
createSet,
deleteSet,
Expand All @@ -28,7 +25,7 @@ import { STATISTICS_CACHE_ID, STATISTICS_PUBLIC_CACHE_ID, verifyCache } from './
import { injectBodyHttpHeaders } from './middleware/injectBodyHttpHeaders';
import { resolveSetIdMiddleware } from './middleware/resolveSetIdInSqon';

export default (keycloak: Keycloak, sqs: SQSClient, getProject: (projectId: string) => ArrangerProject): Express => {
export default (keycloak: Keycloak, getProject: (projectId: string) => ArrangerProject): Express => {
const app = addAsync.addAsync(express());

const cache = new NodeCache({ stdTTL: cacheTTL });
Expand Down Expand Up @@ -88,26 +85,17 @@ export default (keycloak: Keycloak, sqs: SQSClient, getProject: (projectId: stri
res.json(data);
});

app.postAsync('/searchByIds', keycloak.protect(), async (req, res) => {
const ids: string[] = req.body.ids;
const projectId: string = req.body.project;
const participants: SearchByIdsResult[] = await searchAllSources(ids, projectId, getProject);

res.send({ participants });
});

app.getAsync('/sets', keycloak.protect(), async (req, res) => {
const accessToken = req.headers.authorization;
const userId = req['kauth']?.grant?.access_token?.content?.sub;
const userSets = await getSets(accessToken, userId);
const userSets = await getSets(accessToken);

res.send(userSets);
});

app.postAsync('/sets', keycloak.protect(), async (req, res) => {
const accessToken = req.headers.authorization;
const userId = req['kauth']?.grant?.access_token?.content?.sub;
const createdSet = await createSet(req.body as CreateSetBody, accessToken, userId, sqs, getProject);
const createdSet = await createSet(req.body as CreateSetBody, accessToken, userId, getProject);

res.send(createdSet);
});
Expand All @@ -120,14 +108,13 @@ export default (keycloak: Keycloak, sqs: SQSClient, getProject: (projectId: stri
let updatedSet: Set;

if (requestBody.subAction === SubActionTypes.RENAME_TAG) {
updatedSet = await updateSetTag(requestBody as UpdateSetTagBody, accessToken, userId, setId, sqs);
updatedSet = await updateSetTag(requestBody as UpdateSetTagBody, accessToken, setId);
} else {
updatedSet = await updateSetContent(
requestBody as UpdateSetContentBody,
accessToken,
userId,
setId,
sqs,
getProject,
);
}
Expand All @@ -136,17 +123,15 @@ export default (keycloak: Keycloak, sqs: SQSClient, getProject: (projectId: stri

app.deleteAsync('/sets/:setId', keycloak.protect(), async (req, res) => {
const accessToken = req.headers.authorization;
const userId = req['kauth']?.grant?.access_token?.content?.sub;
const setId: string = req.params.setId;

const deletedResult = await deleteSet(accessToken, setId, userId, sqs);
const deletedResult = await deleteSet(accessToken, setId);

res.send(deletedResult);
});

app.postAsync('/phenotypes', keycloak.protect(), async (req, res) => {
const accessToken = req.headers.authorization;
const userId = req['kauth']?.grant?.access_token?.content?.sub;
const sqon: SetSqon = req.body.sqon;
const type: string = req.body.type;
const projectId: string = req.body.project;
Expand All @@ -158,7 +143,6 @@ export default (keycloak: Keycloak, sqs: SQSClient, getProject: (projectId: stri
type,
aggregations_filter_themselves,
accessToken,
userId,
);

res.send({ data });
Expand Down
3 changes: 1 addition & 2 deletions src/endpoints/phenotypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ export const getPhenotypesNodes = async (
type: string,
aggregations_filter_themselves: boolean,
accessToken: string,
userId: string,
) => {
const newSqon = await replaceSetByIds(sqon, accessToken, userId);
const newSqon = await replaceSetByIds(sqon, accessToken);

const participantIds = await getParticipantIds(newSqon as SetSqon, projectId, getProject);

Expand Down
Loading

0 comments on commit b8a8a8d

Please sign in to comment.