fix issues found by sonarqube (#8095)
* fix issues found by sonarqube * fix unit test
This commit is contained in:
parent
b330847d95
commit
5b510cb780
7 changed files with 39 additions and 34 deletions
|
|
@ -454,7 +454,7 @@ export async function fetchPostsSince(serverUrl: string, channelId: string, sinc
|
|||
|
||||
const isCRTEnabled = await getIsCRTEnabled(database);
|
||||
const data = await client.getPostsSince(channelId, since, isCRTEnabled, isCRTEnabled);
|
||||
const result = await processPostsFetched(data);
|
||||
const result = processPostsFetched(data);
|
||||
if (!fetchOnly) {
|
||||
const models = await operator.handlePosts({
|
||||
...result,
|
||||
|
|
|
|||
|
|
@ -524,7 +524,7 @@ export const handleCallsSlashCommand = async (value: string, serverUrl: string,
|
|||
}
|
||||
case 'leave':
|
||||
if (getCurrentCall()?.channelId === channelId) {
|
||||
await leaveCall();
|
||||
leaveCall();
|
||||
return {handled: true};
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ export const recordingAlert = (isHost: boolean, transcriptionsEnabled: boolean,
|
|||
defaultMessage: 'Leave',
|
||||
}),
|
||||
onPress: async () => {
|
||||
await leaveCall();
|
||||
leaveCall();
|
||||
},
|
||||
style: 'destructive',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings![0].app_id).toBe('test_app');
|
||||
expect(result.bindings![0].label).toBeTruthy();
|
||||
expect(result.bindings![0].location).toMatch(/location\/.+/);
|
||||
expect(result!.bindings![0].app_id).toBe('test_app');
|
||||
expect(result!.bindings![0].label).toBeTruthy();
|
||||
expect(result!.bindings![0].location).toMatch(/location\/.+/);
|
||||
});
|
||||
|
||||
it('should remove bindings without app_id', () => {
|
||||
|
|
@ -70,8 +70,8 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].app_id).toBe('sub_app');
|
||||
expect(result!.bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].app_id).toBe('sub_app');
|
||||
});
|
||||
|
||||
it('should remove bindings with empty or whitespace labels', () => {
|
||||
|
|
@ -109,8 +109,8 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].label).toBe('valid_label');
|
||||
expect(result!.bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].label).toBe('valid_label');
|
||||
});
|
||||
|
||||
it('should remove bindings with duplicate labels in COMMAND location', () => {
|
||||
|
|
@ -143,8 +143,8 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].app_id).toBe('sub_app1');
|
||||
expect(result!.bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].app_id).toBe('sub_app1');
|
||||
});
|
||||
|
||||
it('should keep unique labels in IN_POST location', () => {
|
||||
|
|
@ -177,7 +177,7 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.IN_POST);
|
||||
expect(result.bindings).toHaveLength(2);
|
||||
expect(result!.bindings).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should remove invalid sub-bindings without form or submit', () => {
|
||||
|
|
@ -213,9 +213,9 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(2);
|
||||
expect(result.bindings![0].label).toBe('sub_label2');
|
||||
expect(result.bindings![1].label).toBe('sub_label3');
|
||||
expect(result!.bindings).toHaveLength(2);
|
||||
expect(result!.bindings![0].label).toBe('sub_label2');
|
||||
expect(result!.bindings![1].label).toBe('sub_label3');
|
||||
});
|
||||
|
||||
it('should handle forms correctly', () => {
|
||||
|
|
@ -238,8 +238,8 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].form).toBeTruthy();
|
||||
expect(result!.bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].form).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should handle submit calls correctly', () => {
|
||||
|
|
@ -260,8 +260,8 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].submit).toBeTruthy();
|
||||
expect(result!.bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].submit).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should recursively clean sub-bindings', () => {
|
||||
|
|
@ -296,9 +296,9 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].bindings![0].label).toBe('sub_sub_label');
|
||||
expect(result!.bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].bindings![0].label).toBe('sub_sub_label');
|
||||
});
|
||||
|
||||
it('should handle bindings without bindings, form, or submit', () => {
|
||||
|
|
@ -316,7 +316,7 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(0);
|
||||
expect(result!.bindings).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should handle multiple levels of nested bindings correctly', () => {
|
||||
|
|
@ -361,10 +361,10 @@ describe('cleanBinding', () => {
|
|||
};
|
||||
|
||||
const result = cleanBinding(binding, AppBindingLocations.COMMAND);
|
||||
expect(result.bindings).toHaveLength(2);
|
||||
expect(result.bindings![0].bindings).toHaveLength(1);
|
||||
expect(result.bindings![0].bindings![0].label).toBe('sub_sub_label');
|
||||
expect(result.bindings![1].label).toBe('sub_label2');
|
||||
expect(result!.bindings).toHaveLength(2);
|
||||
expect(result!.bindings![0].bindings).toHaveLength(1);
|
||||
expect(result!.bindings![0].bindings![0].label).toBe('sub_sub_label');
|
||||
expect(result!.bindings![1].label).toBe('sub_label2');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ import {AppBindingLocations, AppCallResponseTypes, AppFieldTypes} from '@constan
|
|||
|
||||
import {generateId} from './general';
|
||||
|
||||
export function cleanBinding(binding: AppBinding, topLocation: string): AppBinding {
|
||||
export function cleanBinding(binding: AppBinding, topLocation: string): AppBinding|null {
|
||||
return cleanBindingRec(binding, topLocation, 0);
|
||||
}
|
||||
|
||||
function cleanBindingRec(binding: AppBinding, topLocation: string, depth: number): AppBinding {
|
||||
function cleanBindingRec(binding: AppBinding, topLocation: string, depth: number): AppBinding|null {
|
||||
if (!binding) {
|
||||
return binding;
|
||||
return null;
|
||||
}
|
||||
|
||||
const toRemove: number[] = [];
|
||||
|
|
|
|||
|
|
@ -164,6 +164,10 @@ export function isMainActivity() {
|
|||
return true;
|
||||
}
|
||||
|
||||
function localeCompare(a: string, b: string) {
|
||||
return a.localeCompare(b);
|
||||
}
|
||||
|
||||
export function areBothStringArraysEqual(a: string[], b: string[]) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
|
|
@ -173,8 +177,8 @@ export function areBothStringArraysEqual(a: string[], b: string[]) {
|
|||
return false;
|
||||
}
|
||||
|
||||
const aSorted = a.sort();
|
||||
const bSorted = b.sort();
|
||||
const aSorted = a.sort(localeCompare);
|
||||
const bSorted = b.sort(localeCompare);
|
||||
const areBothEqual = aSorted.every((value, index) => value === bSorted[index]);
|
||||
|
||||
return areBothEqual;
|
||||
|
|
|
|||
|
|
@ -437,7 +437,8 @@ describe('UrlUtils', () => {
|
|||
const onError = jest.fn();
|
||||
const onSuccess = jest.fn();
|
||||
|
||||
await UrlUtils.tryOpenURL(url, onError, onSuccess);
|
||||
UrlUtils.tryOpenURL(url, onError, onSuccess);
|
||||
await TestHelper.wait(100);
|
||||
expect(onError).not.toHaveBeenCalled();
|
||||
expect(onSuccess).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue