#Integrations RunTask Testing Input

1 messages · Page 1 of 1 (latest)

heavy trellis
#

I am trying to test my job using the testing library/package - https://github.com/triggerdotdev/trigger.dev/tree/main/packages/testing

I have a task to insert rows into supabase as below.

const { error } = await io.supabase.runTask("push_history", async () =>
  await io.supabase.client
    .from('inverter_history')
    .insert(history),
  { retry }
);

in my test i have specified the return value

const testRun = await testJob(history, {
  payload: {
    date: "2023-07-19 11:00"
  },
  tasks: {
    push_history: {
    }
  }
});

If I check to make sure the task was called, the below code works

expect(testRun.tasks["push_history"]).toHaveBeenCalledOnce();

if i try and check that the task was called with values i always get undefined

expect(testRun.tasks["push_history"]).toHaveBeenCalledWith(
  What should go here?
);

if i test the returned results for other supabase fetches this works, there seems to be issues with the input checks.

GitHub

✨ Trigger.dev is the open source background jobs framework for TypeScript. With features like API integrations, webhooks, scheduling and delays. - triggerdotdev/trigger.dev

tall turret
#

I think the problem here is that the way those Supabase database runTask calls work isn't compatible with the unit testing library.

If you look at this example (from here https://github.com/triggerdotdev/trigger.dev/blob/6edaffeb7e2792c41935219d4172b326a46b6697/references/unit-testing/tests/example.test.ts#L60)

run: async (payload, io, ctx) => {
  return await io.stripe.createCharge("create-charge", {
    amount: 100,
    currency: "usd",
    source: payload.source,
    customer: payload.customerId,
  });
},
// wask was called with correct params
expect(testRun.tasks["create-charge"]).toHaveBeenCalledWith({
  amount: 100,
  currency: "usd",
  customer: "cus_123",
  source: "src_123",
});

This works because the params were passed in when using the createCharge function with the key "create-charge".

In your case, this line doesn't actually have any inputs.

const { error } = await io.supabase.runTask("push_history", async () =>

I'm assuming what you want to do is verify the history variable that is used in the insert?

heavy trellis
#

yes, i wanted to check that the correct history records are inserted.

heavy trellis
#

@tall turret is this a limitation of the mocking module? or can it be worked around?

heavy trellis
#

the workaround ive thought of for the moment, is to add a debug flag to the payload and add history to the job output.