Skip to content

Commit

Permalink
fixed test suite compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Dec 11, 2023
2 parents f6f7964 + ace08d2 commit 6186468
Show file tree
Hide file tree
Showing 32 changed files with 1,170 additions and 286 deletions.
22 changes: 22 additions & 0 deletions api/src/openapi/root-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ export const rootAPIDoc = {
}
},
additionalProperties: false
},
feature: {
type: 'object',
required: ['submission_feature_id', 'submission_id', 'feature_type', 'data', 'parent_submission_feature_id'],
properties: {
submission_feature_id: {
type: 'number'
},
submission_id: {
type: 'number'
},
feature_type: {
type: 'string'
},
data: {
type: 'object'
},
parent_submission_feature_id: {
type: 'number',
nullable: true
}
}
}
}
}
Expand Down
133 changes: 133 additions & 0 deletions api/src/paths/administrative/security/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { SYSTEM_ROLE } from '../../../constants/roles';
import { getDBConnection } from '../../../database/db';
import { authorizeRequestHandler } from '../../../request-handlers/security/authorization';
import { SecurityService } from '../../../services/security-service';
import { getLogger } from '../../../utils/logger';

const defaultLog = getLogger('paths/administrative/security');

export const GET: Operation = [
authorizeRequestHandler(() => {
return {
and: [
{
validSystemRoles: [SYSTEM_ROLE.SYSTEM_ADMIN],
discriminator: 'SystemRole'
}
]
};
}),
() => {}

Check failure on line 22 in api/src/paths/administrative/security/index.ts

View workflow job for this annotation

GitHub Actions / Running Linter and Formatter

Unexpected empty arrow function
];

GET.apiDoc = {
description: 'Get all observations for the survey.',
tags: ['observation'],
security: [
{
Bearer: []
}
],
parameters: [
{
in: 'path',
name: 'projectId',
schema: {
type: 'number',
minimum: 1
},
required: true
},
{
in: 'path',
name: 'surveyId',
schema: {
type: 'number',
minimum: 1
},
required: true
}
],
responses: {
200: {
description: 'Security Rules.',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
security_rule_id: {
type: 'number'
},
name: {
type: 'string'
},
description: {
type: 'string'
},
record_effective_date: {
type: 'string'
},
record_end_date: {
type: 'string'
},
create_date: {
type: 'string'
},
create_user: {
type: 'number'
},
update_date: {
type: 'string'
},
update_user: {
type: 'number'
},
revision_count: {
type: 'string'
}
}
}
}
}
}
},
400: {
$ref: '#/components/responses/400'
},
401: {
$ref: '#/components/responses/401'
},
403: {
$ref: '#/components/responses/403'
},
500: {
$ref: '#/components/responses/500'
},
default: {
$ref: '#/components/responses/default'
}
}
};

