Skip to content

Commit

Permalink
fix tests / pr clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
KjartanE committed Dec 4, 2023
1 parent 09739f9 commit 59e61dd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion api/src/database/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ describe('db', () => {
db.getServiceAccountDBConnection(SOURCE_SYSTEM['SIMS-SVC-4464']);

expect(getDBConnectionStub).to.have.been.calledWith({
preferred_username: `service-account-${SOURCE_SYSTEM['SIMS-SVC-4464']}@${SYSTEM_IDENTITY_SOURCE.SYSTEM}`,
preferred_username: `service-account-${SOURCE_SYSTEM['SIMS-SVC-4464']}`,
identity_provider: SYSTEM_IDENTITY_SOURCE.SYSTEM
});

Expand Down
9 changes: 1 addition & 8 deletions api/src/paths/dataset/intake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ POST.apiDoc = {
required: ['id', 'type', 'properties'],
properties: {
id: {
title: 'Unique id of the observation',
title: 'feature id',
type: 'string'
},
type: {
Expand Down Expand Up @@ -147,13 +147,6 @@ export function datasetIntake(): RequestHandler {
// insert each submission feature record
await submissionService.insertSubmissionFeatureRecords(response.submission_id, dataset.features);

Check warning on line 148 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L148

Added line #L148 was not covered by tests

// await submissionService.insertSubmissionStatusAndMessage(
// response.submission_id,
// SUBMISSION_STATUS_TYPE.PUBLISHED,
// SUBMISSION_MESSAGE_TYPE.NOTICE,
// additionalInformation
// );

await connection.commit();
res.status(200).json(response);

Check warning on line 151 in api/src/paths/dataset/intake.ts

View check run for this annotation

Codecov / codecov/patch

api/src/paths/dataset/intake.ts#L150-L151

Added lines #L150 - L151 were not covered by tests
} catch (error) {
Expand Down
10 changes: 2 additions & 8 deletions api/src/repositories/submission-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,7 @@ describe('SubmissionRepository', () => {

const submissionRepository = new SubmissionRepository(mockDBConnection);

const response = await submissionRepository.insertSubmissionRecordWithPotentialConflict({
uuid: 'aaaa',
source_transform_id: 1
});
const response = await submissionRepository.insertSubmissionRecordWithPotentialConflict('aaaa');

expect(response).to.eql({
uuid: 'aaaa',
Expand All @@ -510,10 +507,7 @@ describe('SubmissionRepository', () => {
const submissionRepository = new SubmissionRepository(mockDBConnection);

try {
await submissionRepository.insertSubmissionRecordWithPotentialConflict({
uuid: 'bbbb',
source_transform_id: 3
});
await submissionRepository.insertSubmissionRecordWithPotentialConflict('aaaa');
expect.fail();
} catch (actualError) {
expect((actualError as ApiExecuteSQLError).message).to.equal('Failed to get or insert submission record');
Expand Down
1 change: 0 additions & 1 deletion api/src/repositories/submission-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@ export class SubmissionRepository extends BaseRepository {
* @memberof SubmissionRepository
*/
async getHandleBarsTemplateByDatasetId(datasetId: string): Promise<IHandlebarsTemplates> {

Check warning on line 988 in api/src/repositories/submission-repository.ts

View workflow job for this annotation

GitHub Actions / Running Linter and Formatter

'datasetId' is defined but never used
console.log('datasetId', datasetId);
return {
header: simsHandlebarsTemplate_HEADER,
details: simsHandlebarsTemplate_DETAILS
Expand Down
22 changes: 9 additions & 13 deletions api/src/services/artifact-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import sinonChai from 'sinon-chai';
import { HTTPError } from '../errors/http-error';
import { Artifact, ArtifactMetadata, ArtifactRepository } from '../repositories/artifact-repository';
import { SecurityRepository } from '../repositories/security-repository';
import { ISourceTransformModel } from '../repositories/submission-repository';
import * as file_utils from '../utils/file-utils';
import { getMockDBConnection } from '../__mocks__/db';
import { ArtifactService } from './artifact-service';
Expand Down Expand Up @@ -95,9 +94,9 @@ describe('ArtifactService', () => {
const mockDBConnection = getMockDBConnection({ systemUserId: () => 20 });
const artifactService = new ArtifactService(mockDBConnection);

const transformRecordStub = sinon
.stub(SubmissionService.prototype, 'getSourceTransformRecordBySystemUserId')
.resolves({ source_transform_id: 60 } as unknown as ISourceTransformModel);
// const transformRecordStub = sinon
// .stub(SubmissionService.prototype, 'getSourceTransformRecordBySystemUserId')
// .resolves({ source_transform_id: 60 } as unknown as ISourceTransformModel);

// const getOrInsertSubmissionRecordStub =
sinon
Expand All @@ -115,7 +114,7 @@ describe('ArtifactService', () => {
await artifactService.uploadAndPersistArtifact(mockDataPackageId, mockArtifactMetadata, mockFileUuid, mockFile);
expect.fail();
} catch (actualError) {
expect(transformRecordStub).to.be.calledWith(20);
// expect(transformRecordStub).to.be.calledWith(20);
expect((actualError as HTTPError).message).to.equal('Test upload failed');
expect(insertRecordStub).to.not.be.called;
}
Expand All @@ -125,9 +124,9 @@ describe('ArtifactService', () => {
const mockDBConnection = getMockDBConnection({ systemUserId: () => 20 });
const artifactService = new ArtifactService(mockDBConnection);

const transformRecordStub = sinon
.stub(SubmissionService.prototype, 'getSourceTransformRecordBySystemUserId')
.resolves({ source_transform_id: 60 } as unknown as ISourceTransformModel);
// const transformRecordStub = sinon
// .stub(SubmissionService.prototype, 'getSourceTransformRecordBySystemUserId')
// .resolves({ source_transform_id: 60 } as unknown as ISourceTransformModel);

const insertSubmissionRecordWithPotentialConflictStub = sinon
.stub(SubmissionService.prototype, 'insertSubmissionRecordWithPotentialConflict')
Expand All @@ -145,12 +144,9 @@ describe('ArtifactService', () => {
await artifactService.uploadAndPersistArtifact(mockDataPackageId, mockArtifactMetadata, mockFileUuid, mockFile);
expect.fail();
} catch (actualError) {
expect(transformRecordStub).to.be.calledWith(20);
// expect(transformRecordStub).to.be.calledWith(20);

expect(insertSubmissionRecordWithPotentialConflictStub).to.be.calledWith({
source_transform_id: 60,
uuid: mockDataPackageId
});
expect(insertSubmissionRecordWithPotentialConflictStub).to.be.calledWith(mockDataPackageId);
expect(getNextArtifactIdsStub).to.be.calledWith();
expect(uploadStub).to.be.calledWith(
mockFile,
Expand Down
5 changes: 1 addition & 4 deletions api/src/services/submission-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ describe('SubmissionService', () => {
.stub(SubmissionRepository.prototype, 'insertSubmissionRecordWithPotentialConflict')
.resolves({ submission_id: 1 });

const response = await submissionService.insertSubmissionRecordWithPotentialConflict({
uuid: '',
source_transform_id: 1
});
const response = await submissionService.insertSubmissionRecordWithPotentialConflict('aaaa');

expect(repo).to.be.calledOnce;
expect(response).to.be.eql({ submission_id: 1 });
Expand Down
12 changes: 6 additions & 6 deletions api/src/services/validation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ export class ValidationService extends DBService {
* @memberof ValidationService
*/
async validateDatasetSubmission(dataset: IDatasetSubmission): Promise<boolean> {
// Validate given data[property] is of type [type]
const validateProperty = (data: any, property: string | number, type: string) => {
console.log('data', data);
console.log('property', property);
console.log('type', type);

const jsonData = data[0][property];

Check warning on line 32 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L31-L32

Added lines #L31 - L32 were not covered by tests

// check if property is 'features' and jsonData is undefined
if (property === 'features' && jsonData === undefined) {
return;

Check warning on line 36 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L36

Added line #L36 was not covered by tests
}

console.log(`---Validation of ${jsonData} as ${type}---`);

// check if jsonData is an array
if (type === 'array') {
if (!Array.isArray(jsonData)) {
throw new Error(`Invalid dataset submission: ${jsonData} must be a ${type}`);

Check warning on line 42 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L42

Added line #L42 was not covered by tests
}

// recursively validate each feature in the array
jsonData.forEach((element: any) => {
this.validateDatasetSubmission(element);

Check warning on line 47 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L46-L47

Added lines #L46 - L47 were not covered by tests
});
Expand All @@ -64,6 +62,7 @@ export class ValidationService extends DBService {
}
};

// callback function for json-schema-traverse
const validationCallback = (

Check warning on line 66 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L66

Added line #L66 was not covered by tests
schema: traverse.SchemaObject,
json_pointer: string,
Expand All @@ -83,6 +82,7 @@ export class ValidationService extends DBService {
parentJsonPtr = parentJsonPtr.replace('/properties', '');

Check warning on line 82 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L82

Added line #L82 was not covered by tests
}

// if the parent is features, then we need to add a wildcard to the end of the json pointer
if (parentJsonPtr === 'features') {
parentJsonPtr += '.*';

Check warning on line 87 in api/src/services/validation-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/validation-service.ts#L87

Added line #L87 was not covered by tests
}
Expand Down

0 comments on commit 59e61dd

Please sign in to comment.