Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still more sso test #1408

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Opt-in: disable login when cookies are disabled. Refs STCOR-762.
* Add arial-label for `ProfileDropdown.js`. Refs STCOR-753.
* Move `localforage.clear()` to `afterEach` for test suite. Refs STCOR-801.
* Avoid calling `map` on `undefined` via optional-chaining. Refs STCOR-793.

## [10.0.0](https://github.com/folio-org/stripes-core/tree/v10.0.0) (2023-10-11)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v9.0.0...v10.0.0)
Expand Down
1 change: 1 addition & 0 deletions src/RootWithIntl.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
const connect = connectFor('@folio/core', this.props.stripes.epics, this.props.stripes.logger);
const stripes = this.props.stripes.clone({ connect });

console.log(`isAuthenticated: ${isAuthenticated}, token: ${token}`);

Check warning on line 80 in src/RootWithIntl.js

View workflow job for this annotation

GitHub Actions / build-npm

Unexpected console statement

Check warning on line 80 in src/RootWithIntl.js

View workflow job for this annotation

GitHub Actions / build-npm

Unexpected console statement
return (
<StripesContext.Provider value={stripes}>
<CalloutContext.Provider value={this.state.callout}>
Expand Down
71 changes: 71 additions & 0 deletions src/components/SSOLanding.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';
import { useLocation } from 'react-router-dom';
import { useCookies } from 'react-cookie';
import { requestUserWithPerms } from '../loginServices';

import SSOLanding from './SSOLanding';

jest.mock('lodash', () => ({
debounce: jest.fn(fn => fn)
}));

jest.mock('../loginServices', () => ({
requestUserWithPerms: jest.fn(() => {})
}));

jest.mock('react-router-dom', () => ({
useLocation: jest.fn()
}));

jest.mock('stripes-config', () => ({
okapi: {
url: 'okapiUrl',
tenant: 'okapiTenant'
}
}),
{ virtual: true });

jest.mock('react-cookie', () => ({
useCookies: jest.fn()
}));

jest.mock('react-redux', () => ({
useStore: jest.fn()
}));

describe('SSOLanding', () => {
beforeEach(() => {
useLocation.mockImplementation(() => ({ search: '' }));
useCookies.mockImplementation(() => [{}]);
});

afterEach(() => {
jest.resetAllMocks();
});

describe('handles token within query parameters', () => {
it('processes login', () => {
useLocation.mockImplementation(() => ({ search: 'ssoToken=c0ffee' }));
render(<SSOLanding />);
expect(requestUserWithPerms.mock.calls).toHaveLength(1);
expect(screen.getByText(/Logged in with token.*param\.$/)).toBeInTheDocument();
});
});

describe('handles token within a cookie', () => {
it('processes login', () => {
useCookies.mockImplementation(() => ([{ ssoToken: 'c0ffee-c0ffee' }]));
render(<SSOLanding />);
expect(requestUserWithPerms.mock.calls).toHaveLength(1);
expect(screen.getByText(/Logged in with token.*cookie\.$/)).toBeInTheDocument();
});
});

describe('displays error with no token.', () => {
it('processes login', () => {
render(<SSOLanding />);
expect(requestUserWithPerms.mock.calls).toHaveLength(0);
expect(screen.getByText('No cookie or query parameter')).toBeInTheDocument();
});
});
});
8 changes: 5 additions & 3 deletions src/loginServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,11 @@ export function spreadUserWithPerms(userWithPerms) {
...userWithPerms?.user?.personal,
};

// remap data's array of permission-names to set with
// permission-names for keys and `true` for values
const perms = Object.assign({}, ...userWithPerms?.permissions?.permissions.map(p => ({ [p.permissionName]: true })));
// remap permissions from [foo, bar, bat] to { foo: true, bar: true, ... }
const perms = userWithPerms?.permissions?.permissions?.reduce((acc, i) => {
acc[i.permissionName] = true;
return acc;
}, {});

return { user, perms };
}
Expand Down
2 changes: 1 addition & 1 deletion test/bigtest/helpers/setup-application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach } from '@bigtest/mocha';
import { beforeEach, afterEach } from '@bigtest/mocha';
import localforage from 'localforage';

import { reset } from '@folio/stripes-connect';
Expand Down
2 changes: 1 addition & 1 deletion test/bigtest/helpers/setup-core-application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setupApplication from './setup-application';

export default function setupCoreApplication(options = {}) {
options.mirageOptions = { serverType: 'miragejs' };
options.mirageOptions = { ...options.mirageOptions, serverType: 'miragejs' };
setupApplication(options);
}
5 changes: 5 additions & 0 deletions test/bigtest/network/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default function configure() {
},
'departments': [
]
},
'permissions' : {
permissions: [
'configuration.entries.collection.get'
]
}
});

Expand Down
75 changes: 0 additions & 75 deletions test/bigtest/tests/sso-login-test.js

This file was deleted.

Loading