Repository navigation
fix(logout): keep other workspaces reachable after a forced logout #7591
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8df755b
fix(logout): keep other workspaces reachable after a forced logout
8a135ce
Merge remote-tracking branch 'origin/new-sdk' into diegolmello/fix-fo…
diegolmello 9f93c0e
test: move the forced-logout test onto the shared saga store harness
835bfbc
refactor(logout): collapse the duplicated logged-in-server lookup and…
diegolmello 655e203
fix(logout): pass the real server version when switching after a logout
diegolmello 0dc20a8
refactor(logout): look the remaining server up once for both logout b…
diegolmello 03c0e7d
Merge remote-tracking branch 'origin/new-sdk' into diegolmello/fix-fo…
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| jest.mock('../../lib/methods/getPermissions', () => ({ | ||
| getPermissions: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/enterpriseModules', () => ({ | ||
| getEnterpriseModules: jest.fn(), | ||
| isOmnichannelModuleAvailable: jest.fn(() => false), | ||
| isOmnichannelStatusAvailable: jest.fn(() => false), | ||
| isVoipModuleAvailable: jest.fn(() => false) | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/getCustomEmojis', () => ({ | ||
| getCustomEmojis: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/getRoles', () => ({ | ||
| getRoles: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/getSlashCommands', () => ({ | ||
| getSlashCommands: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/getSettings', () => ({ | ||
| subscribeSettings: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/getUsersPresence', () => ({ | ||
| getUserPresence: jest.fn(), | ||
| refreshDmUsersPresence: jest.fn(), | ||
| subscribeUsersPresence: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/restApi', () => ({ | ||
| getUsersRoles: jest.fn(() => []), | ||
| registerPushToken: jest.fn(), | ||
| saveUserProfile: jest.fn(), | ||
| setUserPresenceAway: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/connect', () => ({ | ||
| disconnect: jest.fn(), | ||
| login: jest.fn(), | ||
| loginWithPassword: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/logout', () => ({ | ||
| logout: jest.fn(), | ||
| removeServerData: jest.fn(), | ||
| removeServerDatabase: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/voip/MediaSessionInstance', () => ({ | ||
| mediaSessionInstance: { init: jest.fn(), reset: jest.fn() } | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/voip/MediaSessionStore', () => ({ | ||
| mediaSessionStore: { getCurrentInstance: jest.fn(() => null) } | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/voip/isInActiveVoipCall', () => ({ | ||
| isInActiveVoipCall: jest.fn(() => false) | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/helpers/localAuthentication', () => ({ | ||
| localAuthenticate: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/helpers/info', () => ({ | ||
| showErrorAlert: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/sdk', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| current: { client: { host: '' } }, | ||
| subscribe: jest.fn() | ||
| } | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/helpers/log', () => ({ | ||
| ...jest.requireActual('../../lib/methods/helpers/log'), | ||
| __esModule: true, | ||
| default: jest.fn() | ||
| })); | ||
|
|
||
| const mockServersQuery = { query: jest.fn(() => ({ fetch: jest.fn() })) }; | ||
|
|
||
| jest.mock('../../lib/database', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| active: { get: jest.fn() }, | ||
| servers: { | ||
| get: jest.fn(() => mockServersQuery), | ||
| write: jest.fn(async (block: () => Promise<void>) => block()) | ||
| } | ||
| } | ||
| })); | ||
|
|
||
| import loginRoot from '../login'; | ||
| import { logout } from '../../actions/login'; | ||
| import { selectServerSuccess } from '../../actions/server'; | ||
| import { SERVER } from '../../actions/actionsTypes'; | ||
| import UserPreferences from '../../lib/methods/userPreferences'; | ||
| import { TOKEN_KEY } from '../../lib/constants/keys'; | ||
| import { cancelSagaTasks, createRecordingStore, flushSagaMicrotasks } from '../../lib/testUtils/sagaStore'; | ||
|
|
||
| afterEach(cancelSagaTasks); | ||
|
|
||
| const LOGGED_OUT_SERVER = 'https://logged-out.rocket.chat'; | ||
| const OTHER_SERVER = 'https://other.rocket.chat'; | ||
|
|
||
| const setRemainingServers = (servers: { id: string }[]) => { | ||
| mockServersQuery.query.mockReturnValue({ fetch: jest.fn(() => Promise.resolve(servers)) }); | ||
| }; | ||
|
|
||
| const runForcedLogout = async () => { | ||
| const { store, dispatchedActions } = createRecordingStore(loginRoot); | ||
| store.dispatch(selectServerSuccess({ server: LOGGED_OUT_SERVER, version: '7.0.0', name: 'Logged out' })); | ||
| store.dispatch(logout(true, 'Logged_out_by_server')); | ||
| await flushSagaMicrotasks(); | ||
| return dispatchedActions; | ||
| }; | ||
|
|
||
| describe('login saga — a logout forced by the server', () => { | ||
| beforeEach(() => { | ||
| UserPreferences.removeItem(`${TOKEN_KEY}-${OTHER_SERVER}`); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('points previousServer at another logged in workspace, so the user can leave NewServerView', async () => { | ||
| setRemainingServers([{ id: OTHER_SERVER }]); | ||
| UserPreferences.setString(`${TOKEN_KEY}-${OTHER_SERVER}`, 'user-id'); | ||
|
|
||
| const dispatchedActions = await runForcedLogout(); | ||
|
|
||
| expect(dispatchedActions).toEqual(expect.arrayContaining([{ type: SERVER.INIT_ADD, previousServer: OTHER_SERVER }])); | ||
| }); | ||
|
|
||
| it('leaves previousServer unset when no other workspace is logged in', async () => { | ||
| setRemainingServers([{ id: OTHER_SERVER }]); | ||
|
|
||
| const dispatchedActions = await runForcedLogout(); | ||
|
|
||
| expect(dispatchedActions.some(({ type }) => type === SERVER.INIT_ADD)).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.