Skip to content

Commit

Permalink
adding test to ensure .zip validation does not error out with non con…
Browse files Browse the repository at this point in the history
…tent-types of zip or .zip file extensions
  • Loading branch information
shaselton-usds committed Jan 8, 2024
1 parent 5a1fcc8 commit d927f59
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/DownloadManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@ describe('DownloadManager', () => {
expect(downloadedData).toEqual(simpleData);
});

it('should write a json file within a zip when the response has content type application/x-zip-compressed and the url ends with .zip', async () => {
const simpleData = fs.readJsonSync(
path.join(__dirname, 'fixtures', 'simpleData.json'),
'utf-8'
);
const simpleZip = fs.readFileSync(path.join(__dirname, 'fixtures', 'simpleZip.zip'));
nock('http://example.org')
.get('/data.zip')
.reply(200, simpleZip, { 'content-type': 'application/x-zip-compressed' });
const dataPath = (await downloadManager.downloadDataFile(
'http://example.org/data.zip'
)) as string;
expect(dataPath).toBeString();
expect(fs.existsSync(dataPath));
const downloadedData = fs.readJsonSync(dataPath, 'utf-8');
expect(downloadedData).toEqual(simpleData);
});

it('should write a json file within a zip when the response has content type application/octet-stream and the url ends with .zip followed by a query string', async () => {
const simpleData = fs.readJsonSync(
path.join(__dirname, 'fixtures', 'simpleData.json'),
Expand Down

0 comments on commit d927f59

Please sign in to comment.