-
-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Errors are exposed only as types, which means that its not easy to create mocks for the AWS services. Example for jest/jest-mock-extended:
this.scheduler = mock<Context.Tag.Service<SchedulerService>>()
this.scheduler.updateSchedule.mockReturnValue(
Effect.fail({
...new ResourceNotFoundException({
message: 'not found',
Message: 'Not Found',
$metadata: {},
}),
_tag: 'ResourceNotFoundException',
}),
)
Usability could be vastly improved by providing a constructor for the error, with some possible optimisation to provide sensible defaults, eg.:
this.scheduler.updateSchedule.mockReturnValue(
Effect.fail(new ResourceNotFoundError({ Message: 'Not Found' }))
)
One could apply a kludge such as:
this.scheduler.updateSchedule.mockReturnValue(
Effect.fail({
_tag: 'ResourceNotFoundException',
} as ResourceNotFoundError),
)
although possibly ugly and error prone should the effect-aws library change the constants.
Different mock frameworks will have their own behaviours, but at a fundamental level, the ability to more readily construct error types would be useful.
As an aside, the service type could be exported within the service namespace, so we can avoid the Context.Tag.Service<xxx>
and have something like Service.Type
. I think that effect-aws could improve the exports, to better mirror those used within effect as a whole (Effect.Service
exports Default
as the primary layer for example).