Skip to content

Allow Cloud Validation "options" to be async #7140

Closed
@dblythy

Description

@dblythy

New Issue Checklist

Issue Description

As mentioned by @Cinezaster here, it is not possible to use async with a Parse.Cloud validator.

Steps to reproduce

Actual Outcome

Cloud function completes without running async validation

Expected Outcome

Validator should wait to run options function

Failing Test Case / Pull Request

  • 🤩 I submitted a PR with a fix and a test case.
  • 🧐 I submitted a PR with a failing test case.

Failing test:

it('set params options function async', async (done) => {
    Parse.Cloud.define(
      'hello',
      () => {
        fail('cloud function should not run.');
        return 'Hello world!';
      },
      {
        fields: {
          data: {
            type: Number,
            required: true,
            options: async val => {
              await new Promise((resolve, reject) => {
                setTimeout(resolve, 500);
              })
              return false;
            },
            error: 'Validation failed. Expected data to be between 1 and 5.',
          },
        },
      }
    );
    try {
    await Parse.Cloud.run('hello', { data: 7 })
    } catch (error) {
      expect(error.code).toEqual(Parse.Error.VALIDATION_ERROR);
      expect(error.message).toEqual('Validation failed. Expected data to be between 1 and 5.');
    }
    done();
  });

Environment

Server

  • Parse Server version: 4.5.0
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): FILL_THIS_OUT

Database

  • System (MongoDB or Postgres): FILL_THIS_OUT
  • Database version: FILL_THIS_OUT
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): FILL_THIS_OUT

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions