Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Cloud Validation "options" to be async #7140

Closed
6 tasks done
dblythy opened this issue Jan 22, 2021 · 2 comments
Closed
6 tasks done

Allow Cloud Validation "options" to be async #7140

dblythy opened this issue Jan 22, 2021 · 2 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@dblythy
Copy link
Member

dblythy commented Jan 22, 2021

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

@mtrezza
Copy link
Member

mtrezza commented Jan 22, 2021

Thanks for opening this issue.

It sounds reasonable to allow async validation. I understand from your comment that you are already working on a PR. Just to let others know that this is in the works.

@dblythy
Copy link
Member Author

dblythy commented Jan 22, 2021

Yeah, thank you Manuel. Sorry I have been a bit busy lately and haven't been able to close out my other pending PRs. I'll try to get to that.

@dblythy dblythy closed this as completed Feb 23, 2021
@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

2 participants