Skip to main content

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?

Hi @warner 👋

You’re on the right track using Dehydration/Hydration to lazily load additional data and then merge it into the returned trigger data.

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.

However, I notice that the hydrators.getEmployeeDetails method in performList in the posted code isn’t being called using z.dehydrate().

Please could you try calling hydrators.getEmployeeDetails using z.dehydrate() as per the example in the documentation to see if that resolves the issue you’re seeing: https://github.com/zapier/zapier-platform/blob/master/packages/cli/README.md#dehydration

ca69c8d049bc75786e5049f5d546493b.png
Link to full-size image (shown above)

If that doesn’t resolve the issue, please could you post a screenshot (with any personal or private information removed) that shows us what you see in the Editor when retrieving sample data.

Thanks!