mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
refactor: Async functions don't need to explicitly return promises (no-changelog) (#6041)
This commit is contained in:
parent
03be725cef
commit
308a94311f
|
@ -542,10 +542,10 @@ export class CredentialsHelper extends ICredentialsHelper {
|
|||
): Promise<INodeCredentialTestResult> {
|
||||
const credentialTestFunction = this.getCredentialTestFunction(credentialType);
|
||||
if (credentialTestFunction === undefined) {
|
||||
return Promise.resolve({
|
||||
return {
|
||||
status: 'Error',
|
||||
message: 'No testing function found for this credential.',
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
if (credentialsDecrypted.data) {
|
||||
|
|
|
@ -271,12 +271,12 @@ export class InternalHooks implements IInternalHooksClass {
|
|||
runData?: IRun,
|
||||
userId?: string,
|
||||
): Promise<void> {
|
||||
const promises = [Promise.resolve()];
|
||||
|
||||
if (!workflow.id) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
|
||||
const properties: IExecutionTrackProperties = {
|
||||
workflow_id: workflow.id,
|
||||
is_manual: false,
|
||||
|
|
|
@ -82,7 +82,7 @@ export class LdapService {
|
|||
await this.client.unbind();
|
||||
return searchEntries;
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ export class PostHogClient {
|
|||
}
|
||||
|
||||
async getFeatureFlags(user: Pick<PublicUser, 'id' | 'createdAt'>): Promise<FeatureFlags> {
|
||||
if (!this.postHog) return Promise.resolve({});
|
||||
if (!this.postHog) return {};
|
||||
|
||||
const fullId = [this.instanceId, user.id].join('#');
|
||||
|
||||
|
|
|
@ -73,9 +73,8 @@ export class SamlService {
|
|||
validate: async (response: string) => {
|
||||
const valid = await validateResponse(response);
|
||||
if (!valid) {
|
||||
return Promise.reject(new Error('Invalid SAML response'));
|
||||
throw new Error('Invalid SAML response');
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ export class Telemetry {
|
|||
|
||||
private async pulse(): Promise<unknown> {
|
||||
if (!this.rudderStack) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const allPromises = Object.keys(this.executionCountsBuffer).map(async (workflowId) => {
|
||||
|
|
|
@ -205,9 +205,7 @@ test('GET /ldap/config route should retrieve current configuration', async () =>
|
|||
|
||||
describe('POST /ldap/test-connection', () => {
|
||||
test('route should success', async () => {
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'testConnection')
|
||||
.mockImplementation(async () => Promise.resolve());
|
||||
jest.spyOn(LdapService.prototype, 'testConnection').mockResolvedValue();
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/test-connection');
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
@ -216,9 +214,7 @@ describe('POST /ldap/test-connection', () => {
|
|||
test('route should fail', async () => {
|
||||
const errorMessage = 'Invalid connection';
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'testConnection')
|
||||
.mockImplementation(async () => Promise.reject(new Error(errorMessage)));
|
||||
jest.spyOn(LdapService.prototype, 'testConnection').mockRejectedValue(new Error(errorMessage));
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/test-connection');
|
||||
expect(response.statusCode).toBe(400);
|
||||
|
@ -240,9 +236,7 @@ describe('POST /ldap/sync', () => {
|
|||
|
||||
describe('dry mode', () => {
|
||||
const runTest = async (ldapUsers: LdapUser[]) => {
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve(ldapUsers));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue(ldapUsers);
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/sync').send({ type: 'dry' });
|
||||
|
||||
|
@ -337,9 +331,7 @@ describe('POST /ldap/sync', () => {
|
|||
|
||||
describe('live mode', () => {
|
||||
const runTest = async (ldapUsers: LdapUser[]) => {
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve(ldapUsers));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue(ldapUsers);
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/sync').send({ type: 'live' });
|
||||
|
||||
|
@ -467,9 +459,7 @@ describe('POST /ldap/sync', () => {
|
|||
test('should remove user instance access once the user is disabled during synchronization', async () => {
|
||||
const member = await testDb.createLdapUser({ globalRole: globalMemberRole }, uniqueId());
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve([]));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue([]);
|
||||
|
||||
await authAgent(owner).post('/ldap/sync').send({ type: 'live' });
|
||||
|
||||
|
@ -508,13 +498,9 @@ describe('POST /login', () => {
|
|||
|
||||
const authlessAgent = utils.createAgent(app);
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve([ldapUser]));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue([ldapUser]);
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'validUser')
|
||||
.mockImplementation(async () => Promise.resolve());
|
||||
jest.spyOn(LdapService.prototype, 'validUser').mockResolvedValue();
|
||||
|
||||
const response = await authlessAgent
|
||||
.post('/login')
|
||||
|
|
|
@ -799,11 +799,11 @@ export function installedNodePayload(packageName: string): InstalledNodePayload
|
|||
};
|
||||
}
|
||||
|
||||
export const emptyPackage = () => {
|
||||
export const emptyPackage = async () => {
|
||||
const installedPackage = new InstalledPackages();
|
||||
installedPackage.installedNodes = [];
|
||||
|
||||
return Promise.resolve(installedPackage);
|
||||
return installedPackage;
|
||||
};
|
||||
|
||||
// ----------------------------------
|
||||
|
|
|
@ -18,7 +18,7 @@ jest.mock('@/Db', () => {
|
|||
return {
|
||||
collections: {
|
||||
Execution: {
|
||||
save: jest.fn(async () => Promise.resolve({ id: FAKE_EXECUTION_ID })),
|
||||
save: jest.fn(async () => ({ id: FAKE_EXECUTION_ID })),
|
||||
update: jest.fn(),
|
||||
},
|
||||
},
|
||||
|
|
|
@ -99,12 +99,11 @@ jest.mock('@/Db', () => {
|
|||
return {
|
||||
collections: {
|
||||
Workflow: {
|
||||
find: jest.fn(async () => Promise.resolve(generateWorkflows(databaseActiveWorkflowsCount))),
|
||||
find: jest.fn(async () => generateWorkflows(databaseActiveWorkflowsCount)),
|
||||
findOne: jest.fn(async (searchParams) => {
|
||||
const foundWorkflow = databaseActiveWorkflowsList.find(
|
||||
return databaseActiveWorkflowsList.find(
|
||||
(workflow) => workflow.id.toString() === searchParams.where.id.toString(),
|
||||
);
|
||||
return Promise.resolve(foundWorkflow);
|
||||
}),
|
||||
update: jest.fn(),
|
||||
createQueryBuilder: jest.fn(() => {
|
||||
|
@ -112,7 +111,7 @@ jest.mock('@/Db', () => {
|
|||
update: () => fakeQueryBuilder,
|
||||
set: () => fakeQueryBuilder,
|
||||
where: () => fakeQueryBuilder,
|
||||
execute: () => Promise.resolve(),
|
||||
execute: async () => {},
|
||||
};
|
||||
return fakeQueryBuilder;
|
||||
}),
|
||||
|
@ -246,7 +245,7 @@ describe('ActiveWorkflowRunner', () => {
|
|||
const workflow = generateWorkflows(1);
|
||||
const additionalData = await WorkflowExecuteAdditionalData.getBase('fake-user-id');
|
||||
|
||||
workflowRunnerRun.mockImplementationOnce(() => Promise.resolve('invalid-execution-id'));
|
||||
workflowRunnerRun.mockResolvedValueOnce('invalid-execution-id');
|
||||
|
||||
await activeWorkflowRunner.runWorkflow(
|
||||
workflow[0],
|
||||
|
|
|
@ -6,7 +6,7 @@ jest.mock('@/Db', () => {
|
|||
return {
|
||||
collections: {
|
||||
ExecutionMetadata: {
|
||||
save: jest.fn(async () => Promise.resolve([])),
|
||||
save: jest.fn(async () => []),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -134,63 +134,58 @@ export class BinaryDataFileSystem implements IBinaryDataManager {
|
|||
|
||||
const execsAdded: { [key: string]: number } = {};
|
||||
|
||||
const proms = metaFileNames.reduce(
|
||||
(prev, curr) => {
|
||||
const [prefix, executionId, ts] = curr.split('_');
|
||||
const promises = metaFileNames.reduce<Array<Promise<void>>>((prev, curr) => {
|
||||
const [prefix, executionId, ts] = curr.split('_');
|
||||
|
||||
if (prefix !== filePrefix) {
|
||||
if (prefix !== filePrefix) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
const execTimestamp = parseInt(ts, 10);
|
||||
|
||||
if (execTimestamp < currentTimeValue) {
|
||||
if (execsAdded[executionId]) {
|
||||
// do not delete data, only meta file
|
||||
prev.push(this.deleteMetaFileByPath(path.join(metaPath, curr)));
|
||||
return prev;
|
||||
}
|
||||
|
||||
const execTimestamp = parseInt(ts, 10);
|
||||
execsAdded[executionId] = 1;
|
||||
prev.push(
|
||||
this.deleteBinaryDataByExecutionId(executionId).then(async () =>
|
||||
this.deleteMetaFileByPath(path.join(metaPath, curr)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (execTimestamp < currentTimeValue) {
|
||||
if (execsAdded[executionId]) {
|
||||
// do not delete data, only meta file
|
||||
prev.push(this.deleteMetaFileByPath(path.join(metaPath, curr)));
|
||||
return prev;
|
||||
}
|
||||
return prev;
|
||||
}, []);
|
||||
|
||||
execsAdded[executionId] = 1;
|
||||
prev.push(
|
||||
this.deleteBinaryDataByExecutionId(executionId).then(async () =>
|
||||
this.deleteMetaFileByPath(path.join(metaPath, curr)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return prev;
|
||||
},
|
||||
[Promise.resolve()],
|
||||
);
|
||||
|
||||
return Promise.all(proms).then(() => {});
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
async duplicateBinaryDataByIdentifier(binaryDataId: string, prefix: string): Promise<string> {
|
||||
const newBinaryDataId = this.generateFileName(prefix);
|
||||
|
||||
return fs
|
||||
.copyFile(this.resolveStoragePath(binaryDataId), this.resolveStoragePath(newBinaryDataId))
|
||||
.then(() => newBinaryDataId);
|
||||
await fs.copyFile(
|
||||
this.resolveStoragePath(binaryDataId),
|
||||
this.resolveStoragePath(newBinaryDataId),
|
||||
);
|
||||
return newBinaryDataId;
|
||||
}
|
||||
|
||||
async deleteBinaryDataByExecutionId(executionId: string): Promise<void> {
|
||||
const regex = new RegExp(`${executionId}_*`);
|
||||
const filenames = await fs.readdir(this.storagePath);
|
||||
|
||||
const proms = filenames.reduce(
|
||||
(allProms, filename) => {
|
||||
if (regex.test(filename)) {
|
||||
allProms.push(fs.rm(this.resolveStoragePath(filename)));
|
||||
}
|
||||
const promises = filenames.reduce<Array<Promise<void>>>((allProms, filename) => {
|
||||
if (regex.test(filename)) {
|
||||
allProms.push(fs.rm(this.resolveStoragePath(filename)));
|
||||
}
|
||||
return allProms;
|
||||
}, []);
|
||||
|
||||
return allProms;
|
||||
},
|
||||
[Promise.resolve()],
|
||||
);
|
||||
|
||||
return Promise.all(proms).then(async () => Promise.resolve());
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
async deleteBinaryDataByIdentifier(identifier: string): Promise<void> {
|
||||
|
@ -198,20 +193,17 @@ export class BinaryDataFileSystem implements IBinaryDataManager {
|
|||
}
|
||||
|
||||
async persistBinaryDataForExecutionId(executionId: string): Promise<void> {
|
||||
return fs.readdir(this.getBinaryDataPersistMetaPath()).then(async (metafiles) => {
|
||||
const proms = metafiles.reduce(
|
||||
(prev, curr) => {
|
||||
if (curr.startsWith(`${PREFIX_PERSISTED_METAFILE}_${executionId}_`)) {
|
||||
prev.push(fs.rm(path.join(this.getBinaryDataPersistMetaPath(), curr)));
|
||||
return prev;
|
||||
}
|
||||
|
||||
return fs.readdir(this.getBinaryDataPersistMetaPath()).then(async (metaFiles) => {
|
||||
const promises = metaFiles.reduce<Array<Promise<void>>>((prev, curr) => {
|
||||
if (curr.startsWith(`${PREFIX_PERSISTED_METAFILE}_${executionId}_`)) {
|
||||
prev.push(fs.rm(path.join(this.getBinaryDataPersistMetaPath(), curr)));
|
||||
return prev;
|
||||
},
|
||||
[Promise.resolve()],
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.all(proms).then(() => {});
|
||||
return prev;
|
||||
}, []);
|
||||
|
||||
await Promise.all(promises);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -227,8 +219,8 @@ export class BinaryDataFileSystem implements IBinaryDataManager {
|
|||
return path.join(this.storagePath, 'persistMeta');
|
||||
}
|
||||
|
||||
private async deleteMetaFileByPath(metafilePath: string): Promise<void> {
|
||||
return fs.rm(metafilePath);
|
||||
private async deleteMetaFileByPath(metaFilePath: string): Promise<void> {
|
||||
return fs.rm(metaFilePath);
|
||||
}
|
||||
|
||||
private async deleteFromLocalStorage(identifier: string) {
|
||||
|
|
|
@ -158,38 +158,30 @@ export class BinaryDataManager {
|
|||
|
||||
async markDataForDeletionByExecutionId(executionId: string): Promise<void> {
|
||||
if (this.managers[this.binaryDataMode]) {
|
||||
return this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(executionId);
|
||||
await this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(executionId);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async markDataForDeletionByExecutionIds(executionIds: string[]): Promise<void> {
|
||||
if (this.managers[this.binaryDataMode]) {
|
||||
return Promise.all(
|
||||
await Promise.all(
|
||||
executionIds.map(async (id) =>
|
||||
this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(id),
|
||||
),
|
||||
).then(() => {});
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async persistBinaryDataForExecutionId(executionId: string): Promise<void> {
|
||||
if (this.managers[this.binaryDataMode]) {
|
||||
return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
|
||||
await this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async deleteBinaryDataByExecutionId(executionId: string): Promise<void> {
|
||||
if (this.managers[this.binaryDataMode]) {
|
||||
return this.managers[this.binaryDataMode].deleteBinaryDataByExecutionId(executionId);
|
||||
await this.managers[this.binaryDataMode].deleteBinaryDataByExecutionId(executionId);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async duplicateBinaryData(
|
||||
|
@ -218,7 +210,7 @@ export class BinaryDataManager {
|
|||
return Promise.all(returnInputData);
|
||||
}
|
||||
|
||||
return Promise.resolve(inputData as INodeExecutionData[][]);
|
||||
return inputData as INodeExecutionData[][];
|
||||
}
|
||||
|
||||
private generateBinaryId(filename: string) {
|
||||
|
|
|
@ -792,7 +792,7 @@ export class WorkflowExecute {
|
|||
}
|
||||
|
||||
if (gotCancel) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
nodeSuccessData = null;
|
||||
|
@ -919,7 +919,7 @@ export class WorkflowExecute {
|
|||
|
||||
for (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {
|
||||
if (gotCancel) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (tryIndex !== 0) {
|
||||
|
@ -1175,10 +1175,8 @@ export class WorkflowExecute {
|
|||
outputIndex
|
||||
]) {
|
||||
if (!workflow.nodes.hasOwnProperty(connectionData.node)) {
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
`The node "${executionNode.name}" connects to not found node "${connectionData.node}"`,
|
||||
),
|
||||
throw new Error(
|
||||
`The node "${executionNode.name}" connects to not found node "${connectionData.node}"`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1212,7 +1210,7 @@ export class WorkflowExecute {
|
|||
]);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
return;
|
||||
})()
|
||||
.then(async () => {
|
||||
if (gotCancel && executionError === undefined) {
|
||||
|
|
|
@ -527,15 +527,12 @@ export default mixins(externalHooks, genericHelpers, executionHelpers, showMessa
|
|||
// Suppose 504 finishes before 500, 501, 502 and 503.
|
||||
// iF you use firstId, filtering id >= 504 you won't
|
||||
// ever get ids 500, 501, 502 and 503 when they finish
|
||||
const pastExecutionsPromise: Promise<IExecutionsListResponse> =
|
||||
this.workflowsStore.getPastExecutions(filter, this.requestItemsPerRequest);
|
||||
const currentExecutionsPromise: Promise<IExecutionsCurrentSummaryExtended[]> = isEmpty(
|
||||
filter.metadata,
|
||||
)
|
||||
? this.workflowsStore.getCurrentExecutions({})
|
||||
: Promise.resolve([]);
|
||||
const promises = [this.workflowsStore.getPastExecutions(filter, this.requestItemsPerRequest)];
|
||||
if (isEmpty(filter.metadata)) {
|
||||
promises.push(this.workflowsStore.getCurrentExecutions({}));
|
||||
}
|
||||
|
||||
const results = await Promise.all([pastExecutionsPromise, currentExecutionsPromise]);
|
||||
const results = await Promise.all(promises);
|
||||
|
||||
for (const activeExecution of results[1]) {
|
||||
if (
|
||||
|
|
|
@ -250,7 +250,7 @@ export default mixins(showMessage, debounceHelper).extend({
|
|||
},
|
||||
initialize: {
|
||||
type: Function as PropType<() => Promise<void>>,
|
||||
default: () => () => Promise.resolve(),
|
||||
default: () => async () => {},
|
||||
},
|
||||
filters: {
|
||||
type: Object,
|
||||
|
|
|
@ -460,7 +460,7 @@ export const workflowHelpers = mixins(externalHooks, nodeHelpers, showMessage).e
|
|||
},
|
||||
|
||||
// Returns the currently loaded workflow as JSON.
|
||||
getWorkflowDataToSave(): Promise<IWorkflowData> {
|
||||
async getWorkflowDataToSave(): Promise<IWorkflowData> {
|
||||
const workflowNodes = this.workflowsStore.allNodes;
|
||||
const workflowConnections = this.workflowsStore.allConnections;
|
||||
|
||||
|
@ -468,12 +468,8 @@ export const workflowHelpers = mixins(externalHooks, nodeHelpers, showMessage).e
|
|||
|
||||
const nodes = [];
|
||||
for (let nodeIndex = 0; nodeIndex < workflowNodes.length; nodeIndex++) {
|
||||
try {
|
||||
// @ts-ignore
|
||||
nodeData = this.getNodeDataToSave(workflowNodes[nodeIndex]);
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
// @ts-ignore
|
||||
nodeData = this.getNodeDataToSave(workflowNodes[nodeIndex]);
|
||||
|
||||
nodes.push(nodeData);
|
||||
}
|
||||
|
@ -494,7 +490,7 @@ export const workflowHelpers = mixins(externalHooks, nodeHelpers, showMessage).e
|
|||
data.id = workflowId;
|
||||
}
|
||||
|
||||
return Promise.resolve(data);
|
||||
return data;
|
||||
},
|
||||
|
||||
// Returns all node-types
|
||||
|
|
|
@ -535,14 +535,16 @@ function setLanguage(language: string) {
|
|||
}
|
||||
|
||||
export async function loadLanguage(language?: string) {
|
||||
if (!language) return Promise.resolve();
|
||||
if (!language) return;
|
||||
|
||||
if (i18nInstance.locale === language) {
|
||||
return Promise.resolve(setLanguage(language));
|
||||
setLanguage(language);
|
||||
return;
|
||||
}
|
||||
|
||||
if (loadedLanguages.includes(language)) {
|
||||
return Promise.resolve(setLanguage(language));
|
||||
setLanguage(language);
|
||||
return;
|
||||
}
|
||||
|
||||
const { numberFormats, ...rest } = (await import(`./locales/${language}.json`)).default;
|
||||
|
|
|
@ -243,27 +243,23 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
|
|||
},
|
||||
async fetchPromptsData(): Promise<void> {
|
||||
if (!this.isTelemetryEnabled) {
|
||||
Promise.resolve();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const uiStore = useUIStore();
|
||||
const usersStore = useUsersStore();
|
||||
const promptsData: IN8nPrompts = await getPromptsData(
|
||||
this.settings.instanceId,
|
||||
usersStore.currentUserId || '',
|
||||
);
|
||||
|
||||
if (promptsData && promptsData.showContactPrompt) {
|
||||
uiStore.openModal(CONTACT_PROMPT_MODAL_KEY);
|
||||
} else if (promptsData && promptsData.showValueSurvey) {
|
||||
uiStore.openModal(VALUE_SURVEY_MODAL_KEY);
|
||||
}
|
||||
const uiStore = useUIStore();
|
||||
const usersStore = useUsersStore();
|
||||
const promptsData: IN8nPrompts = await getPromptsData(
|
||||
this.settings.instanceId,
|
||||
usersStore.currentUserId || '',
|
||||
);
|
||||
|
||||
this.setPromptsData(promptsData);
|
||||
Promise.resolve();
|
||||
} catch (error) {
|
||||
Promise.reject(error);
|
||||
if (promptsData && promptsData.showContactPrompt) {
|
||||
uiStore.openModal(CONTACT_PROMPT_MODAL_KEY);
|
||||
} else if (promptsData && promptsData.showValueSurvey) {
|
||||
uiStore.openModal(VALUE_SURVEY_MODAL_KEY);
|
||||
}
|
||||
|
||||
this.setPromptsData(promptsData);
|
||||
},
|
||||
async submitContactInfo(email: string): Promise<IN8nPromptResponse | undefined> {
|
||||
try {
|
||||
|
|
|
@ -445,7 +445,7 @@ export default mixins(
|
|||
}
|
||||
} else if (confirmModal === MODAL_CANCEL) {
|
||||
this.workflowsStore.setWorkflowId(PLACEHOLDER_EMPTY_WORKFLOW_ID);
|
||||
await this.resetWorkspace();
|
||||
this.resetWorkspace();
|
||||
this.uiStore.stateIsDirty = false;
|
||||
next();
|
||||
}
|
||||
|
@ -2529,7 +2529,7 @@ export default mixins(
|
|||
},
|
||||
async newWorkflow(): Promise<void> {
|
||||
this.startLoading();
|
||||
await this.resetWorkspace();
|
||||
this.resetWorkspace();
|
||||
this.workflowData = await this.workflowsStore.getNewWorkflowData();
|
||||
this.workflowsStore.currentWorkflowExecutions = [];
|
||||
this.workflowsStore.activeWorkflowExecution = null;
|
||||
|
@ -2551,7 +2551,7 @@ export default mixins(
|
|||
// In case the workflow got saved we do not have to run init
|
||||
// as only the route changed but all the needed data is already loaded
|
||||
this.uiStore.stateIsDirty = false;
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
if (this.blankRedirect) {
|
||||
this.blankRedirect = false;
|
||||
|
@ -2573,7 +2573,7 @@ export default mixins(
|
|||
const saved = await this.saveCurrentWorkflow();
|
||||
if (saved) await this.settingsStore.fetchPromptsData();
|
||||
} else if (confirmModal === MODAL_CLOSE) {
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Load a workflow
|
||||
|
@ -3473,7 +3473,7 @@ export default mixins(
|
|||
connections: tempWorkflow.connectionsBySourceNode,
|
||||
};
|
||||
},
|
||||
getSelectedNodesToSave(): Promise<IWorkflowData> {
|
||||
async getSelectedNodesToSave(): Promise<IWorkflowData> {
|
||||
const data: IWorkflowData = {
|
||||
nodes: [],
|
||||
connections: {},
|
||||
|
@ -3484,12 +3484,8 @@ export default mixins(
|
|||
const exportNodeNames: string[] = [];
|
||||
|
||||
for (const node of this.uiStore.getSelectedNodes) {
|
||||
try {
|
||||
nodeData = this.getNodeDataToSave(node);
|
||||
exportNodeNames.push(node.name);
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
nodeData = this.getNodeDataToSave(node);
|
||||
exportNodeNames.push(node.name);
|
||||
|
||||
data.nodes.push(nodeData);
|
||||
}
|
||||
|
@ -3539,7 +3535,7 @@ export default mixins(
|
|||
}
|
||||
});
|
||||
|
||||
return Promise.resolve(data);
|
||||
return data;
|
||||
},
|
||||
resetWorkspace() {
|
||||
this.workflowsStore.resetWorkflow();
|
||||
|
@ -3581,7 +3577,6 @@ export default mixins(
|
|||
this.uiStore.nodeViewOffsetPosition = [0, 0];
|
||||
|
||||
this.credentialsUpdated = false;
|
||||
return Promise.resolve();
|
||||
},
|
||||
async loadActiveWorkflows(): Promise<void> {
|
||||
await this.workflowsStore.fetchActiveWorkflows();
|
||||
|
|
|
@ -88,7 +88,7 @@ export class Code implements INodeType {
|
|||
try {
|
||||
result = await sandbox.runCodeAllItems();
|
||||
} catch (error) {
|
||||
if (!this.continueOnFail()) return Promise.reject(error);
|
||||
if (!this.continueOnFail()) throw error;
|
||||
result = [{ json: { error: error.message } }];
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ export class Code implements INodeType {
|
|||
try {
|
||||
result = await sandbox.runCodeEachItem(index);
|
||||
} catch (error) {
|
||||
if (!this.continueOnFail()) return Promise.reject(error);
|
||||
if (!this.continueOnFail()) throw error;
|
||||
returnData.push({ json: { error: error.message } });
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ return items;`,
|
|||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -208,14 +208,14 @@ return item;`,
|
|||
const lineNumber = lineParts.splice(-2, 1);
|
||||
if (!isNaN(lineNumber as number)) {
|
||||
error.message = `${error.message} [Line ${lineNumber} | Item Index: ${itemIndex}]`;
|
||||
return Promise.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error.message = `${error.message} [Item Index: ${itemIndex}]`;
|
||||
|
||||
return Promise.reject(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,17 +13,13 @@ async function processCampaignSearchResponse(
|
|||
): Promise<INodeExecutionData[]> {
|
||||
const results = (responseData.body as IDataObject).results as GoogleAdsCampaignElement;
|
||||
|
||||
return Promise.resolve(
|
||||
results.map((result) => {
|
||||
return {
|
||||
json: {
|
||||
...result.campaign,
|
||||
...result.metrics,
|
||||
...result.campaignBudget,
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
return results.map((result) => ({
|
||||
json: {
|
||||
...result.campaign,
|
||||
...result.metrics,
|
||||
...result.campaignBudget,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
export const campaignOperations: INodeProperties[] = [
|
||||
|
|
|
@ -14,21 +14,20 @@ jest.mock('../../../v2/transport', () => {
|
|||
...originalModule,
|
||||
googleApiRequest: jest.fn(async (method: string, resource: string) => {
|
||||
if (resource === '/v2/projects/test-project/jobs' && method === 'POST') {
|
||||
return Promise.resolve({
|
||||
return {
|
||||
jobReference: {
|
||||
jobId: 'job_123',
|
||||
},
|
||||
status: {
|
||||
state: 'DONE',
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
if (resource === '/v2/projects/test-project/queries/job_123' && method === 'GET') {
|
||||
return Promise.resolve({});
|
||||
return {};
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
// googleApiRequestAllItems: jest.fn(async () => Promise.resolve()),
|
||||
// googleApiRequestAllItems: jest.fn(async () => {}),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -17,25 +17,24 @@ jest.mock('../../../v2/transport', () => {
|
|||
'/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text' &&
|
||||
method === 'GET'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
return {
|
||||
schema: {
|
||||
fields: [
|
||||
{ name: 'id', type: 'INT' },
|
||||
{ name: 'test', type: 'STRING' },
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
if (
|
||||
resource ===
|
||||
'/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text/insertAll' &&
|
||||
method === 'POST'
|
||||
) {
|
||||
return Promise.resolve({ kind: 'bigquery#tableDataInsertAllResponse' });
|
||||
return { kind: 'bigquery#tableDataInsertAllResponse' };
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
googleApiRequestAllItems: jest.fn(async () => Promise.resolve()),
|
||||
googleApiRequestAllItems: jest.fn(async () => {}),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ jest.mock('../../../v2/transport', () => {
|
|||
'/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json' &&
|
||||
method === 'GET'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
return {
|
||||
schema: {
|
||||
fields: [
|
||||
{ name: 'json', type: 'JSON' },
|
||||
|
@ -25,22 +25,21 @@ jest.mock('../../../v2/transport', () => {
|
|||
{ name: 'active', type: 'BOOLEAN' },
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
if (
|
||||
resource ===
|
||||
'/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json/insertAll' &&
|
||||
method === 'POST'
|
||||
) {
|
||||
return Promise.resolve({ kind: 'bigquery#tableDataInsertAllResponse' });
|
||||
return { kind: 'bigquery#tableDataInsertAllResponse' };
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
googleApiRequestAllItems: jest.fn(async () => Promise.resolve()),
|
||||
googleApiRequestAllItems: jest.fn(async () => {}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test Google BigQuery V2, insert define manualy', () => {
|
||||
describe('Test Google BigQuery V2, insert define manually', () => {
|
||||
const workflows = ['nodes/Google/BigQuery/test/v2/node/insert.manualMode.workflow.json'];
|
||||
const tests = workflowToTests(workflows);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ const fakeConnection = {
|
|||
format(query: string, values: any[]) {
|
||||
return mysql2.format(query, values);
|
||||
},
|
||||
query: jest.fn(async (_query = ''): Promise<any> => Promise.resolve([{}])),
|
||||
query: jest.fn(async (_query = '') => [{}]),
|
||||
release: jest.fn(),
|
||||
beginTransaction: jest.fn(),
|
||||
commit: jest.fn(),
|
||||
|
@ -41,7 +41,7 @@ const createFakePool = (connection: IDataObject) => {
|
|||
getConnection() {
|
||||
return connection;
|
||||
},
|
||||
query: jest.fn(async () => Promise.resolve([{}])),
|
||||
query: jest.fn(async () => [{}]),
|
||||
} as unknown as Mysql2Pool;
|
||||
};
|
||||
|
||||
|
@ -214,7 +214,7 @@ describe('Test MySql V2, operations', () => {
|
|||
} else {
|
||||
result.push({});
|
||||
}
|
||||
return Promise.resolve(result);
|
||||
return result;
|
||||
});
|
||||
const pool = createFakePool(fakeConnectionCopy);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ const fakeConnection = {
|
|||
format(query: string, values: any[]) {
|
||||
return mysql2.format(query, values);
|
||||
},
|
||||
query: jest.fn(async () => Promise.resolve([{}])),
|
||||
query: jest.fn(async () => [{}]),
|
||||
release: jest.fn(),
|
||||
beginTransaction: jest.fn(),
|
||||
commit: jest.fn(),
|
||||
|
@ -35,7 +35,7 @@ const createFakePool = (connection: IDataObject) => {
|
|||
getConnection() {
|
||||
return connection;
|
||||
},
|
||||
query: jest.fn(async () => Promise.resolve([{}])),
|
||||
query: jest.fn(async () => [{}]),
|
||||
} as unknown as Mysql2Pool;
|
||||
};
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ const createMockDb = (columnInfo: ColumnInfo[]) => {
|
|||
} as unknown as PgpDatabase;
|
||||
};
|
||||
|
||||
// if node parameters copied from canvas all default parameters has to be added manualy as JSON would not have them
|
||||
// if node parameters copied from canvas all default parameters has to be added manually as JSON would not have them
|
||||
describe('Test PostgresV2, deleteTable operation', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
|
|
@ -1236,13 +1236,7 @@ export class Workflow {
|
|||
return { data: null };
|
||||
}
|
||||
|
||||
let promiseResults;
|
||||
try {
|
||||
promiseResults = await Promise.all(returnPromises);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
const promiseResults = await Promise.all(returnPromises);
|
||||
if (promiseResults) {
|
||||
return { data: [promiseResults] };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue