0.0.1 • Published 4 years ago

zapier-testing v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Zapier Testing Utilities

This package exposes testing utilities to help in testing Zapier apps.

Setup

In your test/jest.setup.js:

import { setApp } from "zapier-testing";
import App from "../src";

// This will create a zapier app tester
// for App
setApp(App);

Test triggers, creates and searches:

To test a create, you can use the following:

import { testCreate, Bundle } from "zapier-testing";

describe("Create Contact", () => {
  it("should create a contact", async () => {
    const bundle: Bundle = {
      inputData: {
        name: "John Doe",
      },
    };

    // for triggers use: testTrigger
    // for searches use: testSearch
    const response = await testCreate("create_contact", bundle);
    expect(response).toEqual({
      id: 1000,
      name: "John Doe",
    });
  });
});

Test a random function outside of the app

Sometimes, you might want to have access to the z object without adding the function as an action to the app. In this case, you can use zMock:

import { zMock, Bundle } from "zapier-testing";

describe("Create Contact", () => {
  it("should create a contact", async () => {
    const bundle: Bundle = {
      inputData: {
        name: "John Doe",
      },
    };

    // wrap your function
    const testFn = zMock.trigger(async (z, bundle) => {
      return [
        {
          id: 1,
          name: bundle.inputData.name,
        },
      ];
    });

    // now you can test the function
    const response = await testFn(bundle);
    expect(response).toEqual([
      {
        id: 1,
        name: "John Doe",
      },
    ]);
  });
});

License

MIT