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

fix: profile-sync-controller - make fixture constants lazy #4592

Merged
merged 4 commits into from
Aug 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,27 @@ export type AllowedActions =
| NotificationServicesPushControllerUpdateTriggerPushNotifications;

// Events
export type NotificationServicesControllerChangeEvent =
export type NotificationServicesControllerStateChangeEvent =
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
ControllerStateChangeEvent<
typeof controllerName,
NotificationServicesControllerState
>;

export type MetamaskNotificationsControllerNotificationsListUpdatedEvent = {
export type NotificationListUpdatedEvent = {
type: `${typeof controllerName}:notificationsListUpdated`;
payload: [INotification[]];
};

export type MetamaskNotificationsControllerMarkNotificationsAsRead = {
export type MarkNotificationsAsReadEvent = {
type: `${typeof controllerName}:markNotificationsAsRead`;
payload: [INotification[]];
};

// Events
export type Events =
| NotificationServicesControllerChangeEvent
| MetamaskNotificationsControllerNotificationsListUpdatedEvent
| MetamaskNotificationsControllerMarkNotificationsAsRead;
| NotificationServicesControllerStateChangeEvent
| NotificationListUpdatedEvent
| MarkNotificationsAsReadEvent;

// Allowed Events
export type AllowedEvents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ export const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT
MOCK_STORAGE_KEY,
)}`;

const MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {
const MOCK_GET_USER_STORAGE_RESPONSE = (): GetUserStorageResponse => ({
HashedKey: 'HASHED_KEY',
Data: MOCK_ENCRYPTED_STORAGE_DATA,
};
Data: MOCK_ENCRYPTED_STORAGE_DATA(),
});

export const getMockUserStorageGetResponse = () => {
return {
url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,
requestMethod: 'GET',
response: MOCK_GET_USER_STORAGE_RESPONSE,
response: MOCK_GET_USER_STORAGE_RESPONSE(),
} satisfies MockResponse;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import encryption, { createSHA256Hash } from '../encryption';
export const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';
export const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);
export const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });
export const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(
MOCK_STORAGE_DATA,
MOCK_STORAGE_KEY,
);

// NOTE - using encryption.encryptString directly in fixtures causes issues on mobile.
// This is because this fixture is getting added in at run time. Will be improved once we support multiple exports
export const MOCK_ENCRYPTED_STORAGE_DATA = () =>
encryption.encryptString(MOCK_STORAGE_DATA, MOCK_STORAGE_KEY);
Comment on lines +7 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, mobile has an issue with running this fixture.

This most likely is because our relative imports (barrel files), drag in these fixtures and need to be computed once pulled in.

We will explore multiple file exports, this should mostly alleviate this issue.

E.g.

// If want to reuse fixtures, we can have a separate endpoint for this. Likewise for other areas for this controller.
import {} from '@metamask/profile-sync-controller/fixtures'

Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ describe('user-storage/services.ts - getUserStorage() tests', () => {
});

describe('user-storage/services.ts - upsertUserStorage() tests', () => {
const encryptedData = MOCK_ENCRYPTED_STORAGE_DATA();
const actCallUpsertUserStorage = () => {
return upsertUserStorage(MOCK_ENCRYPTED_STORAGE_DATA, {
return upsertUserStorage(encryptedData, {
bearerToken: 'MOCK_BEARER_TOKEN',
path: 'notifications.notificationSettings',
storageKey: MOCK_STORAGE_KEY,
Expand Down
Loading