From 99e57e6f3b9a54735563be41fad81b4303763930 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Fri, 7 Jan 2022 12:43:54 +0200 Subject: [PATCH] Revert "tests: Add API and Session tests regarding parallel calls" This reverts commit 2a2c36729ff22a67971096d3e38dd580f3295a14. --- tests/unit/APITest.js | 50 ------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 tests/unit/APITest.js diff --git a/tests/unit/APITest.js b/tests/unit/APITest.js deleted file mode 100644 index d5d3785d38c6..000000000000 --- a/tests/unit/APITest.js +++ /dev/null @@ -1,50 +0,0 @@ -import _ from 'underscore'; -import * as API from '../../src/libs/API'; -import * as Network from '../../src/libs/Network'; -import HttpUtils from '../../src/libs/HttpUtils'; -import waitForPromisesToResolve from '../utils/waitForPromisesToResolve'; -import CONFIG from '../../src/CONFIG'; - -Network.setIsReady(true); - -test('Authenticate should not make parallel auth requests', () => { - // We're setting up a basic case where all requests succeed - const xhr = jest.spyOn(HttpUtils, 'xhr').mockResolvedValue({jsonCode: 200}); - - // Given multiple auth calls happening at the same time - _.each(_.range(5), () => API.Authenticate({ - partnerName: CONFIG.EXPENSIFY.PARTNER_NAME, - partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, - partnerUserID: 'testUserId', - partnerUserSecret: 'testUserSecret', - })); - - // Then a single auth request should be made - return waitForPromisesToResolve() - .then(() => { - expect(xhr).toHaveBeenCalledTimes(1); - }); -}); - -test('Multiple Authenticate calls should be resolved with the same value', () => { - // A mock where only the first xhr responds with 200 and all the rest 999 - const mockResponse = {jsonCode: 200}; - jest.spyOn(HttpUtils, 'xhr') - .mockResolvedValueOnce(mockResponse) - .mockResolvedValue({jsonCode: 999}); - - // Given multiple auth calls happening at the same time - const tasks = _.map(_.range(5), () => API.Authenticate({ - partnerName: CONFIG.EXPENSIFY.PARTNER_NAME, - partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD, - partnerUserID: 'testUserId', - partnerUserSecret: 'testUserSecret', - })); - - // Then they all should be resolved from the first response - return Promise.all(tasks) - .then((results) => { - expect(_.size(results)).toEqual(5); - _.each(results, response => expect(response).toBe(mockResponse)); - }); -});