Skip to content

Commit

Permalink
Update zlib mock implementation to work with Axios 1.6.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Grayson committed Dec 29, 2023
1 parent b9657aa commit 48b3d2d
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions backend/src/tasks/test/cve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
Vulnerability
} from '../../models';
import * as nock from 'nock';
import * as zlib from 'zlib';

const unzipSyncSpy = jest.spyOn(zlib, 'unzipSync');

jest.mock('child_process', () => ({
spawnSync: () => null,
Expand All @@ -26,41 +29,6 @@ jest.mock('fs', () => ({
}
}));

const realZlib = jest.requireActual('zlib');
jest.mock('zlib', () => ({
...realZlib,
unzipSync: (contents) =>
Buffer.from(
JSON.stringify({
CVE_Items: [
{
cve: {
CVE_data_meta: { ID: 'CVE-2019-10866' },
description: {
description_data: [
{
lang: 'en',
value: 'Test description'
}
]
},
references: {
reference_data: [
{
url: 'https://example.com',
name: 'https://example.com',
refsource: 'CONFIRM',
tags: ['Patch', 'Vendor Advisory']
}
]
}
}
}
]
})
)
}));

jest.setTimeout(30000);

const RealDate = Date;
Expand All @@ -69,6 +37,37 @@ describe('cve', () => {
let connection;
beforeAll(async () => {
connection = await connectToDatabase();
unzipSyncSpy.mockImplementation((contents) =>
Buffer.from(
JSON.stringify({
CVE_Items: [
{
cve: {
CVE_data_meta: { ID: 'CVE-2019-10866' },
description: {
description_data: [
{
lang: 'en',
value: 'Test description'
}
]
},
references: {
reference_data: [
{
url: 'https://example.com',
name: 'https://example.com',
refsource: 'CONFIRM',
tags: ['Patch', 'Vendor Advisory']
}
]
}
}
}
]
})
)
);
});
beforeEach(() => {
global.Date.now = jest.fn(() => new Date('2019-04-22T10:20:30Z').getTime());
Expand All @@ -78,6 +77,7 @@ describe('cve', () => {
global.Date = RealDate;
});
afterAll(async () => {
unzipSyncSpy.mockRestore();
await connection.close();
nock.cleanAll();
});
Expand Down

0 comments on commit 48b3d2d

Please sign in to comment.