-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/12435-mvp-handle-engine-does-not-exist
- Loading branch information
Showing
53 changed files
with
3,033 additions
and
395 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,8 @@ | ||
export enum identityErrors { | ||
PERFORM_SIGN_IN = 'Error while trying to sign in', | ||
PERFORM_SIGN_OUT = 'Error while trying to sign out', | ||
ENABLE_PROFILE_SYNCING = 'Error while trying to enable profile syncing', | ||
DISABLE_PROFILE_SYNCING = 'Error while trying to disable profile syncing', | ||
} | ||
|
||
export default identityErrors; |
This file contains 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,51 @@ | ||
import { performSignIn, performSignOut } from '.'; | ||
import Engine from '../../core/Engine'; | ||
|
||
jest.mock('../../core/Engine', () => ({ | ||
resetState: jest.fn(), | ||
context: { | ||
AuthenticationController: { | ||
performSignIn: jest.fn(), | ||
performSignOut: jest.fn(), | ||
getSessionProfile: jest.fn(), | ||
}, | ||
}, | ||
})); | ||
|
||
describe('Identity actions', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('signs in successfully and obtain profile', async () => { | ||
( | ||
Engine.context.AuthenticationController.performSignIn as jest.Mock | ||
).mockResolvedValue('valid-access-token'); | ||
( | ||
Engine.context.AuthenticationController.getSessionProfile as jest.Mock | ||
).mockResolvedValue('valid-profile'); | ||
|
||
const result = await performSignIn(); | ||
|
||
expect( | ||
Engine.context.AuthenticationController.performSignIn, | ||
).toHaveBeenCalled(); | ||
expect( | ||
Engine.context.AuthenticationController.getSessionProfile, | ||
).toHaveBeenCalled(); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('signs out successfully', async () => { | ||
( | ||
Engine.context.AuthenticationController.performSignOut as jest.Mock | ||
).mockResolvedValue(undefined); | ||
|
||
const result = await performSignOut(); | ||
|
||
expect( | ||
Engine.context.AuthenticationController.performSignOut, | ||
).toHaveBeenCalled(); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file contains 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,53 @@ | ||
import { getErrorMessage } from '@metamask/utils'; | ||
import Engine from '../../core/Engine'; | ||
import identityErrors from './constants/errors'; | ||
|
||
export const performSignIn = async () => { | ||
try { | ||
const accessToken = | ||
await Engine.context.AuthenticationController.performSignIn(); | ||
if (!accessToken) { | ||
return getErrorMessage(identityErrors.PERFORM_SIGN_IN); | ||
} | ||
|
||
const profile = | ||
await Engine.context.AuthenticationController.getSessionProfile(); | ||
if (!profile) { | ||
return getErrorMessage(identityErrors.PERFORM_SIGN_IN); | ||
} | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const performSignOut = async () => { | ||
try { | ||
await Engine.context.AuthenticationController.performSignOut(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const enableProfileSyncing = async () => { | ||
try { | ||
await Engine.context.UserStorageController.enableProfileSyncing(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const disableProfileSyncing = async () => { | ||
try { | ||
await Engine.context.UserStorageController.disableProfileSyncing(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; | ||
|
||
export const syncInternalAccountsWithUserStorage = async () => { | ||
try { | ||
await Engine.context.UserStorageController.syncInternalAccountsWithUserStorage(); | ||
} catch (error) { | ||
return getErrorMessage(error); | ||
} | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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.