Skip to content

Commit

Permalink
Add remaining schedule tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jun 9, 2024
1 parent 01e7dbf commit a3eecde
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 3 deletions.
16 changes: 13 additions & 3 deletions examples/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
})
}

Expand Down
210 changes: 210 additions & 0 deletions lib/clients/scheduler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit a3eecde

Please sign in to comment.