-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Microsoft Outlook Node): New operation sendAndWait (#12795)
- Loading branch information
1 parent
3e9f24d
commit f4bf55f
Showing
8 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
packages/nodes-base/nodes/Microsoft/Outlook/test/v2/node/message/sendAndWait.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { MockProxy } from 'jest-mock-extended'; | ||
import { mock } from 'jest-mock-extended'; | ||
import { SEND_AND_WAIT_OPERATION, type IExecuteFunctions } from 'n8n-workflow'; | ||
|
||
import { description } from '../../../../v2/actions/node.description'; | ||
import { MicrosoftOutlookV2 } from '../../../../v2/MicrosoftOutlookV2.node'; | ||
import * as transport from '../../../../v2/transport'; | ||
|
||
jest.mock('../../../../v2/transport', () => { | ||
const originalModule = jest.requireActual('../../../../v2/transport'); | ||
return { | ||
...originalModule, | ||
microsoftApiRequest: jest.fn(async function (method: string) { | ||
if (method === 'POST') { | ||
return {}; | ||
} | ||
}), | ||
}; | ||
}); | ||
|
||
describe('Test MicrosoftOutlookV2, message => sendAndWait', () => { | ||
let microsoftOutlook: MicrosoftOutlookV2; | ||
let mockExecuteFunctions: MockProxy<IExecuteFunctions>; | ||
|
||
beforeEach(() => { | ||
microsoftOutlook = new MicrosoftOutlookV2(description); | ||
mockExecuteFunctions = mock<IExecuteFunctions>(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should send message and put execution to wait', async () => { | ||
const items = [{ json: { data: 'test' } }]; | ||
//router | ||
mockExecuteFunctions.getInputData.mockReturnValue(items); | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('message'); | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(SEND_AND_WAIT_OPERATION); | ||
mockExecuteFunctions.putExecutionToWait.mockImplementation(); | ||
|
||
//operation | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my@outlook.com'); | ||
mockExecuteFunctions.getInstanceId.mockReturnValue('instanceId'); | ||
|
||
//getSendAndWaitConfig | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my message'); | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('my subject'); | ||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('http://localhost/waiting-webhook'); | ||
mockExecuteFunctions.evaluateExpression.mockReturnValueOnce('nodeID'); | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); | ||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('approval'); | ||
|
||
const result = await microsoftOutlook.execute.call(mockExecuteFunctions); | ||
|
||
expect(result).toEqual([items]); | ||
expect(transport.microsoftApiRequest).toHaveBeenCalledTimes(1); | ||
expect(mockExecuteFunctions.putExecutionToWait).toHaveBeenCalledTimes(1); | ||
|
||
expect(transport.microsoftApiRequest).toHaveBeenCalledWith('POST', '/sendMail', { | ||
message: { | ||
body: { | ||
content: expect.stringContaining( | ||
'href="http://localhost/waiting-webhook/nodeID?approved=true"', | ||
), | ||
contentType: 'html', | ||
}, | ||
subject: 'my subject', | ||
toRecipients: [{ emailAddress: { address: 'my@outlook.com' } }], | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/nodes-base/nodes/Microsoft/Outlook/v2/actions/message/sendAndWait.operation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { | ||
IDataObject, | ||
IExecuteFunctions, | ||
INodeExecutionData, | ||
INodeProperties, | ||
} from 'n8n-workflow'; | ||
|
||
import { createEmailBody } from '../../../../../../utils/sendAndWait/email-templates'; | ||
import { | ||
getSendAndWaitConfig, | ||
getSendAndWaitProperties, | ||
createButton, | ||
} from '../../../../../../utils/sendAndWait/utils'; | ||
import { createMessage } from '../../helpers/utils'; | ||
import { microsoftApiRequest } from '../../transport'; | ||
|
||
export const description: INodeProperties[] = getSendAndWaitProperties([ | ||
{ | ||
displayName: 'To', | ||
name: 'toRecipients', | ||
description: 'Comma-separated list of email addresses of recipients', | ||
type: 'string', | ||
required: true, | ||
default: '', | ||
}, | ||
]); | ||
|
||
export async function execute(this: IExecuteFunctions, index: number, items: INodeExecutionData[]) { | ||
const toRecipients = this.getNodeParameter('toRecipients', index) as string; | ||
|
||
const config = getSendAndWaitConfig(this); | ||
const buttons: string[] = []; | ||
for (const option of config.options) { | ||
buttons.push(createButton(config.url, option.label, option.value, option.style)); | ||
} | ||
|
||
const instanceId = this.getInstanceId(); | ||
|
||
const bodyContent = createEmailBody(config.message, buttons.join('\n'), instanceId); | ||
|
||
const fields: IDataObject = { | ||
subject: config.title, | ||
bodyContent, | ||
toRecipients, | ||
bodyContentType: 'html', | ||
}; | ||
|
||
const message: IDataObject = createMessage(fields); | ||
|
||
const body: IDataObject = { message }; | ||
|
||
await microsoftApiRequest.call(this, 'POST', '/sendMail', body); | ||
|
||
return items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters