Skip to content

Commit 3320f82

Browse files
committed
chore: test refactor and project cleanup
1 parent 1b17b90 commit 3320f82

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

handwritten/storage/test/resumable-upload.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ function mockAuthorizeRequest(
6868
return nock('https://oauth2.googleapis.com').post('/token').reply(code, data);
6969
}
7070

71-
/* TODO: UnSkip once the circular dependency is fixed. */
72-
describe.skip('resumable-upload', () => {
71+
describe('resumable-upload', () => {
7372
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7473
let upload: any;
7574
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -98,7 +97,7 @@ describe.skip('resumable-upload', () => {
9897
const keyFile = path.join(getDirName(), '../../../test/fixtures/keys.json');
9998

10099
before(() => {
101-
mockery.enable({useCleanCache: true, warnOnUnregistered: false});
100+
mockery.enable({useCleanCache: false, warnOnUnregistered: false});
102101
upload = require('../src/resumable-upload').upload;
103102
});
104103

@@ -1369,7 +1368,7 @@ describe.skip('resumable-upload', () => {
13691368
return {
13701369
status: 200,
13711370
data: {},
1372-
headers: {},
1371+
headers: new Headers(),
13731372
config: opts,
13741373
statusText: 'OK',
13751374
} as GaxiosResponse;
@@ -1427,6 +1426,10 @@ describe.skip('resumable-upload', () => {
14271426
const capturedReqOpts: GaxiosOptions[] = [];
14281427
requestCount = 0;
14291428

1429+
const totalChunks = isMultiChunk
1430+
? Math.ceil(data.byteLength / CHUNK_SIZE)
1431+
: 1;
1432+
14301433
uploadInstance.makeRequestStream = async (
14311434
requestOptions: GaxiosOptions,
14321435
) => {
@@ -1446,33 +1449,33 @@ describe.skip('resumable-upload', () => {
14461449

14471450
const serverCrc32c = expectedCrc32c || CALCULATED_CRC32C;
14481451
const serverMd5 = expectedMd5 || CALCULATED_MD5;
1449-
if (
1450-
isMultiChunk &&
1451-
requestCount < Math.ceil(DUMMY_CONTENT.byteLength / CHUNK_SIZE)
1452-
) {
1452+
if (isMultiChunk && requestCount < totalChunks) {
14531453
const lastByteReceived = requestCount * CHUNK_SIZE - 1;
14541454
return {
14551455
data: '',
14561456
status: RESUMABLE_INCOMPLETE_STATUS_CODE,
1457-
headers: {range: `bytes=0-${lastByteReceived}`},
1458-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1459-
} as any;
1460-
} else {
1461-
return {
1462-
status: 200,
1463-
data: {
1464-
crc32c: serverCrc32c,
1465-
md5Hash: serverMd5,
1466-
name: FILE,
1467-
bucket: BUCKET,
1468-
size: DUMMY_CONTENT.byteLength.toString(),
1457+
headers: {
1458+
range: `bytes=0-${lastByteReceived}`,
1459+
'Content-Length': '0',
14691460
},
1470-
headers: {},
1471-
config: {},
1472-
statusText: 'OK',
14731461
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14741462
} as any;
14751463
}
1464+
1465+
return {
1466+
status: 200,
1467+
data: {
1468+
crc32c: serverCrc32c,
1469+
md5Hash: serverMd5,
1470+
name: FILE,
1471+
bucket: BUCKET,
1472+
size: DUMMY_CONTENT.byteLength.toString(),
1473+
},
1474+
headers: new Headers(),
1475+
config: {},
1476+
statusText: 'OK',
1477+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1478+
} as any;
14761479
};
14771480

14781481
return new Promise((resolve, reject) => {
@@ -1584,19 +1587,23 @@ describe.skip('resumable-upload', () => {
15841587
const headers = reqOpts[0].headers as Record<string, any>;
15851588
assert.strictEqual(reqOpts.length, 2);
15861589

1587-
assert.strictEqual(headers['Content-Length'], CHUNK_SIZE);
1590+
assert.strictEqual(headers['Content-Length'], CHUNK_SIZE.toString());
15881591
assert.strictEqual(headers['X-Goog-Hash'], undefined);
15891592
});
15901593

15911594
it('should include X-Goog-Hash header ONLY on the final multi-chunk request', async () => {
15921595
const expectedHashHeader = `crc32c=${CALCULATED_CRC32C},md5=${CALCULATED_MD5}`;
15931596
const reqOpts = await performUpload(up, DUMMY_CONTENT, true);
15941597
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1595-
const headers = reqOpts[0].headers as Record<string, any>;
1598+
const headers = reqOpts[1].headers as any;
15961599
assert.strictEqual(reqOpts.length, 2);
15971600

1598-
assert.strictEqual(headers['Content-Length'], CHUNK_SIZE);
1599-
assert.equal(headers['X-Goog-Hash'], expectedHashHeader);
1601+
const xGoogHash =
1602+
typeof headers.get === 'function'
1603+
? headers.get('x-goog-hash')
1604+
: headers['X-Goog-Hash'];
1605+
assert.strictEqual(headers['Content-Length'], CHUNK_SIZE.toString());
1606+
assert.equal(xGoogHash, expectedHashHeader);
16001607
});
16011608
});
16021609
});

0 commit comments

Comments
 (0)