pull:初次提交
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import type { RecurringEventInstance } from '../EventInterface';
|
||||
import { addTimezoneToDate, dateObjectToISO, eventExtendYearIntoFuture } from '../GenericFunctions';
|
||||
|
||||
describe('addTimezoneToDate', () => {
|
||||
it('should add timezone to date', () => {
|
||||
const dateWithTimezone = '2021-09-01T12:00:00.000Z';
|
||||
const result1 = addTimezoneToDate(dateWithTimezone, 'Europe/Prague');
|
||||
expect(result1).toBe('2021-09-01T12:00:00.000Z');
|
||||
|
||||
const dateWithoutTimezone = '2021-09-01T12:00:00';
|
||||
const result2 = addTimezoneToDate(dateWithoutTimezone, 'Europe/Prague');
|
||||
expect(result2).toBe('2021-09-01T10:00:00Z');
|
||||
|
||||
const result3 = addTimezoneToDate(dateWithoutTimezone, 'Asia/Tokyo');
|
||||
expect(result3).toBe('2021-09-01T03:00:00Z');
|
||||
|
||||
const dateWithDifferentTimezone = '2021-09-01T12:00:00.000+08:00';
|
||||
const result4 = addTimezoneToDate(dateWithDifferentTimezone, 'Europe/Prague');
|
||||
expect(result4).toBe('2021-09-01T12:00:00.000+08:00');
|
||||
});
|
||||
});
|
||||
|
||||
describe('dateObjectToISO', () => {
|
||||
test('should return ISO string for DateTime instance', () => {
|
||||
const mockDateTime = DateTime.fromISO('2025-01-07T12:00:00');
|
||||
const result = dateObjectToISO(mockDateTime);
|
||||
expect(result).toBe('2025-01-07T12:00:00.000+00:00');
|
||||
});
|
||||
|
||||
test('should return ISO string for Date instance', () => {
|
||||
const mockDate = new Date('2025-01-07T12:00:00Z');
|
||||
const result = dateObjectToISO(mockDate);
|
||||
expect(result).toBe('2025-01-07T12:00:00.000Z');
|
||||
});
|
||||
|
||||
test('should return string when input is not a DateTime or Date instance', () => {
|
||||
const inputString = '2025-01-07T12:00:00';
|
||||
const result = dateObjectToISO(inputString);
|
||||
expect(result).toBe(inputString);
|
||||
});
|
||||
});
|
||||
|
||||
describe('eventExtendYearIntoFuture', () => {
|
||||
const timezone = 'UTC';
|
||||
|
||||
it('should return true if any event extends into the next year', () => {
|
||||
const events = [
|
||||
{
|
||||
recurringEventId: '123',
|
||||
start: { dateTime: '2026-01-01T00:00:00Z', date: null },
|
||||
},
|
||||
] as unknown as RecurringEventInstance[];
|
||||
|
||||
const result = eventExtendYearIntoFuture(events, timezone, 2025);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if no event extends into the next year', () => {
|
||||
const events = [
|
||||
{
|
||||
recurringEventId: '123',
|
||||
start: { dateTime: '2025-12-31T23:59:59Z', date: null },
|
||||
},
|
||||
] as unknown as RecurringEventInstance[];
|
||||
|
||||
const result = eventExtendYearIntoFuture(events, timezone, 2025);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for invalid event start dates', () => {
|
||||
const events = [
|
||||
{
|
||||
recurringEventId: '123',
|
||||
start: { dateTime: 'invalid-date', date: null },
|
||||
},
|
||||
] as unknown as RecurringEventInstance[];
|
||||
|
||||
const result = eventExtendYearIntoFuture(events, timezone, 2025);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for events without a recurringEventId', () => {
|
||||
const events = [
|
||||
{
|
||||
recurringEventId: null,
|
||||
start: { dateTime: '2025-01-01T00:00:00Z', date: null },
|
||||
},
|
||||
] as unknown as RecurringEventInstance[];
|
||||
|
||||
const result = eventExtendYearIntoFuture(events, timezone, 2025);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle events with only a date and no time', () => {
|
||||
const events = [
|
||||
{
|
||||
recurringEventId: '123',
|
||||
start: { dateTime: null, date: '2026-01-01' },
|
||||
},
|
||||
] as unknown as RecurringEventInstance[];
|
||||
|
||||
const result = eventExtendYearIntoFuture(events, timezone, 2025);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import type { RecurrentEvent } from '../GenericFunctions';
|
||||
import { addNextOccurrence } from '../GenericFunctions';
|
||||
|
||||
const mockNow = '2024-09-06T16:30:00+03:00';
|
||||
jest.spyOn(global.Date, 'now').mockImplementation(() => moment(mockNow).valueOf());
|
||||
|
||||
describe('addNextOccurrence', () => {
|
||||
it('should not modify event if no recurrence exists', () => {
|
||||
const event: RecurrentEvent[] = [
|
||||
{
|
||||
start: {
|
||||
dateTime: '2024-09-01T08:00:00Z',
|
||||
timeZone: 'UTC',
|
||||
},
|
||||
end: {
|
||||
dateTime: '2024-09-01T09:00:00Z',
|
||||
timeZone: 'UTC',
|
||||
},
|
||||
recurrence: [],
|
||||
},
|
||||
];
|
||||
|
||||
const result = addNextOccurrence(event);
|
||||
|
||||
expect(result[0].nextOccurrence).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle event with no RRULE correctly', () => {
|
||||
const event: RecurrentEvent[] = [
|
||||
{
|
||||
start: {
|
||||
dateTime: '2024-09-01T08:00:00Z',
|
||||
timeZone: 'UTC',
|
||||
},
|
||||
end: {
|
||||
dateTime: '2024-09-01T09:00:00Z',
|
||||
timeZone: 'UTC',
|
||||
},
|
||||
recurrence: ['FREQ=WEEKLY;COUNT=2'],
|
||||
},
|
||||
];
|
||||
|
||||
const result = addNextOccurrence(event);
|
||||
|
||||
expect(result[0].nextOccurrence).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should ignore recurrence if until date is in the past', () => {
|
||||
const event: RecurrentEvent[] = [
|
||||
{
|
||||
start: {
|
||||
dateTime: '2024-08-01T08:00:00Z',
|
||||
timeZone: 'UTC',
|
||||
},
|
||||
end: {
|
||||
dateTime: '2024-08-01T09:00:00Z',
|
||||
timeZone: 'UTC',
|
||||
},
|
||||
recurrence: ['RRULE:FREQ=DAILY;UNTIL=20240805T000000Z'],
|
||||
},
|
||||
];
|
||||
|
||||
const result = addNextOccurrence(event);
|
||||
|
||||
expect(result[0].nextOccurrence).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should handle errors gracefully without breaking and return unchanged event', () => {
|
||||
const event: RecurrentEvent[] = [
|
||||
{
|
||||
start: {
|
||||
dateTime: '2024-09-06T17:30:00+03:00',
|
||||
timeZone: 'Europe/Berlin',
|
||||
},
|
||||
end: {
|
||||
dateTime: '2024-09-06T18:00:00+03:00',
|
||||
timeZone: 'Europe/Berlin',
|
||||
},
|
||||
recurrence: ['xxxxx'],
|
||||
},
|
||||
];
|
||||
|
||||
const result = addNextOccurrence(event);
|
||||
|
||||
expect(result).toEqual(event);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,219 @@
|
||||
import type { MockProxy } from 'jest-mock-extended';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { INode, IExecuteFunctions, IDataObject } from 'n8n-workflow';
|
||||
|
||||
import * as genericFunctions from '../../GenericFunctions';
|
||||
import { GoogleCalendar } from '../../GoogleCalendar.node';
|
||||
|
||||
let response: IDataObject[] | undefined = [];
|
||||
let responseWithRetries: IDataObject | undefined = {};
|
||||
|
||||
jest.mock('../../GenericFunctions', () => {
|
||||
const originalModule = jest.requireActual('../../GenericFunctions');
|
||||
return {
|
||||
...originalModule,
|
||||
getTimezones: jest.fn(),
|
||||
googleApiRequest: jest.fn(),
|
||||
googleApiRequestAllItems: jest.fn(async function () {
|
||||
return (() => response)();
|
||||
}),
|
||||
googleApiRequestWithRetries: jest.fn(async function () {
|
||||
return (() => responseWithRetries)();
|
||||
}),
|
||||
addNextOccurrence: jest.fn(function (data: IDataObject[]) {
|
||||
return data;
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Google Calendar Node', () => {
|
||||
let googleCalendar: GoogleCalendar;
|
||||
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
googleCalendar = new GoogleCalendar();
|
||||
mockExecuteFunctions = mock<IExecuteFunctions>({
|
||||
getInputData: jest.fn(),
|
||||
getNode: jest.fn(),
|
||||
getNodeParameter: jest.fn(),
|
||||
getTimezone: jest.fn(),
|
||||
helpers: {
|
||||
constructExecutionMetaData: jest.fn().mockReturnValue([]),
|
||||
},
|
||||
});
|
||||
response = undefined;
|
||||
responseWithRetries = undefined;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Google Calendar > Event > Get Many', () => {
|
||||
it('should configure get all request parameters in version 1.3', async () => {
|
||||
// pre loop setup
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('getAll');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.3 }));
|
||||
|
||||
//operation setup
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true); //returnAll
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar'); //calendar
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
iCalUID: 'uid',
|
||||
maxAttendees: 25,
|
||||
orderBy: 'startTime',
|
||||
query: 'test query',
|
||||
recurringEventHandling: 'expand',
|
||||
showDeleted: true,
|
||||
showHiddenInvitations: true,
|
||||
updatedMin: '2024-12-21T00:00:00',
|
||||
}); //options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('Europe/Berlin'); //options.timeZone
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-20T00:00:00'); //timeMin
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-26T00:00:00'); //timeMax
|
||||
|
||||
await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(genericFunctions.googleApiRequestAllItems).toHaveBeenCalledWith(
|
||||
'items',
|
||||
'GET',
|
||||
'/calendar/v3/calendars/myCalendar/events',
|
||||
{},
|
||||
{
|
||||
iCalUID: 'uid',
|
||||
maxAttendees: 25,
|
||||
orderBy: 'startTime',
|
||||
q: 'test query',
|
||||
showDeleted: true,
|
||||
showHiddenInvitations: true,
|
||||
singleEvents: true,
|
||||
timeMax: '2024-12-25T23:00:00Z',
|
||||
timeMin: '2024-12-19T23:00:00Z',
|
||||
timeZone: 'Europe/Berlin',
|
||||
updatedMin: '2024-12-20T23:00:00Z',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('should configure get all recurringEventHandling equals next in version 1.3', async () => {
|
||||
// pre loop setup
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('getAll');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.3 }));
|
||||
|
||||
//operation setup
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true); //returnAll
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar'); //calendar
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
recurringEventHandling: 'next',
|
||||
}); //options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('Europe/Berlin'); //options.timeZone
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-20T00:00:00'); //timeMin
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-26T00:00:00'); //timeMax
|
||||
|
||||
response = [
|
||||
{
|
||||
recurrence: ['RRULE:FREQ=DAILY;COUNT=5'],
|
||||
},
|
||||
];
|
||||
|
||||
responseWithRetries = { items: [] };
|
||||
|
||||
const result = await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(genericFunctions.googleApiRequestAllItems).toHaveBeenCalledWith(
|
||||
'items',
|
||||
'GET',
|
||||
'/calendar/v3/calendars/myCalendar/events',
|
||||
{},
|
||||
{
|
||||
timeMax: '2024-12-25T23:00:00Z',
|
||||
timeMin: '2024-12-19T23:00:00Z',
|
||||
timeZone: 'Europe/Berlin',
|
||||
},
|
||||
);
|
||||
expect(genericFunctions.googleApiRequestWithRetries).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
method: 'GET',
|
||||
itemIndex: 0,
|
||||
resource: '/calendar/v3/calendars/myCalendar/events/undefined/instances',
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result).toEqual([[]]);
|
||||
});
|
||||
|
||||
it('should configure get all recurringEventHandling equals first in version 1.3', async () => {
|
||||
// pre loop setup
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('getAll');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.3 }));
|
||||
|
||||
//operation setup
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true); //returnAll
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar'); //calendar
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
recurringEventHandling: 'first',
|
||||
}); //options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('Europe/Berlin'); //options.timeZone
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-20T00:00:00'); //timeMin
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-26T00:00:00'); //timeMax
|
||||
|
||||
response = [
|
||||
{
|
||||
recurrence: ['RRULE:FREQ=DAILY;COUNT=5'],
|
||||
created: '2024-12-19T00:00:00',
|
||||
},
|
||||
{
|
||||
recurrence: ['RRULE:FREQ=DAILY;COUNT=5'],
|
||||
created: '2024-12-27T00:00:00',
|
||||
},
|
||||
];
|
||||
|
||||
const result = await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(result).toEqual([[]]);
|
||||
});
|
||||
|
||||
it('should configure get all should have hint in version 1.3', async () => {
|
||||
// pre loop setup
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('getAll');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.3 }));
|
||||
|
||||
//operation setup
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true); //returnAll
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar'); //calendar
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({}); //options
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('Europe/Berlin'); //options.timeZone
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('2024-12-20T00:00:00'); //timeMin
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(''); //timeMax
|
||||
|
||||
response = [
|
||||
{
|
||||
recurrence: ['RRULE:FREQ=DAILY;COUNT=5'],
|
||||
created: '2024-12-25T00:00:00',
|
||||
recurringEventId: '1',
|
||||
start: { dateTime: '2027-12-25T00:00:00' },
|
||||
},
|
||||
];
|
||||
|
||||
await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(mockExecuteFunctions.addExecutionHints).toHaveBeenCalledWith({
|
||||
message:
|
||||
"Some events repeat far into the future. To return less of them, add a 'Before' date or change the 'Recurring Event Handling' option.",
|
||||
location: 'outputPane',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,127 @@
|
||||
import type { MockProxy } from 'jest-mock-extended';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { INode, IExecuteFunctions } from 'n8n-workflow';
|
||||
|
||||
import * as genericFunctions from '../../GenericFunctions';
|
||||
import { GoogleCalendar } from '../../GoogleCalendar.node';
|
||||
|
||||
jest.mock('../../GenericFunctions', () => ({
|
||||
getTimezones: jest.fn(),
|
||||
googleApiRequest: jest.fn(),
|
||||
googleApiRequestAllItems: jest.fn(),
|
||||
addTimezoneToDate: jest.fn(),
|
||||
addNextOccurrence: jest.fn(),
|
||||
encodeURIComponentOnce: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('Google Calendar Node', () => {
|
||||
let googleCalendar: GoogleCalendar;
|
||||
let mockExecuteFunctions: MockProxy<IExecuteFunctions>;
|
||||
|
||||
beforeEach(() => {
|
||||
googleCalendar = new GoogleCalendar();
|
||||
mockExecuteFunctions = mock<IExecuteFunctions>({
|
||||
getInputData: jest.fn(),
|
||||
getNode: jest.fn(),
|
||||
getNodeParameter: jest.fn(),
|
||||
getTimezone: jest.fn(),
|
||||
helpers: {
|
||||
constructExecutionMetaData: jest.fn().mockReturnValue([]),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Google Calendar > Event > Update', () => {
|
||||
it('should update replace attendees in version 1.1', async () => {
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('update');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.1 }));
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myEvent');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
attendees: ['email1@mail.com'],
|
||||
});
|
||||
|
||||
await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(genericFunctions.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/calendar/v3/calendars/undefined/events/myEvent',
|
||||
{ attendees: [{ email: 'email1@mail.com' }] },
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it('should update replace attendees', async () => {
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('update');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.2 }));
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myEvent');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
attendeesUi: {
|
||||
values: {
|
||||
mode: 'replace',
|
||||
attendees: ['email1@mail.com'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(genericFunctions.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/calendar/v3/calendars/undefined/events/myEvent',
|
||||
{ attendees: [{ email: 'email1@mail.com' }] },
|
||||
{},
|
||||
);
|
||||
});
|
||||
|
||||
it('should update add attendees', async () => {
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([{ json: {} }]);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('event');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('update');
|
||||
mockExecuteFunctions.getTimezone.mockReturnValueOnce('Europe/Berlin');
|
||||
mockExecuteFunctions.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.2 }));
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myCalendar');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce('myEvent');
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce(true);
|
||||
mockExecuteFunctions.getNodeParameter.mockReturnValueOnce({
|
||||
attendeesUi: {
|
||||
values: {
|
||||
mode: 'add',
|
||||
attendees: ['email1@mail.com'],
|
||||
},
|
||||
},
|
||||
});
|
||||
(genericFunctions.googleApiRequest as jest.Mock).mockResolvedValueOnce({
|
||||
attendees: [{ email: 'email2@mail.com' }],
|
||||
});
|
||||
|
||||
await googleCalendar.execute.call(mockExecuteFunctions);
|
||||
|
||||
expect(genericFunctions.googleApiRequest).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(genericFunctions.googleApiRequest).toHaveBeenCalledWith(
|
||||
'GET',
|
||||
'/calendar/v3/calendars/undefined/events/myEvent',
|
||||
);
|
||||
expect(genericFunctions.googleApiRequest).toHaveBeenCalledWith(
|
||||
'PATCH',
|
||||
'/calendar/v3/calendars/undefined/events/myEvent',
|
||||
{ attendees: [{ email: 'email2@mail.com' }, { email: 'email1@mail.com' }] },
|
||||
{},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user