mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
test(Gmail Node): Add test coverage (no-changelog) (#12278)
This commit is contained in:
75
packages/nodes-base/nodes/Google/Gmail/v2/loadOptions.ts
Normal file
75
packages/nodes-base/nodes/Google/Gmail/v2/loadOptions.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import type { ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
|
||||
|
||||
import { googleApiRequest, googleApiRequestAllItems } from '../GenericFunctions';
|
||||
|
||||
/**
|
||||
* Get all the labels to display them to user so that they can select them easily
|
||||
*/
|
||||
export async function 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;
|
||||
});
|
||||
}
|
||||
|
||||
export async function 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;
|
||||
}
|
||||
|
||||
export async function 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;
|
||||
}
|
||||
Reference in New Issue
Block a user