Skip to content

Commit 3485243

Browse files
committed
test: minor test fixes and cleanup
1 parent c95d520 commit 3485243

5 files changed

Lines changed: 15 additions & 19 deletions

File tree

test/__mocks__/parse-duration.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/expiration.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TestStorage } from './shared';
22

3-
describe('expiration shorthand', () => {
3+
describe('expiration', () => {
44
it('should normalize string shorthand to ExpirationOptions', () => {
55
const s = new TestStorage({ expiration: '6h' });
66
expect(s.config.expiration).toBeDefined();

test/gcs-storage.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import {
1010
} from '../packages/gcs/src';
1111
import { authRequest, deepClone, metafile, storageOptions, testfile } from './shared';
1212

13-
const mockFetch = jest.fn();
14-
global.fetch = mockFetch;
15-
1613
const mockAuthRequest = jest.fn();
1714
jest.mock('google-auth-library', () => ({
1815
GoogleAuth: jest.fn(() => ({ request: mockAuthRequest }))
1916
}));
2017

2118
describe('GCStorage', () => {
19+
const mockFetch = jest.fn();
20+
const originalFetch = global.fetch;
2221
jest.useFakeTimers().setSystemTime(new Date('2022-02-02'));
2322
let storage: GCStorage;
2423
const uri = 'http://api.com?upload_id=123456789';
@@ -30,10 +29,16 @@ describe('GCStorage', () => {
3029

3130
beforeEach(async () => {
3231
jest.clearAllMocks();
32+
global.fetch = mockFetch;
3333
mockAuthRequest.mockResolvedValueOnce({ bucket: 'ok' });
3434
storage = new GCStorage({ ...storageOptions, bucket: 'test-bucket' });
3535
});
3636

37+
afterAll(() => {
38+
jest.useRealTimers();
39+
global.fetch = originalFetch;
40+
});
41+
3742
describe('initialization', () => {
3843
it('should set defaults', () => {
3944
mockAuthRequest.mockResolvedValueOnce({ bucket: 'ok' });
@@ -46,9 +51,7 @@ describe('GCStorage', () => {
4651
describe('.create()', () => {
4752
it('should request api and set status and uri', async () => {
4853
mockAuthRequest.mockRejectedValueOnce({ code: 404, detail: 'meta not found' }); // getMeta
49-
mockAuthRequest.mockResolvedValueOnce({
50-
headers: new Headers({ location: uri })
51-
}); //
54+
mockAuthRequest.mockResolvedValueOnce({ headers: new Headers({ location: uri }) });
5255
mockAuthRequest.mockResolvedValueOnce('_saveOk');
5356
const gcsFile = await storage.create(req, metafile);
5457
expect(gcsFile).toMatchSnapshot();

test/s3-storage.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('S3Storage', () => {
129129
});
130130
});
131131

132-
describe('delete()', () => {
132+
describe('.delete()', () => {
133133
it('should set status', async () => {
134134
s3Mock.on(HeadObjectCommand).resolves(metafileResponse);
135135
s3Mock.on(DeleteObjectCommand).resolves({});
@@ -200,7 +200,7 @@ describe('S3PresignedStorage', () => {
200200
});
201201
});
202202

203-
describe('update', () => {
203+
describe('.update()', () => {
204204
it('should add partsUrls', async () => {
205205
s3Mock.on(HeadObjectCommand).resolves(metafileResponse);
206206
s3Mock.on(ListPartsCommand).resolves({ Parts: [] });

test/storage.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ describe('BaseStorage', () => {
4040

4141
it('should check if not expired', async () => {
4242
storage = new TestStorage({ expiration: { maxAge: '1h' } });
43-
expect(storage.checkIfExpired({ ...metafile, expiredAt: Date.now() + 1000 })).toBeTruthy();
43+
expect(
44+
await storage.checkIfExpired({ ...metafile, expiredAt: Date.now() + 1000 })
45+
).toBeTruthy();
4446
});
4547

4648
it('should save meta and update cache', async () => {

0 commit comments

Comments
 (0)