Skip to content

Commit

Permalink
Lint fix and unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
srpiatt committed Jan 18, 2024
1 parent 442642a commit 5e957c5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,83 @@ describe('fetchOpenData', () => {
sha: 'abc2',
};

const whitelistStudy = {
name: 'Study 3',
description: 'Example study 3',
tags: ['other-tag'],
resources: [
{
description: 'Description for Study 3',
arn: 'arn:aws:s3:::study3',
region: 'us-east-1',
type: 'S3 Bucket',
},
],
id: 'study-3',
sha: 'abc2',
};

it('has invalid study (Invalid ARN)', async () => {
const fileUrls = ['firstFileUrl'];
const requiredTags = ['genetic'];
const studyWhitelist = [];
const fetchFile = jest.fn();
fetchFile.mockReturnValueOnce(invalidStudy);

const result = await fetchOpenData({ fileUrls, requiredTags, log: consoleLogger, fetchFile });
const result = await fetchOpenData({ fileUrls, requiredTags, studyWhitelist, log: consoleLogger, fetchFile });
expect(result).toEqual([]);
});

it('has one valid study', async () => {
const fileUrls = ['firstFileUrl'];
const requiredTags = ['genetic'];
const studyWhitelist = [];
const fetchFile = jest.fn();
fetchFile.mockReturnValueOnce(validStudy);

const result = await fetchOpenData({ fileUrls, requiredTags, log: consoleLogger, fetchFile });
const result = await fetchOpenData({ fileUrls, requiredTags, studyWhitelist, log: consoleLogger, fetchFile });
expect(result).toEqual([validStudyOpenData]);
});

it('has one valid study and one invalid study (Invalid ARN)', async () => {
const fileUrls = ['firstFileUrl'];
const fileUrls = ['firstFileUrl', 'fileUrl2'];
const requiredTags = ['genetic'];
const studyWhitelist = [];
const fetchFile = jest.fn();
fetchFile.mockReturnValueOnce(validStudy).mockReturnValueOnce(invalidStudy);

const result = await fetchOpenData({ fileUrls, requiredTags, log: consoleLogger, fetchFile });
const result = await fetchOpenData({ fileUrls, requiredTags, studyWhitelist, log: consoleLogger, fetchFile });
expect(result).toEqual([validStudyOpenData]);
});

it('has whitelisted study is included', async () => {
const fileUrls = ['firstFileUrl', 'fileUrl2', 'fileUrl3'];
const requiredTags = ['genetic'];
const studyWhitelist = ['study-3'];
const fetchFile = jest.fn();
fetchFile
.mockReturnValueOnce(validStudy)
.mockReturnValueOnce(invalidStudy)
.mockReturnValueOnce(whitelistStudy);

const result = await fetchOpenData({ fileUrls, requiredTags, studyWhitelist, log: consoleLogger, fetchFile });
expect(result).toEqual([
validStudyOpenData,
{
description: 'Example study 3',
id: 'study-3',
name: 'Study 3',
resources: [
{
arn: 'arn:aws:s3:::study3',
description: 'Description for Study 3',
region: 'us-east-1',
type: 'S3 Bucket',
},
],
sha: 'abc2',
tags: ['other-tag'],
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ const fetchOpenData = async ({ fileUrls, requiredTags, studyWhitelist, log, fetc
const validS3Arn = new RegExp(/^arn:aws:s3:.*:.*:.+$/);
const filtered = metadata.filter(({ id, tags, resources }) => {
return (
(
studyWhitelist.includes(id) ||
requiredTags.some(filterTag => tags.includes(filterTag))
) && resources.every(resource => {
(studyWhitelist.includes(id) || requiredTags.some(filterTag => tags.includes(filterTag))) &&
resources.every(resource => {
return resource.type === 'S3 Bucket' && validS3Arn.test(resource.arn);
})
);
Expand Down Expand Up @@ -246,7 +244,7 @@ const fetchAndSaveOpenData = async (fetchDatasetFiles, scrape, log, fetchFile, b
requiredTags: scrape.filterTags,
studyWhitelist: scrape.studyWhitelist,
log,
fetchFile
fetchFile,
});

const simplifiedStudyData = openData.map(basicProjection);
Expand Down

0 comments on commit 5e957c5

Please sign in to comment.