Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BIOMAGE-2015] Removed dynamo references #399

Merged
merged 2 commits into from
Jul 25, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ properties:
description: |-
The cell set for preliminary selection of cells to compare.

This must be a valid UUID of a cell set as found in DynamoDB. All operations in `DifferentialExpression` will only consider cells that are found in this cell set.
This must be a valid UUID of a cell set as found in the DB. All operations in `DifferentialExpression` will only consider cells that are found in this cell set.

If not specified, no preliminary selection is done and the entire experiment is used as a basis for computation.
cellSet:
type: string
description: The first cell set differential expression is run on. This must be a valid UUID of a cell set as found in DynamoDB.
description: The first cell set differential expression is run on. This must be a valid UUID of a cell set as found in the DB.
compareWith:
type: string
description: |-
Expand Down
6 changes: 3 additions & 3 deletions src/sql/migrations/20220304184711_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ CREATE OR REPLACE FUNCTION public.delete_sample_file_if_orphan()
AS $function$
BEGIN
DELETE FROM sample_file
WHERE
WHERE
sample_file.id = OLD.sample_file_id AND
NOT EXISTS(
SELECT FROM sample_to_sample_file_map sf_map
SELECT FROM sample_to_sample_file_map sf_map
WHERE sf_map.sample_file_id = OLD.sample_file_id AND NOT OLD.sample_id = sf_map.sample_id
);
RETURN OLD;
Expand Down Expand Up @@ -41,7 +41,7 @@ const setupEnums = async (knex) => {
await knex.raw('CREATE TYPE sample_technology AS ENUM (\'10x\', \'rhapsody\');');
await knex.raw('CREATE TYPE sample_file_type AS ENUM (\'features10x\', \'barcodes10x\', \'matrix10x\', \'rhapsody\');');
await knex.raw(
'CREATE TYPE upload_status AS ENUM (\'uploaded\', \'uploading\', \'compressing\', \'uploadError\', \'fileNotFound\', \'fileReadError\', \'fileReadAborted\');',
'CREATE TYPE upload_status AS ENUM (\'invalidFormat\', \'uploaded\', \'uploading\', \'compressing\', \'uploadError\', \'fileNotFound\', \'fileReadError\', \'fileReadAborted\');',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do this change here, you need to add a new migration to add invalidFormat to the upload_status

);
await knex.raw('CREATE TYPE access_role AS ENUM (\'owner\', \'admin\', \'explorer\', \'viewer\');');
};
Expand Down
74 changes: 0 additions & 74 deletions src/utils/dynamoDb.js

This file was deleted.

109 changes: 0 additions & 109 deletions src/utils/safeBatchGetItem.js

This file was deleted.

153 changes: 0 additions & 153 deletions tests/test-utils/mockAWSServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,150 +2,6 @@ const AWSMock = require('aws-sdk-mock');
const _ = require('lodash');
const AWS = require('../../src/utils/requireAWS');

const marshallTableResults = (entries) => entries.map(
(entry) => AWS.DynamoDB.Converter.marshall(entry),
);

const mockDynamoGetItem = (payload = {}, error = null) => {
const dynamodbData = {
Item: AWS.DynamoDB.Converter.marshall(payload),
};

const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB', 'getItem', (params, callback) => {
fnSpy(params);
callback(error, dynamodbData);
});
return fnSpy;
};

const mockDynamoBatchGetItem = (response = {}, error = null) => {
const dynamodbData = {
Responses: _.mapValues(response.Responses, marshallTableResults),
};

const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB', 'batchGetItem', (params, callback) => {
fnSpy(params);
callback(error, dynamodbData);
});
return fnSpy;
};

const mockDynamoDeleteItem = (payload = {}, error = null) => {
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB', 'deleteItem', (params, callback) => {
fnSpy(params);
callback(error, payload);
});
return fnSpy;
};

const mockDynamoQuery = (payload = [], error = null) => {
const payloadToReturn = !Array.isArray(payload) ? [payload] : payload;

const dynamodbData = {
Items: payloadToReturn.map((entry) => AWS.DynamoDB.Converter.marshall(entry)),
};
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB', 'query', (params, callback) => {
fnSpy(params);
callback(error, dynamodbData);
});
return fnSpy;
};

const mockDocClientPutItem = (payload = {}, error = null) => {
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB.DocumentClient', 'put', (params, callback) => {
fnSpy(params);
callback(error, payload);
});
return fnSpy;
};

const mockDocClientQuery = (payload = [], error = null) => {
const payloadToReturn = !Array.isArray(payload) ? [payload] : payload;

const dynamodbData = {
Items: payloadToReturn,
};
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB.DocumentClient', 'query', (params, callback) => {
fnSpy(params);
callback(error, dynamodbData);
});
return fnSpy;
};

const mockDocClientBatchWrite = (payload = {}, error = null) => {
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB.DocumentClient', 'batchWrite', (params, callback) => {
fnSpy(params);
callback(error, payload);
});
return fnSpy;
};

/**
* Mocks the scan operation in dynamodb
*
* @param {Array} payloadPages the payloads to return in each scan operation in order
* (for pagination, also returns the LastEvaluatedKey if it has more than one page)
* @returns An object containing descriptions of projects.
*/
const mockDynamoScan = (payloadPages, error = null) => {
const pagesLength = payloadPages.length;
const dynamodbDbDataPages = payloadPages.map((page, i) => {
const isLastPage = pagesLength === i + 1;

const lastKey = isLastPage ? null : AWS.DynamoDB.Converter.marshall(_.first(payloadPages[i + 1]));
const items = page.map((entry) => AWS.DynamoDB.Converter.marshall(entry));

const response = { Items: items };

if (!isLastPage) {
response.LastEvaluatedKey = lastKey;
}

return response;
});

const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);

let callNumber = 0;
AWSMock.mock('DynamoDB', 'scan', (params, callback) => {
fnSpy(params);

callback(error, dynamodbDbDataPages[callNumber]);

callNumber += 1;
});

return fnSpy;
};

const mockDynamoUpdateItem = (payload = {}, error = null) => {
const dynamodbData = {
Attributes: AWS.DynamoDB.Converter.marshall(payload),
};
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
AWSMock.mock('DynamoDB', 'updateItem', (params, callback) => {
fnSpy(params);
callback(error, dynamodbData);
});
return fnSpy;
};

const mockS3GetObject = (payload = {}, error = null) => {
const fnSpy = jest.fn((x) => x);
AWSMock.setSDKInstance(AWS);
Expand Down Expand Up @@ -213,19 +69,10 @@ const mockS3GetSignedUrl = (payload = {}, error = null) => {
};

module.exports = {
mockDynamoGetItem,
mockDynamoBatchGetItem,
mockDynamoQuery,
mockDynamoScan,
mockDynamoUpdateItem,
mockDynamoDeleteItem,
mockS3GetObject,
mockS3PutObject,
mockS3DeleteObject,
mockS3DeleteObjects,
mockS3GetSignedUrl,
mockS3GetObjectTagging,
mockDocClientQuery,
mockDocClientBatchWrite,
mockDocClientPutItem,
};
Loading