Hi,
I have developed a custom trigger that fires when leave is approved in our payroll system. The custom integration is built using the Zapier CLI and uses REST Hooks to receive leave requests “instantly”.
Everything is working well in the simple case and the trigger will output data from the webhook request to pass on to our timesheet system.
Unfortunately the webhook request doesn’t contain enough information to identify the employee in the timesheet system, so it is necessary to make an additional request to lookup the employee details. I have used a hydrator to lazily load the employee data when the downstream task requires the extra info. This all works as expected.
The problem is the response from `performList` that is used to test the trigger. Currently `performList` fetches a list of leave requests from the payroll system. However the test data does not contain the dehydrated employee details. If I use the dehydrator in the `performList` function, the test data contains an encoded pointer which is confusing to an end user.
The only way I can get produce test data that is realistic is to manually call the hydrator function and splice the employee response with the leave request response. See example below:
const performList = async (z, bundle) => {
const options = {
url: `https://payroll.com/api/leaverequest`,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
params: {
'filter.status': 'Approved'
}
};
const response = await z.request(options);
response.throwForStatus();
const leaveRequest = response.jsono0];
leaveRequest.employeeDetails = await hydrators.getEmployeeDetails(z, {
inputData: {
employeeId: leaveRequest.employeeId
}
});
return leaveRequest];
};
This works but it seems like too much work and setting up api mocks in the tests is cumbersome. Is there a better way?