Skip to content

Commit

Permalink
wip 2
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed May 20, 2024
1 parent 0f9ab4a commit 2681751
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 31 deletions.
9 changes: 7 additions & 2 deletions .github/actions/javascript/bumpVersion/bumpVersion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';
import {exec as originalExec} from 'child_process';
import fs from 'fs';
import type {PackageJson} from 'type-fest';
import {promisify} from 'util';
import {generateAndroidVersionCode, updateAndroidVersion, updateiOSVersion} from '@github/libs/nativeVersionUpdater';
import * as versionUpdater from '@github/libs/versionUpdater';
Expand Down Expand Up @@ -47,8 +48,12 @@ if (!semanticVersionLevel || !Object.keys(versionUpdater.SEMANTIC_VERSION_LEVELS
console.log(`Invalid input for 'SEMVER_LEVEL': ${semanticVersionLevel}`, `Defaulting to: ${semanticVersionLevel}`);
}

const {version: previousVersion}: {version: string} = JSON.parse(fs.readFileSync('./package.json').toString());
const newVersion = versionUpdater.incrementVersion(previousVersion, semanticVersionLevel);
const {version: previousVersion}: PackageJson = JSON.parse(fs.readFileSync('./package.json').toString());
if (!previousVersion) {
core.setFailed('Error: Could not read package.json');
}

const newVersion = versionUpdater.incrementVersion(previousVersion ?? '', semanticVersionLevel);
console.log(`Previous version: ${previousVersion}`, `New version: ${newVersion}`);

updateNativeVersions(newVersion);
Expand Down
8 changes: 7 additions & 1 deletion src/components/AttachmentPicker/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s
completeAttachmentSelection.current(result);
})
.catch((error) => {
showGeneralAlert(error.message);
let errorMessage;
if (error instanceof Error) {
errorMessage = error.message;
} else {
errorMessage = String(error.message);
}
showGeneralAlert(errorMessage);
throw error;
});
},
Expand Down
5 changes: 3 additions & 2 deletions src/components/Attachments/AttachmentCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
return;
}

const item: Attachment = entry.item;
if (entry.index !== null) {
setPage(entry.index);
setActiveSource(entry.item.source);
setActiveSource(item.source);
}

