Skip to content

Commit

Permalink
Merge pull request #37026 from ruben-rebelo/ts-migration/unit-pusherh…
Browse files Browse the repository at this point in the history
…elper

[No QA][TS migration] Migrate PusherHelper to Typescript
  • Loading branch information
luacmartins authored Mar 4, 2024
2 parents 3eed3c9 + 036f22c commit 623c191
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/types/utils/AsMutable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {Writable} from 'type-fest';

const asMutable = <T>(value: T): Writable<T> => value as Writable<T>;

export default asMutable;
21 changes: 10 additions & 11 deletions tests/utils/PusherHelper.js → tests/utils/PusherHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import CONFIG from '../../src/CONFIG';
import CONST from '../../src/CONST';
import * as Pusher from '../../src/libs/Pusher/pusher';
import PusherConnectionManager from '../../src/libs/PusherConnectionManager';
import type {OnyxUpdate} from 'react-native-onyx';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import * as Pusher from '@src/libs/Pusher/pusher';
import PusherConnectionManager from '@src/libs/PusherConnectionManager';
import asMutable from '@src/types/utils/AsMutable';

const CHANNEL_NAME = `${CONST.PUSHER.PRIVATE_USER_CHANNEL_PREFIX}1${CONFIG.PUSHER.SUFFIX}`;

Expand All @@ -10,8 +12,8 @@ function setup() {
// channel already in a subscribed state. These methods are normally used to prevent
// duplicated subscriptions, but we don't need them for this test so forcing them to
// return false will make the testing less complex.
Pusher.isSubscribed = jest.fn().mockReturnValue(false);
Pusher.isAlreadySubscribing = jest.fn().mockReturnValue(false);
asMutable(Pusher).isSubscribed = jest.fn().mockReturnValue(false);
asMutable(Pusher).isAlreadySubscribing = jest.fn().mockReturnValue(false);

// Connect to Pusher
PusherConnectionManager.init();
Expand All @@ -22,12 +24,9 @@ function setup() {
});
}

/**
* @param {Array} args
*/
function emitOnyxUpdate(args) {
function emitOnyxUpdate(args: OnyxUpdate[]) {
const channel = Pusher.getChannel(CHANNEL_NAME);
channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [
channel?.emit(Pusher.TYPE.MULTIPLE_EVENTS, [
{
eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE,
data: args,
Expand Down

0 comments on commit 623c191

Please sign in to comment.