diff --git a/test/unit/core/plugins/auth/actions.js b/test/unit/core/plugins/auth/actions.js index 349f19ee..84e0a53d 100644 --- a/test/unit/core/plugins/auth/actions.js +++ b/test/unit/core/plugins/auth/actions.js @@ -1,7 +1,7 @@ import { Map } from "immutable" import { authorizeRequest, - authorizeAccessCodeWithFormParams, + authorizeAccessCodeWithFormParams, authorizeWithPersistOption, authorizeOauth2WithPersistOption, logoutWithPersistOption, @@ -57,7 +57,7 @@ describe("auth plugin - actions", () => { }, "http://specs/authorize" ], - ].forEach(([{oas3, server, effectiveServer, scheme, host, url}, expectedFetchUrl]) => { + ].forEach(([{ oas3, server, effectiveServer, scheme, host, url }, expectedFetchUrl]) => { it("should resolve authorization endpoint against the server URL", () => { // Given @@ -72,6 +72,9 @@ describe("auth plugin - actions", () => { authSelectors: { getConfigs: () => ({}) }, + errActions: { + newAuthErr: () => ({}) + }, oas3Selectors: { selectedServer: () => server, serverEffectiveValue: () => effectiveServer || server @@ -89,7 +92,7 @@ describe("auth plugin - actions", () => { // Then expect(system.fn.fetch.mock.calls.length).toEqual(1) - expect(system.fn.fetch.mock.calls[0][0]).toEqual(expect.objectContaining({url: expectedFetchUrl})) + expect(system.fn.fetch.mock.calls[0][0]).toEqual(expect.objectContaining({ url: expectedFetchUrl })) }) }) @@ -111,6 +114,9 @@ describe("auth plugin - actions", () => { } }) }, + errActions: { + newAuthErr: () => ({}) + }, specSelectors: { isOAS3: () => false, operationScheme: () => "https", @@ -139,6 +145,9 @@ describe("auth plugin - actions", () => { fn: { fetch: jest.fn().mockImplementation(() => Promise.resolve()) }, + errActions: { + newAuthErr: () => ({}) + }, getConfigs: () => ({}), authSelectors: { getConfigs: () => ({ @@ -167,7 +176,7 @@ describe("auth plugin - actions", () => { }) }) - describe("tokenRequest", function() { + describe("tokenRequest", function () { it("should send the code verifier when set", () => { const data = { auth: { @@ -200,17 +209,17 @@ describe("auth plugin - actions", () => { const data = { "api_key": {} } - const system = { + const system = { getConfigs: () => ({}), authActions: { - authorize: jest.fn(()=>{}), - persistAuthorizationIfNeeded: jest.fn(()=>{}) + authorize: jest.fn(() => { }), + persistAuthorizationIfNeeded: jest.fn(() => { }) } } - + // When authorizeWithPersistOption(data)(system) - + // Then expect(system.authActions.authorize).toHaveBeenCalled() expect(system.authActions.authorize).toHaveBeenCalledWith(data) @@ -223,17 +232,17 @@ describe("auth plugin - actions", () => { const data = { "api_key": {} } - const system = { + const system = { getConfigs: () => ({}), authActions: { - authorizeOauth2: jest.fn(()=>{}), - persistAuthorizationIfNeeded: jest.fn(()=>{}) + authorizeOauth2: jest.fn(() => { }), + persistAuthorizationIfNeeded: jest.fn(() => { }) } } - + // When authorizeOauth2WithPersistOption(data)(system) - + // Then expect(system.authActions.authorizeOauth2).toHaveBeenCalled() expect(system.authActions.authorizeOauth2).toHaveBeenCalledWith(data) @@ -246,23 +255,23 @@ describe("auth plugin - actions", () => { const data = { "api_key": {} } - const system = { + const system = { getConfigs: () => ({}), authActions: { - logout: jest.fn(()=>{}), - persistAuthorizationIfNeeded: jest.fn(()=>{}) + logout: jest.fn(() => { }), + persistAuthorizationIfNeeded: jest.fn(() => { }) } } - + // When logoutWithPersistOption(data)(system) - + // Then expect(system.authActions.logout).toHaveBeenCalled() expect(system.authActions.logout).toHaveBeenCalledWith(data) expect(system.authActions.persistAuthorizationIfNeeded).toHaveBeenCalled() }) - }) + }) describe("persistAuthorizationIfNeeded", () => { beforeEach(() => { @@ -270,18 +279,18 @@ describe("auth plugin - actions", () => { }) it("should skip if `persistAuthorization` is turned off", () => { // Given - const system = { + const system = { getConfigs: () => ({ persistAuthorization: false - }), + }), authSelectors: { - authorized: jest.fn(()=>{}) + authorized: jest.fn(() => { }) } } - + // When persistAuthorizationIfNeeded()(system) - + // Then expect(system.authSelectors.authorized).not.toHaveBeenCalled() }) @@ -290,22 +299,25 @@ describe("auth plugin - actions", () => { const data = { "api_key": {} } - const system = { + const system = { getConfigs: () => ({ persistAuthorization: true - }), + }), + errActions: { + newAuthErr: () => ({}) + }, authSelectors: { - authorized: jest.fn(()=>Map(data)) + authorized: jest.fn(() => Map(data)) } - } + } jest.spyOn(Object.getPrototypeOf(window.localStorage), "setItem") // When persistAuthorizationIfNeeded()(system) expect(localStorage.setItem).toHaveBeenCalled() - expect(localStorage.setItem).toHaveBeenCalledWith("authorized", JSON.stringify(data)) - + expect(localStorage.setItem).toHaveBeenCalledWith("authorized", JSON.stringify(data)) + }) })