Skip to content

Commit

Permalink
Chore: Cleanup function names and add tests for utils
Browse files Browse the repository at this point in the history
setup CI to run unit tests for a passing build

Updated release command to ensure all unit tests are passing
  • Loading branch information
paustint committed Apr 28, 2024
1 parent c8d2057 commit 4927cf9
Show file tree
Hide file tree
Showing 152 changed files with 2,155 additions and 1,122 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:

jobs:
# Build application
build:
build-and-test:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand All @@ -41,10 +41,15 @@ jobs:
- name: install dependencies
run: yarn install --frozen-lockfile

- name: Test application
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn test:affected

- name: Build application
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: npx nx run-many --target=build --parallel=3 --projects=jetstream,api,download-zip-sw,landing --configuration=production
run: yarn build:ci

- name: Uploading artifacts
uses: actions/upload-artifact@v4
Expand All @@ -54,7 +59,7 @@ jobs:

# e2e tests only runs if build passes, since it uses production build to run tests
e2e:
needs: build
needs: build-and-test
runs-on: ubuntu-latest
env:
LOG_LEVEL: warn
Expand Down
1 change: 1 addition & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"release": true
},
"hooks": {
"before:init": ["SKIP_ROLLBAR=true yarn build", "yarn test:all"],
"before:bump": "SKIP_ROLLBAR=true yarn build",
"after:release": "CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && git checkout release && git reset --hard $CURRENT_BRANCH && git push origin release -f && git checkout main && yarn rollbar:create-deploy"
}
Expand Down
1 change: 0 additions & 1 deletion apps/api/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export default {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/server',
};
7 changes: 3 additions & 4 deletions apps/api/src/app/services/comtd/cometd-replay-extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* ENDED UP NOT USING THIS STUFF
*/
import { MapOf } from '@jetstream/types';
import { CometD, Message, Extension } from 'cometd';
import { CometD, Extension, Message } from 'cometd';
import { isNumber } from 'lodash';

/*
Expand Down Expand Up @@ -61,7 +60,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// message.ext = {};
// }

// const replayFromMap: MapOf<number> = {};
// const replayFromMap: Record<string, number> = {};
// replayFromMap[_channel] = _replay;

// // add "ext: { "replay" : { CHANNEL : REPLAY_VALUE }}" to subscribe message
Expand All @@ -76,7 +75,7 @@ export class CometdReplayExtension implements Extension {
static REPLAY_FROM_KEY = 'replay';
cometd: CometD;
extensionEnabled = true;
replayFromMap: MapOf<number | undefined> = {};
replayFromMap: Record<string, number | undefined> = {};

setEnabled(extensionEnabled: boolean) {
this.extensionEnabled = extensionEnabled;
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/app/services/salesforce.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ensureArray, getFullNameFromListMetadata, orderObjectsBy } from '@jetstream/shared/utils';
import { ListMetadataResult, MapOf, Maybe, PackageTypeMembers, RetrieveRequest } from '@jetstream/types';
import { ListMetadataResult, Maybe, PackageTypeMembers, RetrieveRequest } from '@jetstream/types';
import { isObjectLike, isString, get as lodashGet } from 'lodash';
import { create as xmlBuilder } from 'xmlbuilder2';
import { UserFacingError } from '../utils/error-handler';

const VALID_PACKAGE_VERSION = /^[0-9]+\.[0-9]+$/;

export function buildPackageXml(
types: MapOf<Pick<ListMetadataResult, 'fullName' | 'namespacePrefix'>[]>,
types: Record<string, Pick<ListMetadataResult, 'fullName' | 'namespacePrefix'>[]>,
version: string,
otherFields: Maybe<MapOf<string>> = {},
otherFields: Maybe<Record<string, string>> = {},
prettyPrint = true
) {
// prettier-ignore
Expand Down Expand Up @@ -44,7 +44,7 @@ export function buildPackageXml(
}

export function getRetrieveRequestFromListMetadata(
types: MapOf<Pick<ListMetadataResult, 'fullName' | 'namespacePrefix'>[]>,
types: Record<string, Pick<ListMetadataResult, 'fullName' | 'namespacePrefix'>[]>,
version: string
) {
// https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_retrieve_request.htm
Expand Down
13 changes: 8 additions & 5 deletions apps/api/src/app/utils/socket-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logger } from '@jetstream/api-config';
import { MapOf, UserProfileServer } from '@jetstream/types';
import { UserProfileServer } from '@jetstream/types';
import { CometD, SubscriptionHandle } from 'cometd';
import { Server, Socket } from 'socket.io';
import { DefaultEventsMap } from 'socket.io/dist/typed-events';
Expand All @@ -10,10 +10,13 @@ export interface SocketConnectionState {
io: Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap>;
socket: Socket<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap>;
user: UserProfileServer;
cometdConnections: MapOf<{
cometd: CometD | null;
subscriptions: Map<string, SubscriptionHandle>;
}>;
cometdConnections: Record<
string,
{
cometd: CometD | null;
subscriptions: Map<string, SubscriptionHandle>;
}
>;
}

export async function getOrg(user: UserProfileServer, uniqueId: string) {
Expand Down
2 changes: 1 addition & 1 deletion apps/cron-tasks/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export default {
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/cron-tasks',

preset: '../../jest.preset.js',
};
2 changes: 1 addition & 1 deletion apps/download-zip-sw/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export default {
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/download-zip-sw',

preset: '../../jest.preset.js',
};
2 changes: 1 addition & 1 deletion apps/jetstream-worker/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export default {
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/jetstream-worker',

preset: '../../jest.preset.js',
};
2 changes: 1 addition & 1 deletion apps/jetstream/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
coverageDirectory: '../../coverage/apps/jetstream',

globals: {},
displayName: 'jetstream',
preset: '../../jest.preset.js',
Expand Down
8 changes: 0 additions & 8 deletions apps/jetstream/src/app/__tests__/app.spec.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions apps/jetstream/src/app/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from '@jetstream/shared/client-logger';
import { HTTP, INDEXED_DB } from '@jetstream/shared/constants';
import { checkHeartbeat, getOrgs, getUserProfile } from '@jetstream/shared/data';
import { getOrgType, parseCookie } from '@jetstream/shared/ui-utils';
import { getMapOf } from '@jetstream/shared/utils';
import { groupByFlat } from '@jetstream/shared/utils';
import { ApplicationCookie, Maybe, SalesforceOrgUi, SalesforceOrgUiType, UserProfilePreferences, UserProfileUi } from '@jetstream/types';
import localforage from 'localforage';
import isString from 'lodash/isString';
Expand Down Expand Up @@ -185,7 +185,7 @@ export const salesforceOrgsById = selector({
key: 'salesforceOrgsById',
get: ({ get }) => {
const salesforceOrgs = get(salesforceOrgsState) || [];
return getMapOf(salesforceOrgs, 'uniqueId');
return groupByFlat(salesforceOrgs, 'uniqueId');
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ANALYTICS_KEYS, INDEXED_DB, LOG_LEVELS, TITLES } from '@jetstream/share
import { anonymousApex } from '@jetstream/shared/data';
import { useBrowserNotifications, useDebounce, useNonInitialEffect, useRollbar, useTitle } from '@jetstream/shared/ui-utils';
import { SplitWrapper as Split } from '@jetstream/splitjs';
import { ApexHistoryItem, ListItem, MapOf, SalesforceOrgUi } from '@jetstream/types';
import { ApexHistoryItem, ListItem, SalesforceOrgUi } from '@jetstream/types';
import {
AutoFullHeightContainer,
Badge,
Expand Down Expand Up @@ -101,7 +101,7 @@ export const AnonymousApex: FunctionComponent<AnonymousApexProps> = () => {
if (apex) {
(async () => {
try {
await localforage.setItem<MapOf<ApexHistoryItem>>(INDEXED_DB.KEYS.apexHistory, historyItems);
await localforage.setItem<Record<string, ApexHistoryItem>>(INDEXED_DB.KEYS.apexHistory, historyItems);
} catch (ex) {
logger.warn(ex);
}
Expand Down
16 changes: 8 additions & 8 deletions apps/jetstream/src/app/components/anonymous-apex/apex.state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from '@jetstream/shared/client-logger';
import { DATE_FORMATS, INDEXED_DB } from '@jetstream/shared/constants';
import { getMapOf, hashString, pluralizeFromNumber, truncate } from '@jetstream/shared/utils';
import { ApexHistoryItem, MapOf, SalesforceOrgUi } from '@jetstream/types';
import { groupByFlat, hashString, pluralizeFromNumber, truncate } from '@jetstream/shared/utils';
import { ApexHistoryItem, SalesforceOrgUi } from '@jetstream/types';
import { addDays } from 'date-fns/addDays';
import { formatDate } from 'date-fns/format';
import { isBefore } from 'date-fns/isBefore';
Expand All @@ -17,7 +17,7 @@ let didRunCleanup = false;
* If history grows to a very large size,
* prune older entries
*/
export async function cleanUpHistoryState(): Promise<MapOf<ApexHistoryItem> | undefined> {
export async function cleanUpHistoryState(): Promise<Record<string, ApexHistoryItem> | undefined> {
const ITEMS_UNTIL_PRUNE = 100; // require this many items before taking action
const DAYS_TO_KEEP = 60; // if action is taken, remove items older than this, keep all others
try {
Expand All @@ -29,7 +29,7 @@ export async function cleanUpHistoryState(): Promise<MapOf<ApexHistoryItem> | un
if (Object.keys(history).length > ITEMS_UNTIL_PRUNE) {
logger.info('[APEX-HISTORY][CLEANUP]', 'Cleaning up apex history');
const dateCutOff = startOfDay(addDays(new Date(), -1 * DAYS_TO_KEEP));
const itemsToKeep = getMapOf(
const itemsToKeep = groupByFlat(
Object.values(history).filter((item) => isBefore(dateCutOff, item.lastRun)),
'key'
);
Expand All @@ -40,16 +40,16 @@ export async function cleanUpHistoryState(): Promise<MapOf<ApexHistoryItem> | un
}

logger.info('[APEX-HISTORY][CLEANUP]', 'Keeping items', itemsToKeep);
await localforage.setItem<MapOf<ApexHistoryItem>>(INDEXED_DB.KEYS.apexHistory, itemsToKeep);
await localforage.setItem<Record<string, ApexHistoryItem>>(INDEXED_DB.KEYS.apexHistory, itemsToKeep);
return itemsToKeep;
}
} catch (ex) {
logger.warn('[APEX-HISTORY][CLEANUP]', 'Error cleaning up apex history', ex);
}
}

const initApexHistory = async (): Promise<MapOf<ApexHistoryItem>> => {
return (await localforage.getItem<MapOf<ApexHistoryItem>>(INDEXED_DB.KEYS.apexHistory)) || {};
const initApexHistory = async (): Promise<Record<string, ApexHistoryItem>> => {
return (await localforage.getItem<Record<string, ApexHistoryItem>>(INDEXED_DB.KEYS.apexHistory)) || {};
};

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function initNewApexHistoryItem(org: SalesforceOrgUi, apex: string)
return { ...historyItems, [newItem.key]: newItem };
}

export const apexHistoryState = atom<MapOf<ApexHistoryItem>>({
export const apexHistoryState = atom<Record<string, ApexHistoryItem>>({
key: 'apexHistory.apexHistoryState',
default: initApexHistory(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// */
// export function useApexCompletions(org: SalesforceOrgUi) {
// const isMounted = useRef(true);
// const [_completions, setCompletions] = useState<MapOf<ApexCompletion>>(null);
// const [_completions, setCompletions] = useState<Record<string, ApexCompletion>>(null);
// const [loading, setLoading] = useState(false);

// useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import { css } from '@emotion/react';
import { ANALYTICS_KEYS, TITLES } from '@jetstream/shared/constants';
import { formatNumber, useTitle } from '@jetstream/shared/ui-utils';
import { pluralizeFromNumber } from '@jetstream/shared/utils';
import {
FileExtAllTypes,
ListMetadataResult,
MapOf,
MimeType,
RetrievePackageFromListMetadataJob,
SalesforceOrgUi,
} from '@jetstream/types';
import { FileExtAllTypes, ListMetadataResult, MimeType, RetrievePackageFromListMetadataJob, SalesforceOrgUi } from '@jetstream/types';
import {
AutoFullHeightContainer,
Badge,
Expand Down Expand Up @@ -144,7 +137,7 @@ export const AutomationControlEditor: FunctionComponent<AutomationControlEditorP
mimeType: data.mimeType,
listMetadataItems: rows
.filter((row) => isTableRowItem(row))
.reduce((output: MapOf<ListMetadataResult[]>, item: TableRowItem) => {
.reduce((output: Record<string, ListMetadataResult[]>, item: TableRowItem) => {
const type = getAutomationDeployType(item.type);
output[type] = output[type] || [];
const record = item.record;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
// onRestore,
// }) => {
// const [isOpen, setIsOpen] = useState(false);
// const [snapshots, setSnapshots] = useState<MapOf<TableRowItemSnapshot[]>>();
// const [snapshots, setSnapshots] = useState<Record<string, TableRowItemSnapshot[]>>();
// const [snapshotsItems, setSnapshotItems] = useState<string[]>([]);
// const [selectedSnapshot, setSelectedSnapshot] = useState<string | null>(null);

// const getSnapshots = useCallback(async () => {
// try {
// const snapshotMap =
// (await localforage.getItem<MapOf<TableRowItemSnapshot[]>>(`${INDEXED_DB.KEYS.automationControlHistory}:${selectedOrg.uniqueId}`)) ||
// (await localforage.getItem<Record<string, TableRowItemSnapshot[]>>(`${INDEXED_DB.KEYS.automationControlHistory}:${selectedOrg.uniqueId}`)) ||
// {};
// setSnapshots(snapshotMap);
// setSnapshotItems(Object.keys(snapshotMap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// }
// });
// const snapshotMap =
// (await localforage.getItem<MapOf<TableRowItemSnapshot[]>>(`${INDEXED_DB.KEYS.automationControlHistory}:${selectedOrg.uniqueId}`)) ||
// (await localforage.getItem<Record<string, TableRowItemSnapshot[]>>(`${INDEXED_DB.KEYS.automationControlHistory}:${selectedOrg.uniqueId}`)) ||
// {};
// snapshotMap[name] = snapshot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
saveCacheItemNonHttp,
} from '@jetstream/shared/data';
import { getToolingRecords, logErrorToRollbar, pollMetadataResultsUntilDone } from '@jetstream/shared/ui-utils';
import { getMapOf, splitArrayToMaxSize } from '@jetstream/shared/utils';
import { CompositeRequest, CompositeRequestBody, CompositeResponse, MapOf, SalesforceOrgUi } from '@jetstream/types';
import { groupByFlat, splitArrayToMaxSize } from '@jetstream/shared/utils';
import { CompositeRequest, CompositeRequestBody, CompositeResponse, SalesforceOrgUi } from '@jetstream/types';
import { formatRelative } from 'date-fns/formatRelative';
import { Observable, Subject, from, of } from 'rxjs';
import { catchError, mergeMap } from 'rxjs/operators';
Expand Down Expand Up @@ -232,7 +232,7 @@ export async function getValidationRulesMetadata(
validationRuleRecords.map((record) => record.Id),
apiVersion
);
const validationRuleMetaById = getMapOf(
const validationRuleMetaById = groupByFlat(
validationRules.compositeResponse.map((item) => item.body),
'Id'
);
Expand Down Expand Up @@ -273,7 +273,7 @@ export async function getWorkflowRulesMetadata(
apiVersion
);

const workflowRuleMetaById = getMapOf(
const workflowRuleMetaById = groupByFlat(
workflowRules.compositeResponse.map((item) => item.body),
'Id'
);
Expand Down Expand Up @@ -319,8 +319,8 @@ export async function getProcessBuildersMetadata(
const sobjectSet = new Set(sobjects);
let workflowRuleRecords = (await query<FlowViewRecord>(selectedOrg, getProcessBuildersQuery(), false)).queryResults.records;

let flowIdToSobject: MapOf<string>;
const flowIdToSobjectCache = skipCache ? null : await getCacheItemNonHttp<MapOf<string>>(selectedOrg, PROCESS_BUILDER_CACHE_ID);
let flowIdToSobject: Record<string, string>;
const flowIdToSobjectCache = skipCache ? null : await getCacheItemNonHttp<Record<string, string>>(selectedOrg, PROCESS_BUILDER_CACHE_ID);

if (flowIdToSobjectCache) {
flowIdToSobject = flowIdToSobjectCache.data;
Expand All @@ -338,7 +338,7 @@ export async function getProcessBuildersMetadata(

const definitionIdsBySObject = flowVersionWithMetadata.compositeResponse
.map((item) => item.body)
.reduce((output: MapOf<string>, { Id, DefinitionId, Metadata }) => {
.reduce((output: Record<string, string>, { Id, DefinitionId, Metadata }) => {
try {
if (Metadata) {
let sobject: string | undefined = undefined;
Expand Down Expand Up @@ -497,7 +497,7 @@ export function deployMetadata(
Promise.resolve().then(async () => {
try {
// items with prior errors are not deployed
const idToKeyMap: MapOf<string> = Object.keys(itemsByKey)
const idToKeyMap: Record<string, string> = Object.keys(itemsByKey)
.filter((key) => !itemsByKey[key].deploy.deployError)
.reduce((output, key) => {
output[itemsByKey[key].deploy.id] = key;
Expand Down Expand Up @@ -572,7 +572,8 @@ export async function deployMetadataFileBased(
return null;
}

const deployItems: MapOf<
const deployItems: Record<
string,
{
fullName: string;
dirPath: string;
Expand Down
Loading

0 comments on commit 4927cf9

Please sign in to comment.