From 162173b49fdb26ca705051d90fa2197d967f9a54 Mon Sep 17 00:00:00 2001 From: Jonathan Lui Date: Fri, 1 May 2020 16:06:34 -0700 Subject: [PATCH] fix tests --- test/file.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/test/file.ts b/test/file.ts index c5d00121c..963d58673 100644 --- a/test/file.ts +++ b/test/file.ts @@ -2822,14 +2822,15 @@ describe('File', () => { fakeTimer.restore(); }); + const fieldsToConditions = (fields: object) => + Object.entries(fields).map(([k, v]) => ({[k]: v})); + it('should create a signed policy', done => { CONFIG.fields = { 'x-goog-meta-foo': 'bar', }; - const fields = { - ...CONFIG.fields, - bucket: BUCKET.name, + const requiredFields = { key: file.name, 'x-goog-date': '20200101T000000Z', 'x-goog-credential': `${CLIENT_EMAIL}/20200101/auto/storage/goog4_request`, @@ -2837,9 +2838,11 @@ describe('File', () => { }; const policy = { - conditions: Object.entries(fields).map(([key, value]) => ({ - [key]: value, - })), + conditions: [ + ...fieldsToConditions(CONFIG.fields), + {bucket: BUCKET.name}, + ...fieldsToConditions(requiredFields), + ], expiration: dateFormat.format( new Date(CONFIG.expires), 'YYYY-MM-DD[T]HH:mm:ss[Z]', @@ -2852,6 +2855,12 @@ describe('File', () => { const EXPECTED_SIGNATURE = Buffer.from(SIGNATURE, 'base64').toString( 'hex' ); + const EXPECTED_FIELDS = { + ...CONFIG.fields, + ...requiredFields, + 'x-goog-signature': EXPECTED_SIGNATURE, + policy: EXPECTED_POLICY, + }; // eslint-disable-next-line @typescript-eslint/no-explicit-any file.generateSignedPostPolicyV4( @@ -2860,11 +2869,7 @@ describe('File', () => { assert.ifError(err); assert(res.url, `${STORAGE_POST_POLICY_BASE_URL}/${BUCKET.name}`); - assert.deepStrictEqual(res.fields, { - ...fields, - 'x-goog-signature': EXPECTED_SIGNATURE, - policy: EXPECTED_POLICY, - }); + assert.deepStrictEqual(res.fields, EXPECTED_FIELDS); const signStub = BUCKET.storage.authClient.sign; assert.deepStrictEqual(