From 3a16c83697b32cf7d80bd6593a261f4e80793325 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Sun, 25 Sep 2022 17:30:07 +0500 Subject: [PATCH] test: AuthManager specs are updated/removed --- src/auth/spec/AuthManager.spec.ts | 76 ++++--------------------------- 1 file changed, 8 insertions(+), 68 deletions(-) diff --git a/src/auth/spec/AuthManager.spec.ts b/src/auth/spec/AuthManager.spec.ts index 763651d..46eb09e 100644 --- a/src/auth/spec/AuthManager.spec.ts +++ b/src/auth/spec/AuthManager.spec.ts @@ -101,46 +101,20 @@ describe('AuthManager', () => { loginForm: null }) ) - jest - .spyOn(authManager, 'logOut') - .mockImplementation(() => Promise.resolve(true)) + jest.spyOn(authManager, 'logOut') - jest - .spyOn(authManager, 'getNewLoginForm') - .mockImplementation(() => - Promise.resolve({ - name: 'test' - }) - ) - mockedAxios.post.mockImplementation(() => - Promise.resolve({ data: mockLoginSuccessResponse }) - ) + jest.spyOn(authManager, 'getNewLoginForm') + jest.spyOn(authManager, 'sendLoginRequest') const loginResponse = await authManager.logIn(userName, password) expect(loginResponse.isLoggedIn).toBeTruthy() expect(loginResponse.userName).toEqual(userName) - const loginParams = serialize({ - _service: 'default', - username: userName, - password, - name: 'test' - }) expect(authCallback).toHaveBeenCalledTimes(1) - expect(authManager.logOut).toHaveBeenCalledTimes(1) - expect(authManager['getNewLoginForm']).toHaveBeenCalledTimes(1) - expect(mockedAxios.post).toHaveBeenCalledWith( - `/SASLogon/login`, - loginParams, - { - withCredentials: true, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - Accept: '*/*' - } - } - ) + expect(authManager.logOut).toHaveBeenCalledTimes(0) + expect(authManager['getNewLoginForm']).toHaveBeenCalledTimes(0) + expect(authManager['sendLoginRequest']).toHaveBeenCalledTimes(0) expect(authCallback).toHaveBeenCalledTimes(1) }) @@ -567,43 +541,8 @@ describe('AuthManager', () => { ) }) - it('return session information when logged in - SAS9', async () => { - // username cannot have `-` and cannot be uppercased - const username = 'testusername' - const serverType = ServerType.Sas9 - const authManager = new AuthManager( - serverUrl, - serverType, - requestClient, - authCallback - ) - mockedAxios.get.mockImplementation(() => - Promise.resolve({ - data: `"title":"Log Off ${username}","url":"javascript: clearFrame(\"/SASStoredProcess/do?_action=logoff\")"' })` - }) - ) - - const response = await authManager.checkSession() - expect(response.isLoggedIn).toBeTruthy() - expect(response.userName).toEqual(username) - expect(mockedAxios.get).toHaveBeenNthCalledWith( - 1, - `http://test-server.com/SASStoredProcess`, - { - withCredentials: true, - responseType: 'text', - transformResponse: undefined, - headers: { - Accept: '*/*', - 'Content-Type': 'text/plain' - } - } - ) - }) - it('return session information when logged in - SAS9 - having full name in html', async () => { const fullname = 'FirstName LastName' - const username = 'firlas' const serverType = ServerType.Sas9 const authManager = new AuthManager( serverUrl, @@ -619,7 +558,8 @@ describe('AuthManager', () => { const response = await authManager.checkSession() expect(response.isLoggedIn).toBeTruthy() - expect(response.userName).toEqual(username) + expect(response.userName).toEqual('') + expect(response.userLongName).toEqual(fullname) expect(mockedAxios.get).toHaveBeenNthCalledWith( 1, `http://test-server.com/SASStoredProcess`,