Skip to content

Commit

Permalink
Add getSchedule tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jun 9, 2024
1 parent 3e5784a commit 01e7dbf
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions lib/clients/scheduler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

0 comments on commit 01e7dbf

Please sign in to comment.