From 263df53dcf82f10558a6c8d014c193adfe85fba9 Mon Sep 17 00:00:00 2001 From: Salakar Date: Sun, 6 May 2018 13:52:56 +0100 Subject: [PATCH] [tests][functions] added HttpsError tests --- bridge/e2e/functions/functions.e2e.js | 126 +++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/bridge/e2e/functions/functions.e2e.js b/bridge/e2e/functions/functions.e2e.js index e72757a2..d98aecac 100644 --- a/bridge/e2e/functions/functions.e2e.js +++ b/bridge/e2e/functions/functions.e2e.js @@ -73,6 +73,130 @@ describe('functions()', () => { }); describe('HttpsError', () => { - // todo + it('errors return instance of HttpsError', async () => { + const functionRunner = firebase.functions().httpsCallable('runTest'); + try { + await functionRunner({}); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + should.equal(e.details, null); + e.code.should.equal('invalid-argument'); + e.message.should.equal('Invalid test requested.'); + } + + return Promise.resolve(); + }); + + it('HttpsError.details -> allows returning complex data', async () => { + let type = 'advancedObject'; + let inputData = TEST_DATA[type]; + const functionRunner = firebase.functions().httpsCallable('runTest'); + try { + await functionRunner({ + type, + inputData, + asError: true, + }); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + should.deepEqual(e.details, inputData); + e.code.should.equal('cancelled'); + e.message.should.equal( + 'Response data was requested to be sent as part of an Error payload, so here we are!' + ); + } + + type = 'advancedArray'; + inputData = TEST_DATA[type]; + try { + await functionRunner({ + type, + inputData, + asError: true, + }); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + should.deepEqual(e.details, inputData); + e.code.should.equal('cancelled'); + e.message.should.equal( + 'Response data was requested to be sent as part of an Error payload, so here we are!' + ); + } + + return Promise.resolve(); + }); + + it('HttpsError.details -> allows returning primitives', async () => { + let type = 'number'; + let inputData = TEST_DATA[type]; + const functionRunner = firebase.functions().httpsCallable('runTest'); + try { + await functionRunner({ + type, + inputData, + asError: true, + }); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + e.code.should.equal('cancelled'); + e.message.should.equal( + 'Response data was requested to be sent as part of an Error payload, so here we are!' + ); + should.deepEqual(e.details, inputData); + } + + type = 'string'; + inputData = TEST_DATA[type]; + try { + await functionRunner({ + type, + inputData, + asError: true, + }); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + should.deepEqual(e.details, inputData); + e.code.should.equal('cancelled'); + e.message.should.equal( + 'Response data was requested to be sent as part of an Error payload, so here we are!' + ); + } + + type = 'boolean'; + inputData = TEST_DATA[type]; + try { + await functionRunner({ + type, + inputData, + asError: true, + }); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + should.deepEqual(e.details, inputData); + e.code.should.equal('cancelled'); + e.message.should.equal( + 'Response data was requested to be sent as part of an Error payload, so here we are!' + ); + } + + type = 'null'; + inputData = TEST_DATA[type]; + try { + await functionRunner({ + type, + inputData, + asError: true, + }); + return Promise.reject(new Error('Function did not reject with error.')); + } catch (e) { + should.deepEqual(e.details, inputData); + e.code.should.equal('cancelled'); + e.message.should.equal( + 'Response data was requested to be sent as part of an Error payload, so here we are!' + ); + } + + return Promise.resolve(); + }); }); });