diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 236edf2cb1c..84144d88e1b 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1593,24 +1593,6 @@ "count": 70 } }, - "packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 4 - }, - "@typescript-eslint/prefer-nullish-coalescing": { - "count": 1 - } - }, - "packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 6 - } - }, - "packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 1 - } - }, "packages/notification-services-controller/src/NotificationServicesPushController/services/services.ts": { "@typescript-eslint/naming-convention": { "count": 1 diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts b/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts index a0d8caa3714..5c93260ffb0 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts @@ -16,11 +16,16 @@ const MOCK_FCM_TOKEN = 'mockFcmToken'; const MOCK_ADDRESSES = ['0x123', '0x456', '0x789']; // Testing util to clean up verbose logs when testing errors -const mockErrorLog = () => +const mockErrorLog = (): jest.SpyInstance => jest.spyOn(log, 'error').mockImplementation(jest.fn()); describe('NotificationServicesPushController', () => { - const arrangeServicesMocks = (token?: string) => { + const arrangeServicesMocks = ( + token?: string, + ): { + activatePushNotificationsMock: jest.SpyInstance; + deactivatePushNotificationsMock: jest.SpyInstance; + } => { const activatePushNotificationsMock = jest .spyOn(services, 'activatePushNotifications') .mockResolvedValue(token ?? MOCK_FCM_TOKEN); @@ -359,8 +364,12 @@ function arrangeMockMessenger( state?: Partial; } >, -) { - const { state: stateOverride, ...configOverride } = controllerConfig || {}; +): { + controller: NotificationServicesPushController; + initialState: NotificationServicesPushController['state']; + messenger: NotificationServicesPushControllerMessenger; +} { + const { state: stateOverride, ...configOverride } = controllerConfig ?? {}; const config: ControllerConfig = { isPushFeatureEnabled: true, @@ -403,7 +412,14 @@ function arrangeMockMessenger( */ function mockAuthBearerTokenCall( messenger: NotificationServicesPushControllerMessenger, -) { +): jest.Mock< + ReturnType< + AuthenticationController.AuthenticationControllerGetBearerToken['handler'] + >, + Parameters< + AuthenticationController.AuthenticationControllerGetBearerToken['handler'] + > +> { type Fn = AuthenticationController.AuthenticationControllerGetBearerToken['handler']; const mockAuthGetBearerToken = jest diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts b/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts index 5f867d2dc52..445bd3533fc 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts @@ -225,7 +225,7 @@ export default class NotificationServicesPushController extends BaseController< }); } - async #getAndAssertBearerToken() { + async #getAndAssertBearerToken(): Promise { const bearerToken = await this.messenger.call( 'AuthenticationController:getBearerToken', ); @@ -239,7 +239,7 @@ export default class NotificationServicesPushController extends BaseController< return bearerToken; } - #updatePushState(command: StateCommand) { + #updatePushState(command: StateCommand): void { if (command.type === 'enable') { this.update((state) => { state.isPushEnabled = true; @@ -266,7 +266,7 @@ export default class NotificationServicesPushController extends BaseController< } } - public async subscribeToPushNotifications() { + public async subscribeToPushNotifications(): Promise { if (!this.#config.isPushFeatureEnabled) { return; } @@ -296,7 +296,7 @@ export default class NotificationServicesPushController extends BaseController< * * @param addresses - An array of addresses to enable push notifications for. */ - public async enablePushNotifications(addresses: string[]) { + public async enablePushNotifications(addresses: string[]): Promise { if (!this.#config.isPushFeatureEnabled) { return; } @@ -351,7 +351,7 @@ export default class NotificationServicesPushController extends BaseController< * Disables push notifications for the application. * This removes the registration token on this device, and ensures we unsubscribe from any listeners */ - public async disablePushNotifications() { + public async disablePushNotifications(): Promise { if (!this.#config.isPushFeatureEnabled) { return; } @@ -394,7 +394,9 @@ export default class NotificationServicesPushController extends BaseController< * @param addresses - An array of addresses that should trigger push notifications. * @deprecated - this is not used anymore and will most likely be removed */ - public async updateTriggerPushNotifications(addresses: string[]) { + public async updateTriggerPushNotifications( + addresses: string[], + ): Promise { if (!this.#config.isPushFeatureEnabled) { return; } diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts b/packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts index 605655c4672..75129d47d51 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts @@ -9,7 +9,7 @@ type MockReply = { export const mockEndpointUpdatePushNotificationLinks = ( mockReply?: MockReply, -) => { +): nock.Scope => { const mockResponse = getMockUpdatePushNotificationLinksResponse(); const reply = mockReply ?? { status: 204,