Skip to content
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 @@ -69,26 +69,6 @@ const mockErrorLog = () =>
const mockWarnLog = () => jest.spyOn(log, 'warn').mockImplementation(jest.fn());

describe('metamask-notifications - constructor()', () => {
const arrangeMocks = () => {
const messengerMocks = mockNotificationMessenger();
jest
.spyOn(ControllerUtils, 'toChecksumHexAddress')
.mockImplementation((x) => x);

return messengerMocks;
};

const actPublishKeyringStateChange = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messenger: any,
) => {
messenger.publish(
'KeyringController:stateChange',
{} as KeyringControllerState,
[],
);
};

it('initializes state & override state', () => {
const controller1 = new NotificationServicesController({
messenger: mockNotificationMessenger().messenger,
Expand All @@ -108,6 +88,28 @@ describe('metamask-notifications - constructor()', () => {
expect(controller2.state.isFeatureAnnouncementsEnabled).toBe(true);
expect(controller2.state.isNotificationServicesEnabled).toBe(true);
});
});

describe('metamask-notifications - init()', () => {
const arrangeMocks = () => {
const messengerMocks = mockNotificationMessenger();
jest
.spyOn(ControllerUtils, 'toChecksumHexAddress')
.mockImplementation((x) => x);

return messengerMocks;
};

const actPublishKeyringStateChange = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messenger: any,
) => {
messenger.publish(
'KeyringController:stateChange',
{} as KeyringControllerState,
[],
);
};

it('keyring Change Event but feature not enabled will not add or remove triggers', async () => {
const { messenger, globalMessenger, mockWithKeyring } = arrangeMocks();
Expand All @@ -118,6 +120,7 @@ describe('metamask-notifications - constructor()', () => {
messenger,
env: { featureAnnouncements: featureAnnouncementsEnv },
});
controller.init();

const mockUpdate = jest
.spyOn(controller, 'updateOnChainTriggersByAccount')
Expand Down Expand Up @@ -146,6 +149,7 @@ describe('metamask-notifications - constructor()', () => {
subscriptionAccountsSeen: [ADDRESS_1],
},
});
controller.init();

const mockUpdate = jest
.spyOn(controller, 'updateOnChainTriggersByAccount')
Expand Down Expand Up @@ -199,12 +203,14 @@ describe('metamask-notifications - constructor()', () => {
modifications?.(mocks);

// Act
new NotificationServicesController({
const controller = new NotificationServicesController({
messenger: mocks.messenger,
env: { featureAnnouncements: featureAnnouncementsEnv },
state: { isNotificationServicesEnabled: true },
});

controller.init();

return mocks;
};

Expand Down Expand Up @@ -287,7 +293,7 @@ describe('metamask-notifications - constructor()', () => {
modifications?.(mocks);

// Act
new NotificationServicesController({
const controller = new NotificationServicesController({
messenger: mocks.messenger,
env: {
featureAnnouncements: featureAnnouncementsEnv,
Expand All @@ -296,6 +302,8 @@ describe('metamask-notifications - constructor()', () => {
state: { isNotificationServicesEnabled: true },
});

controller.init();

return mocks;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ export default class NotificationServicesController extends BaseController<
this.#featureAnnouncementEnv = env.featureAnnouncements;
this.#registerMessageHandlers();
this.#clearLoadingStates();
}

init() {
this.#keyringController.setupLockedStateSubscriptions(async () => {
await this.#accounts.initialize();
await this.#pushNotifications.initializePushNotifications();
Expand Down
Loading