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

test: Add test to set custom object ID #9137

Closed
wants to merge 10 commits into from

Conversation

badboy-tian
Copy link

Pull Request

Issue

Closes: #9134

Approach

Can not custom objectId with parse/node

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Copy link

Thanks for opening this pull request!

@@ -12,6 +12,7 @@
// single-instance mode and we don't want these tests to run in
// single-instance mode.

const Parse = require('parse/node');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary. There surely are existing tests with custom obj ID?

@badboy-tian
Copy link
Author

@mtrezza The test passed. only add

Parse.allowCustomObjectId = true;

I do not know why. I have set

await reconfigureServer({
      allowCustomObjectId: true,
    });


const body = {
name: 'SaveAudio',
data: '{"objectId":"66541dbdffead844f1339e3c","createdAt":"2024-05-27T05:44:29.504Z","updatedAt":"2024-05-27T05:44:29.504Z"}',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you setting the createdAt date here? Could you just create a new object, set a custom object Id and save it, without parsing a JSON. Remember, a test should be as simple as possible to demonstrate the issue.

const testObject = new Parse.Object(name);
testObject.id = data.objectId;

const entries = Object.entries(data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, the loop is unnecessary, and you don't need to set and field of the object at all. This is about setting a custom ID. So all this extra code should be removed.

}

console.log(testObject.toJSON());
await testObject.save(null, { useMasterKey: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end of the test you may want to fetch the object by the custom ID to ensure it has been created correctly in the DB.

@badboy-tian badboy-tian changed the title test: Can not custom objectId with parse/node test: Can not custom objectId with parse server api May 31, 2024
spec/ParseObject.spec.js Outdated Show resolved Hide resolved
Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com>
@mtrezza
Copy link
Member

mtrezza commented May 31, 2024

So the test passes. If you are unable to adapt this test to fail, we have to consider it an issue that is specific to your deployment (custom Cloud Code, triggers, etc). We'd still merge the PR to have this test.

@mtrezza mtrezza changed the title test: Can not custom objectId with parse server api test: Add test to set custom object ID May 31, 2024
@mtrezza
Copy link
Member

mtrezza commented Jul 9, 2024

Closing as no further response

@mtrezza mtrezza closed this Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom objectId not working
2 participants