Code Monkey home page Code Monkey logo

Comments (7)

xavdid avatar xavdid commented on May 24, 2024 2

This has been released as part of CLI 10.0.1.

from zapier-platform.

xavdid avatar xavdid commented on May 24, 2024 1

Yeah, great question! once the fix is deployed (which, pre-warning, can take some time) and you've got the update, then your tests with cursors will use the actual cursor endpoints and perform just like production code will. The apptester generates (short-lived) cursors for each call to appTester(... (so each test gets its own cursor)

If you (understandably) want to fix your tests right now you can edit this function in your local node_modules to be return true:

const shouldPaginate = (appRaw, method) => {
if (method.startsWith('triggers') && method.endsWith('perform')) {
const methodParts = method.split('.');
methodParts.pop();
return get(appRaw, `${methodParts.join('.')}.canPaginate`);
}

that's in node_modules/zapier-platform-core/src/tools/create-app-tester.js

That'll mean that all your tests will be able to use triggers (even when they shouldn't), but that's the easiest guaranteed fix. That'll keep working until you re-install node_modules, but it'll at least unblock you.

from zapier-platform.

jonathan-codaio avatar jonathan-codaio commented on May 24, 2024

Wanted to check in on the status of this. Is this in fact a bug?

We're having the same issue. Our application is moving from offset-based pagination to cursor-based pagination. Our resources are set to canPaginate: true. It was easy to implement perform to get and set the cursor as needed.

However, when using createAppTester, we are now getting

Invalid cursor operation. `z.cursor` can only be used in `perform` methods of polling triggers and when `canPaginate` is `true`.

It seems like this is supported by the app tester is incorrectly raising an issue here. Is that the case? Is there anything we can do to work around this in the meantime?

from zapier-platform.

xavdid avatar xavdid commented on May 24, 2024

I think it's just an issue with createAppTester and resources w/ paginating triggers.

If you don't mind, could you post your appTester(... line for the trigger that doesn't work? That'll help me narrow this down.

from zapier-platform.

jonathan-codaio avatar jonathan-codaio commented on May 24, 2024

Thanks @xavdid !

The test itself is basically:

const bundle = {
  ...fake bundle stuff
};

...

bundle.meta.page = 2;
const results = await appTester(App.resources.column.list.operation.perform, bundle);

And the definition of the resource in question is:

async function performListColumns(z: ZObject, bundle: Bundle): Promise<any[]> {
  const {documentId, tableId} = bundle.inputData;
  const response = await listColumns({
    z,
    bundle,
    documentId,
    tableId,
    pageToken: bundle.meta.page ? await z.cursor.get() : undefined,
  });
  if (response.nextPageToken) {
    await z.cursor.set(response.nextPageToken);
  }
  return response.items;
}

export const ColumnResource = {
  key: 'column' as 'column',
  noun: 'Column',

  list: {
    display: {
      label: 'New Column',
      description: 'Triggers when a new column is added to the selected table.',
      hidden: true,
    },
    operation: {
      canPaginate: true,
      inputFields: [
        {
          key: 'documentId',
          required: true,
          label: 'Document',
          dynamic: 'documentList.id.name',
          altersDynamicFields: true,
        },
        {
          key: 'tableId',
          required: true,
          label: 'Table',
          dynamic: 'tableList.id.name',
          altersDynamicFields: true,
          helpText: 'Changes to your document may take a little time to show up here.',
        },
      ],
      perform: performListColumns,
      sample: {
        items: [
          {
            id: 'c-abc123',
            name: 'Column A',
            href: 'https://coda.io/apis/v1/docs/12345/tables/grid-abc123/columns/c-abc123',
          },
          {
            id: 'c-def456',
            name: 'Column B',
            href: 'https://coda.io/apis/v1/docs/12345/tables/grid-abc123/columns/c-def456',
          },
        ],
      },
    },
  },

  sample: {
    id: 'c-102sdfn28',
    name: 'Column A',
    href: 'https://coda.io/apis/v1/docs/12345/tables/grid-abc123/columns/c-102sdfn28',
  },

  outputFields: [
    {key: 'id', label: 'ID'},
    {key: 'name', label: 'Name'},
    {key: 'href', label: 'Link'},
    {key: 'calculated', label: 'Calculated'},
    {key: 'display', label: 'Display'},
  ],
};

from zapier-platform.

xavdid avatar xavdid commented on May 24, 2024

nice! the appTester(App.resources.column.list.operation.perform, bundle); is the key here - that's the correct test code, but it's running afoul of the lines caleb linked in the OP. I'll get this fixed!

from zapier-platform.

jonathan-codaio avatar jonathan-codaio commented on May 24, 2024

Very much appreciate the quick response time here, thanks!

Relatedly, once fixed, is there a way to mock/hack setting z.cursor in the test? It's obviously easy to pass in an arbitrary bundle, but to meaningfully test cursor-based pagination one would need to set the cursor to something non-empty. But that seems like it's all within the bowels of the app tester.

from zapier-platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.