diff --git a/examples/schedule.js b/examples/schedule.js index 0868075..a9d7293 100644 --- a/examples/schedule.js +++ b/examples/schedule.js @@ -33,13 +33,23 @@ export const deleteSchedule = export const updateSchedule = ({ log }) => - async (scheduleName, groupName) => { + async (scheduleName, groupName, arn, roleArn) => { const client = new SchedulerClient({ log }) return client.updateSchedule(scheduleName, { - scheduleExpression: 'rate(2 minute)', - groupName + scheduleExpression: 'rate(2 minutes)', + flexibleTimeWindow: { mode: 'OFF' }, + input: { foo: 'bar' }, + groupName, + target: { + arn, + roleArn, + eventBridgeParameters: { + detailType: 'example', + source: 'example' + } + } }) } diff --git a/lib/clients/scheduler.spec.js b/lib/clients/scheduler.spec.js index ce0071b..95c838b 100644 --- a/lib/clients/scheduler.spec.js +++ b/lib/clients/scheduler.spec.js @@ -96,11 +96,221 @@ test('getSchedule: throws error from client', async (t) => { await t.throwsAsync(() => client.getSchedule(scheduleName), { is: err }) }) +test('deleteSchedule: returns response', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new DeleteScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenResolve({}) + + const data = await client.deleteSchedule(scheduleName) + + t.deepEqual(data, {}) +}) + +test('deleteSchedule: passes params', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new DeleteScheduleCommand({ Name: scheduleName, GroupName: groupName }) + ) + ) + ).thenResolve({}) + + const data = await client.deleteSchedule(scheduleName, { groupName }) + + t.deepEqual(data, {}) +}) + +test('deleteSchedule: throws error from client', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + const err = new Error('foo') + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new DeleteScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenReject(err) + + await t.throwsAsync(() => client.getSchedule(scheduleName), { is: err }) +}) + +test('createSchedule: returns response', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new CreateScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenResolve(createScheduleResponse) + + const data = await client.createSchedule(scheduleName) + + t.deepEqual(data, createScheduleResponseFormatted) +}) + +test('createSchedule: passes params', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new CreateScheduleCommand({ + Arn: 'mock-schedule-arn', + FlexibleTimeWindow: { Mode: 'OFF' }, + Name: scheduleName, + ScheduleExpression: 'rate(1 minute)', + Target: { + Arn: 'mock-arn', + EventBridgeParameters: { + DetailType: 'mock-detail-type', + Source: 'mock-source' + }, + RoleArn: 'mock-role-arn' + } + }) + ) + ) + ).thenResolve(createScheduleResponse) + + const data = await client.createSchedule(scheduleName, { + arn: 'mock-schedule-arn', + flexibleTimeWindow: { mode: 'OFF' }, + name: scheduleName, + scheduleExpression: 'rate(1 minute)', + target: { + arn: 'mock-arn', + eventBridgeParameters: { + detailType: 'mock-detail-type', + source: 'mock-source' + }, + roleArn: 'mock-role-arn' + } + }) + + t.deepEqual(data, createScheduleResponseFormatted) +}) + +test('createSchedule: throws error from client', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + const err = new Error('foo') + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new CreateScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenReject(err) + + await t.throwsAsync(() => client.createSchedule(scheduleName), { is: err }) +}) + +test('updateSchedule: returns response', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new UpdateScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenResolve(updateScheduleResponse) + + const data = await client.updateSchedule(scheduleName) + + t.deepEqual(data, updateScheduleResponseFormatted) +}) + +test('updateSchedule: passes params', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new UpdateScheduleCommand({ + Arn: 'mock-schedule-arn', + FlexibleTimeWindow: { Mode: 'OFF' }, + Name: scheduleName, + ScheduleExpression: 'rate(1 minute)', + Target: { + Arn: 'mock-arn', + EventBridgeParameters: { + DetailType: 'mock-detail-type', + Source: 'mock-source' + }, + RoleArn: 'mock-role-arn' + } + }) + ) + ) + ).thenResolve(updateScheduleResponse) + + const data = await client.updateSchedule(scheduleName, { + arn: 'mock-schedule-arn', + flexibleTimeWindow: { mode: 'OFF' }, + name: scheduleName, + scheduleExpression: 'rate(1 minute)', + target: { + arn: 'mock-arn', + eventBridgeParameters: { + detailType: 'mock-detail-type', + source: 'mock-source' + }, + roleArn: 'mock-role-arn' + } + }) + + t.deepEqual(data, updateScheduleResponseFormatted) +}) + +test('updateSchedule: throws error from client', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + const err = new Error('foo') + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new UpdateScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenReject(err) + + await t.throwsAsync(() => client.updateSchedule(scheduleName), { is: err }) +}) + const reqId = 'mock-req-id' const scheduleName = 'mock-schedule-name' const groupName = 'mock-schedule-group' +const createScheduleResponse = { ScheduleArn: 'mock-schedule-arn' } + +const createScheduleResponseFormatted = { scheduleArn: 'mock-schedule-arn' } + +const updateScheduleResponse = createScheduleResponse + +const updateScheduleResponseFormatted = createScheduleResponseFormatted + const getScheduleResponse = { ActionAfterCompletion: 'NONE', Arn: 'mock-schedule-arn',