mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
test(Gmail Node): Add test coverage (no-changelog) (#12278)
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeBaseDescription,
|
||||
INodeTypeDescription,
|
||||
@@ -15,7 +13,16 @@ import {
|
||||
WAIT_INDEFINITELY,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { draftFields, draftOperations } from './DraftDescription';
|
||||
import { labelFields, labelOperations } from './LabelDescription';
|
||||
import { messageFields, messageOperations } from './MessageDescription';
|
||||
import { threadFields, threadOperations } from './ThreadDescription';
|
||||
import type { IEmail } from '../../../../utils/sendAndWait/interfaces';
|
||||
import {
|
||||
createEmail,
|
||||
getSendAndWaitProperties,
|
||||
sendAndWaitWebhook,
|
||||
} from '../../../../utils/sendAndWait/utils';
|
||||
import {
|
||||
encodeEmail,
|
||||
googleApiRequest,
|
||||
@@ -29,20 +36,7 @@ import {
|
||||
simplifyOutput,
|
||||
unescapeSnippets,
|
||||
} from '../GenericFunctions';
|
||||
|
||||
import { messageFields, messageOperations } from './MessageDescription';
|
||||
|
||||
import { labelFields, labelOperations } from './LabelDescription';
|
||||
|
||||
import { draftFields, draftOperations } from './DraftDescription';
|
||||
|
||||
import { threadFields, threadOperations } from './ThreadDescription';
|
||||
|
||||
import {
|
||||
getSendAndWaitProperties,
|
||||
createEmail,
|
||||
sendAndWaitWebhook,
|
||||
} from '../../../../utils/sendAndWait/utils';
|
||||
import { getGmailAliases, getLabels, getThreadMessages } from './loadOptions';
|
||||
|
||||
const versionDescription: INodeTypeDescription = {
|
||||
displayName: 'Gmail',
|
||||
@@ -187,78 +181,9 @@ export class GmailV2 implements INodeType {
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the labels to display them to user so that they can
|
||||
// select them easily
|
||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
const labels = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'labels',
|
||||
'GET',
|
||||
'/gmail/v1/users/me/labels',
|
||||
);
|
||||
|
||||
for (const label of labels) {
|
||||
returnData.push({
|
||||
name: label.name,
|
||||
value: label.id,
|
||||
});
|
||||
}
|
||||
|
||||
return returnData.sort((a, b) => {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
},
|
||||
|
||||
async getThreadMessages(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
|
||||
const id = this.getNodeParameter('threadId', 0) as string;
|
||||
const { messages } = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/gmail/v1/users/me/threads/${id}`,
|
||||
{},
|
||||
{ format: 'minimal' },
|
||||
);
|
||||
|
||||
for (const message of messages || []) {
|
||||
returnData.push({
|
||||
name: message.snippet,
|
||||
value: message.id,
|
||||
});
|
||||
}
|
||||
|
||||
return returnData;
|
||||
},
|
||||
|
||||
async getGmailAliases(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const { sendAs } = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/gmail/v1/users/me/settings/sendAs',
|
||||
);
|
||||
|
||||
for (const alias of sendAs || []) {
|
||||
const displayName = alias.isDefault
|
||||
? `${alias.sendAsEmail} (Default)`
|
||||
: alias.sendAsEmail;
|
||||
returnData.push({
|
||||
name: displayName,
|
||||
value: alias.sendAsEmail,
|
||||
});
|
||||
}
|
||||
|
||||
return returnData;
|
||||
},
|
||||
getLabels,
|
||||
getThreadMessages,
|
||||
getGmailAliases,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user