if (onNavigate) {
onNavigate(entry.item as Attachment);
onNavigate(item);
}
},
[isFullScreenRef, onNavigate],
Expand Down
7 changes: 6 additions & 1 deletion src/components/Onfido/BaseOnfidoWeb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ function initializeOnfido({sdkToken, onSuccess, onError, onUserExit, preferredLo
onSuccess(data);
},
onError: (error) => {
let errorMessage;
if (error instanceof Error) {
errorMessage = error.message;
} else {
errorMessage = CONST.ERROR.UNKNOWN_ERROR;
}
const errorType = error.type;
const errorMessage = error.message ?? CONST.ERROR.UNKNOWN_ERROR;
Log.hmmm('Onfido error', {errorType, errorMessage});
if (errorType === CONST.WALLET.ERROR.ONFIDO_USER_CONSENT_DENIED) {
onUserExit();
Expand Down
9 changes: 7 additions & 2 deletions src/components/Onfido/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ function Onfido({sdkToken, onUserExit, onSuccess, onError}: OnfidoProps) {
})
.then(onSuccess)
.catch((error) => {
const errorMessage = error.message ?? CONST.ERROR.UNKNOWN_ERROR;
let errorMessage: string;
if (error instanceof Error) {
errorMessage = error.message;
} else {
errorMessage = CONST.ERROR.UNKNOWN_ERROR;
}
const errorType = error.type;

Log.hmmm('Onfido error on native', {errorType, errorMessage});

// If the user cancels the Onfido flow we won't log this error as it's normal. In the React Native SDK the user exiting the flow will trigger this error which we can use as
// our "user exited the flow" callback. On web, this event has it's own callback passed as a config so we don't need to bother with this there.
if ([CONST.ONFIDO.ERROR.USER_CANCELLED, CONST.ONFIDO.ERROR.USER_TAPPED_BACK, CONST.ONFIDO.ERROR.USER_EXITED].includes(errorMessage)) {
if (([CONST.ONFIDO.ERROR.USER_CANCELLED, CONST.ONFIDO.ERROR.USER_TAPPED_BACK, CONST.ONFIDO.ERROR.USER_EXITED] as string[]).includes(errorMessage)) {
onUserExit();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SignInButtons/AppleSignIn/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function AppleSignIn() {
appleSignInRequest()
.then((token) => Session.beginAppleSignIn(token))
.catch((e) => {
if (e.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) {
if (e instanceof Error && e.message === appleAuthAndroid.Error.SIGNIN_CANCELLED) {
return null;
}
Log.alert('[Apple Sign In] Apple authentication failed', e);
Expand Down
12 changes: 7 additions & 5 deletions src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {FrequentlyUsedEmoji, Locale} from '@src/types/onyx';
import type {ReportActionReaction, UsersReactions} from '@src/types/onyx/ReportActionReactions';
import type IconAsset from '@src/types/utils/IconAsset';
import type EmojiTrie from './EmojiTrie';
import type {SupportedLanguage} from './EmojiTrie';

type HeaderIndice = {code: string; index: number; icon: IconAsset};
type EmojiSpacer = {code: string; spacer: boolean};
Expand Down Expand Up @@ -312,9 +314,9 @@ function getAddedEmojis(currentEmojis: Emoji[], formerEmojis: Emoji[]): Emoji[]
*/
function replaceEmojis(text: string, preferredSkinTone: OnyxEntry<number | string> = CONST.EMOJI_DEFAULT_SKIN_TONE, lang: Locale = CONST.LOCALES.DEFAULT): ReplacedEmoji {
// emojisTrie is importing the emoji JSON file on the app starting and we want to avoid it
const emojisTrie = require('./EmojiTrie').default;
const emojisTrie: typeof EmojiTrie = require('./EmojiTrie').default;

const trie = emojisTrie[lang];
const trie = emojisTrie[lang as SupportedLanguage];
if (!trie) {
return {text, emojis: []};
}
Expand Down Expand Up @@ -390,9 +392,9 @@ function replaceAndExtractEmojis(text: string, preferredSkinTone: OnyxEntry<numb
*/
function suggestEmojis(text: string, lang: Locale, limit: number = CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_SUGGESTIONS): Emoji[] | undefined {
// emojisTrie is importing the emoji JSON file on the app starting and we want to avoid it
const emojisTrie = require('./EmojiTrie').default;
const emojisTrie: typeof EmojiTrie = require('./EmojiTrie').default;

const trie = emojisTrie[lang];
const trie = emojisTrie[lang as SupportedLanguage];
if (!trie) {
return [];
}
Expand All @@ -411,7 +413,7 @@ function suggestEmojis(text: string, lang: Locale, limit: number = CONST.AUTO_CO
}
matching.push({code: node.metaData.code, name: node.name, types: node.metaData.types});
}
const suggestions: Emoji[] | undefined = node.metaData.suggestions;
const suggestions = node.metaData.suggestions;
if (!suggestions) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Localize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Phrase<TKey extends TranslationPaths> = TranslationFlatObject[TKey] extends
*/
const translationCache = new Map<ValueOf<typeof CONST.LOCALES>, Map<TranslationPaths, string>>(
Object.values(CONST.LOCALES).reduce((cache, locale) => {
cache.push([locale, new Map()]);
cache.push([locale, new Map<TranslationPaths, string>()]);
return cache;
}, [] as Array<[ValueOf<typeof CONST.LOCALES>, Map<TranslationPaths, string>]>),
);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Pusher/pusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function bindEventToChannel<EventName extends PusherEventName>(channel: Channel
// packet.
if (chunkedEvent.receivedFinal && chunkedEvent.chunks.length === Object.keys(chunkedEvent.chunks).length) {
try {
eventCallback(JSON.parse(chunkedEvent.chunks.join('')));
eventCallback(JSON.parse(chunkedEvent.chunks.join('')) as EventData<EventName>);
} catch (err) {
Log.alert('[Pusher] Unable to parse chunked JSON response from Pusher', {
error: err,
Expand Down
10 changes: 9 additions & 1 deletion src/libs/actions/Device/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ function setDeviceID() {
Log.info('Got new deviceID', false, uniqueID);
Onyx.set(ONYXKEYS.DEVICE_ID, uniqueID);
})
.catch((err) => Log.info('Found existing deviceID', false, err.message));
.catch((err) => {
let errorMessage;
if (err instanceof Error) {
errorMessage = err.message;
} else {
errorMessage = String(err.message);
}
Log.info('Found existing deviceID', false, errorMessage);
});
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ const createServerInstance = (): ServerInstance => {
res.end('Error executing command');
})
.catch((error) => {
Logger.error('Error executing command', error);
let errorString;
if (error instanceof Error) {
errorString = error.toString();
} else {
errorString = String(error);
}
Logger.error('Error executing command', errorString);
res.statusCode = 500;
res.end('Error executing command');
});
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const createAddListenerMock = (): ListenerMock => {
transitionEndListeners.forEach((transitionEndListener) => transitionEndListener());
};

const addListener: jest.Mock = jest.fn().mockImplementation((listener, callback) => {
const addListener: jest.Mock = jest.fn().mockImplementation((listener, callback: () => void) => {
if (listener === 'transitionEnd') {
transitionEndListeners.push(callback);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/MiddlewareTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('Middleware', () => {

expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch).toHaveBeenLastCalledWith('https://www.expensify.com.dev/api/AddComment?', expect.anything());
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[1][1].body, {reportID: '1234', reportActionID: '5678'});
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[1][1].body as TestHelper.FormData, {reportID: '1234', reportActionID: '5678'});
expect(global.fetch).toHaveBeenNthCalledWith(1, 'https://www.expensify.com.dev/api/OpenReport?', expect.anything());
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[0][1].body, {reportID: '1234'});
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[0][1].body as TestHelper.FormData, {reportID: '1234'});
});

test('Request with preexistingReportID', async () => {
Expand Down Expand Up @@ -93,9 +93,9 @@ describe('Middleware', () => {

expect(global.fetch).toHaveBeenCalledTimes(2);
expect(global.fetch).toHaveBeenLastCalledWith('https://www.expensify.com.dev/api/AddComment?', expect.anything());
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[1][1].body, {reportID: '5555', reportActionID: '5678'});
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[1][1].body as TestHelper.FormData, {reportID: '5555', reportActionID: '5678'});
expect(global.fetch).toHaveBeenNthCalledWith(1, 'https://www.expensify.com.dev/api/OpenReport?', expect.anything());
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[0][1].body, {reportID: '1234'});
TestHelper.assertFormDataMatchesObject((global.fetch as jest.Mock).mock.calls[0][1].body as TestHelper.FormData, {reportID: '1234'});
});
});
});
6 changes: 3 additions & 3 deletions tests/unit/markPullRequestsAsDeployedTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ platform | result
});

it('comments on pull requests correctly for a standard production deploy', async () => {
mockGetInput.mockImplementation((key) => {
mockGetInput.mockImplementation((key: string) => {
if (key === 'IS_PRODUCTION_DEPLOY') {
return true;
}
Expand Down Expand Up @@ -226,7 +226,7 @@ platform | result
});

it('comments on pull requests correctly for a cherry pick', async () => {
mockGetInput.mockImplementation((key) => {
mockGetInput.mockImplementation((key: string) => {
if (key === 'PR_LIST') {
return JSON.stringify([3]);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ platform | result
});

it('comments on pull requests correctly when one platform fails', async () => {
mockGetInput.mockImplementation((key) => {
mockGetInput.mockImplementation((key: string) => {
if (key === 'ANDROID') {
return 'skipped';
}
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/TestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const createAddListenerMock = () => {
transitionEndListeners.forEach((transitionEndListener) => transitionEndListener());
};

const addListener = jest.fn().mockImplementation((listener, callback) => {
const addListener = jest.fn().mockImplementation((listener, callback: Listener) => {
if (listener === 'transitionEnd') {
transitionEndListeners.push(callback);
}
Expand All @@ -242,5 +242,5 @@ const createAddListenerMock = () => {
return {triggerTransitionEnd, addListener};
};

export type {MockFetch};
export type {MockFetch, FormData};
export {assertFormDataMatchesObject, buildPersonalDetails, buildTestReportComment, createAddListenerMock, getGlobalFetchMock, setPersonalDetails, signInWithTestUser, signOutTestUser};
4 changes: 2 additions & 2 deletions workflow_tests/utils/ExtendedAct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class ExtendedAct extends Act {
if (opts.workflowFile) {
workflowFiles = [path.basename(opts.workflowFile)];
} else if (this['workflowFile'] !== this['cwd']) {
workflowFiles = [path.basename(this['workflowFile'])];
workflowFiles = [path.basename(this['workflowFile'] as string)];
} else {
const availableWorkflows = await this.list(undefined, opts.cwd, opts.workflowFile);
workflowFiles = availableWorkflows.filter(filter).map((workflow: Workflow) => workflow.workflowFile);
}

return workflowFiles.map((workflowFile) => {
const jobMocker = new JobMocker(workflowFile, opts.cwd ?? this['cwd']);
const jobMocker = new JobMocker(workflowFile, opts.cwd ?? (this['cwd'] as string));
return jobMocker.mock(opts.mockJobs);
});
}
Expand Down
2 changes: 1 addition & 1 deletion workflow_tests/utils/preGenerateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ checkIfMocksFileExists(workflowTestMocksDirectory, workflowTestMocksFileName);
const workflowTestAssertionsFileName = `${workflowName}Assertions.ts`;
checkIfAssertionsFileExists(workflowTestAssertionsDirectory, workflowTestAssertionsFileName);

const workflow = yaml.parse(fs.readFileSync(workflowFilePath, 'utf8'));
const workflow: YamlWorkflow = yaml.parse(fs.readFileSync(workflowFilePath, 'utf8'));
const workflowJobs = parseWorkflowFile(workflow);

const mockFileContent = getMockFileContent(workflowName, workflowJobs);
Expand Down

0 comments on commit 2681751

Please sign in to comment.