export function getActiveSecurityRules(): RequestHandler {
return async (req, res) => {
const connection = getDBConnection(req['keycloak_token']);
const service = new SecurityService(connection);

try {
const data = await service.getActiveSecurityRules();
return res.status(200).json(data);
} catch (error) {
defaultLog.error({ label: 'getActiveSecurityRules', message: 'error', error });
await connection.rollback();
throw error;
} finally {
connection.release();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { getUnreviewedSubmissions } from '.';
import { getUnreviewedSubmissionsForAdmins } from '.';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/http-error';
import { SubmissionService } from '../../../../services/submission-service';
Expand All @@ -26,7 +26,7 @@ describe('list', () => {

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

const requestHandler = getUnreviewedSubmissions();
const requestHandler = getUnreviewedSubmissionsForAdmins();

try {
await requestHandler(mockReq, mockRes, mockNext);
Expand All @@ -48,10 +48,10 @@ describe('list', () => {
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

const getUnreviewedSubmissionsStub = sinon
.stub(SubmissionService.prototype, 'getUnreviewedSubmissions')
.stub(SubmissionService.prototype, 'getUnreviewedSubmissionsForAdmins')
.resolves([]);

const requestHandler = getUnreviewedSubmissions();
const requestHandler = getUnreviewedSubmissionsForAdmins();

await requestHandler(mockReq, mockRes, mockNext);

Expand Down
77 changes: 0 additions & 77 deletions api/src/paths/dataset/{datasetId}/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions api/src/paths/dwc/submission/{datasetId}/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/http-error';
import { Artifact } from '../../../../repositories/artifact-repository';
import { SECURITY_APPLIED_STATUS } from '../../../../repositories/security-repository';
import { ArtifactService } from '../../../../services/artifact-service';
import { SecurityService } from '../../../../services/security-service';
Expand Down Expand Up @@ -219,7 +218,7 @@ describe('getArtifactsByDatasetId', () => {
const artifactServiceStub = sinon.stub(ArtifactService.prototype, 'getArtifactsByDatasetId').resolves([
{ artifact_id: 1, security_review_timestamp: new Date('1970-01-01T00:00:00.000Z') },
{ artifact_id: 2, security_review_timestamp: new Date('1970-01-01T00:00:00.000Z') }
] as Artifact[]);
] as any[]);

const isSystemUserAdminStub = sinon.stub(UserService.prototype, 'isSystemUserAdmin').resolves(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { ValidationService } from '../../services/validation-service';
import { getKeycloakSource } from '../../utils/keycloak-utils';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/dataset/intake');
const defaultLog = getLogger('paths/submission/intake');

/*
TODO: UPDATED PATH TO SUBMISSION/INTAKE NEED TO UPDATE SIMS TO USE THIS PATH
*/

export const POST: Operation = [
authorizeRequestHandler(() => {
Expand All @@ -23,12 +27,12 @@ export const POST: Operation = [
]
};
}),
datasetIntake()
submissionIntake()
];

POST.apiDoc = {
description: 'Submit dataset to BioHub',
tags: ['dataset'],
description: 'Submit submission to BioHub',
tags: ['submission'],
security: [
{
Bearer: []
Expand All @@ -48,7 +52,7 @@ POST.apiDoc = {
},
type: {
type: 'string',
enum: ['dataset']
enum: ['submission']
},
properties: {
title: 'Dataset properties',
Expand Down Expand Up @@ -89,7 +93,7 @@ POST.apiDoc = {
}
};

export function datasetIntake(): RequestHandler {
export function submissionIntake(): RequestHandler {
return async (req, res) => {
const sourceSystem = getKeycloakSource(req['keycloak_token']);

Expand All @@ -99,7 +103,7 @@ export function datasetIntake(): RequestHandler {
]);
}

const dataset = {
const submission = {
...req.body,
properties: { ...req.body.properties, additionalInformation: req.body.properties.additionalInformation }
};
Expand All @@ -113,21 +117,21 @@ export function datasetIntake(): RequestHandler {
const submissionService = new SubmissionService(connection);
const validationService = new ValidationService(connection);

// validate the dataset submission
if (!(await validationService.validateDatasetSubmission(dataset))) {
throw new HTTP400('Invalid dataset submission');
// validate the submission submission
if (!(await validationService.validateDatasetSubmission(submission))) {
throw new HTTP400('Invalid submission submission');
}

// insert the submission record
const response = await submissionService.insertSubmissionRecordWithPotentialConflict(id);

// insert each submission feature record
await submissionService.insertSubmissionFeatureRecords(response.submission_id, dataset.features);
await submissionService.insertSubmissionFeatureRecords(response.submission_id, submission.features);

await connection.commit();
res.status(200).json(response);
} catch (error) {
defaultLog.error({ label: 'datasetIntake', message: 'error', error });
defaultLog.error({ label: 'submissionIntake', message: 'error', error });
await connection.rollback();
throw error;
} finally {
Expand Down
Loading

0 comments on commit 6186468

Please sign in to comment.