From 01e7dbf15aafd5d1cfafc733a5121c79aae750ff Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Sun, 9 Jun 2024 17:51:22 -0500 Subject: [PATCH] Add getSchedule tests --- lib/clients/scheduler.spec.js | 78 ++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/lib/clients/scheduler.spec.js b/lib/clients/scheduler.spec.js index e401fc2..ce0071b 100644 --- a/lib/clients/scheduler.spec.js +++ b/lib/clients/scheduler.spec.js @@ -63,10 +63,84 @@ test('getSchedule: returns response', async (t) => { t.deepEqual(data, getScheduleResponseFormatted) }) +test('getSchedule: passes params', async (t) => { + const { AwsSchedulerClient, createClient } = t.context + const client = createClient(t) + + td.when( + AwsSchedulerClient.prototype.send( + td.matchers.isAwsSdkCommand( + new GetScheduleCommand({ Name: scheduleName, GroupName: groupName }) + ) + ) + ).thenResolve(getScheduleResponse) + + const data = await client.getSchedule(scheduleName, { groupName }) + + t.deepEqual(data, getScheduleResponseFormatted) +}) + +test('getSchedule: 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 GetScheduleCommand({ Name: scheduleName }) + ) + ) + ).thenReject(err) + + await t.throwsAsync(() => client.getSchedule(scheduleName), { is: err }) +}) + const reqId = 'mock-req-id' const scheduleName = 'mock-schedule-name' +const groupName = 'mock-schedule-group' -const getScheduleResponse = { ScheduleArn: 'mock-schedule-arn' } +const getScheduleResponse = { + ActionAfterCompletion: 'NONE', + Arn: 'mock-schedule-arn', + CreationDate: '2024-06-09T22:40:07.749Z', + FlexibleTimeWindow: { Mode: 'OFF' }, + groupName, + LastModificationDate: '2024-06-09T22:40:07.749Z', + Name: scheduleName, + ScheduleExpression: 'rate(1 minute)', + ScheduleExpressionTimezone: 'UTC', + State: 'ENABLED', + Target: { + Arn: 'mock-arn', + EventBridgeParameters: { + DetailType: 'mock-detail-type', + Source: 'mock-source' + }, + RetryPolicy: { MaximumEventAgeInSeconds: 86400, MaximumRetryAttempts: 185 }, + RoleArn: 'mock-role-arn' + } +} -const getScheduleResponseFormatted = { scheduleArn: 'mock-schedule-arn' } +const getScheduleResponseFormatted = { + actionAfterCompletion: 'NONE', + arn: 'mock-schedule-arn', + creationDate: '2024-06-09T22:40:07.749Z', + flexibleTimeWindow: { mode: 'OFF' }, + groupName, + lastModificationDate: '2024-06-09T22:40:07.749Z', + name: scheduleName, + scheduleExpression: 'rate(1 minute)', + scheduleExpressionTimezone: 'UTC', + state: 'ENABLED', + target: { + arn: 'mock-arn', + eventBridgeParameters: { + detailType: 'mock-detail-type', + source: 'mock-source' + }, + retryPolicy: { maximumEventAgeInSeconds: 86400, maximumRetryAttempts: 185 }, + roleArn: 'mock-role-arn' + } +}