Skip to content

Commit

Permalink
chore(message-system): better named getValidExperimentIds utility fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
matejkriz committed Jan 14, 2025
1 parent a7c00a0 commit 97ea53c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Message system middleware', () => {
message3,
message4,
]);
jest.spyOn(messageSystemUtils, 'getValidExperiments').mockImplementation(() => []);
jest.spyOn(messageSystemUtils, 'getValidExperimentIds').mockImplementation(() => []);

const store = initStore(getInitialState(undefined, undefined));
store.dispatch({
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('Message system middleware', () => {

it('saves messages even if there are no valid messages', () => {
jest.spyOn(messageSystemUtils, 'getValidMessages').mockImplementation(() => []);
jest.spyOn(messageSystemUtils, 'getValidExperiments').mockImplementation(() => []);
jest.spyOn(messageSystemUtils, 'getValidExperimentIds').mockImplementation(() => []);

const store = initStore(getInitialState(undefined, undefined));
store.dispatch({
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('Message system middleware', () => {
],
};

jest.spyOn(messageSystemUtils, 'getValidExperiments').mockImplementation(() => [
jest.spyOn(messageSystemUtils, 'getValidExperimentIds').mockImplementation(() => [
experiment1.id,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
messageSystemActions,
categorizeMessages,
getValidMessages,
getValidExperiments,
getValidExperimentIds,
} from '@suite-common/message-system';

import { SUITE } from 'src/actions/suite/constants';
Expand Down Expand Up @@ -50,10 +50,10 @@ const messageSystemMiddleware =
const validMessages = getValidMessages(config, validationParams);
const categorizedValidMessages = categorizeMessages(validMessages);

const validExperiments = getValidExperiments(config, validationParams);
const validExperimentIds = getValidExperimentIds(config, validationParams);

api.dispatch(messageSystemActions.updateValidMessages(categorizedValidMessages));
api.dispatch(messageSystemActions.updateValidExperiments(validExperiments));
api.dispatch(messageSystemActions.updateValidExperiments(validExperimentIds));
}

return action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1945,9 +1945,9 @@ export const validateExperiments = [
},
];

export const getValidExperiments = [
export const getValidExperimentIds = [
{
description: 'getValidExperiments - case 1',
description: 'getValidExperimentIds - case 1',
currentDate: '2021-04-01T12:10:00.000Z',
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('Message system utils', () => {
});
});

describe('getValidExperiments', () => {
describe('getValidExperimentIds', () => {
let userAgentGetter: any;
const OLD_ENV = { ...process.env };

Expand All @@ -140,7 +140,7 @@ describe('Message system utils', () => {
process.env = OLD_ENV;
});

fixtures.getValidExperiments.forEach(f => {
fixtures.getValidExperimentIds.forEach(f => {
it(f.description, () => {
jest.spyOn(Date, 'now').mockImplementation(() => new Date(f.currentDate).getTime());
// @ts-expect-error (getOsName returns union of string literals)
Expand All @@ -151,7 +151,7 @@ describe('Message system utils', () => {
process.env.VERSION = f.suiteVersion;

// @ts-expect-error
expect(messageSystem.getValidExperiments(f.config, f.options)).toEqual(f.result);
expect(messageSystem.getValidExperimentIds(f.config, f.options)).toEqual(f.result);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion suite-common/message-system/src/messageSystemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const getValidMessages = (config: MessageSystem | null, options: Options)
.map(action => action.message);
};

export const getValidExperiments = (config: MessageSystem | null, options: Options): string[] => {
export const getValidExperimentIds = (config: MessageSystem | null, options: Options): string[] => {
if (!config?.experiments) {
return [];
}
Expand Down
6 changes: 3 additions & 3 deletions suite-native/message-system/src/messageSystemMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
categorizeMessages,
getValidMessages,
selectMessageSystemConfig,
getValidExperiments,
getValidExperimentIds,
} from '@suite-common/message-system';
import { deviceActions, selectSelectedDevice } from '@suite-common/wallet-core';
import {
Expand Down Expand Up @@ -42,10 +42,10 @@ export const messageSystemMiddleware = createMiddleware((action, { next, dispatc
const validMessages = getValidMessages(config, validationParams);
const categorizedValidMessages = categorizeMessages(validMessages);

const validExperiments = getValidExperiments(config, validationParams);
const validExperimentIds = getValidExperimentIds(config, validationParams);

dispatch(messageSystemActions.updateValidMessages(categorizedValidMessages));
dispatch(messageSystemActions.updateValidExperiments(validExperiments));
dispatch(messageSystemActions.updateValidExperiments(validExperimentIds));
}

return action;
Expand Down

0 comments on commit 97ea53c

Please sign in to comment.