fix: Queries with object field authData.provider.id are incorrectly transformed to _auth_data_provider.id for custom classes (#9932)
This commit is contained in:
@@ -521,6 +521,23 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
||||
expect(output.authData).toBe('random');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should only transform authData.provider.id for _User class', () => {
|
||||
// Test that for _User class, authData.facebook.id is transformed
|
||||
const userInput = {
|
||||
'authData.facebook.id': '10000000000000001',
|
||||
};
|
||||
const userOutput = transform.transformWhere('_User', userInput, { fields: {} });
|
||||
expect(userOutput['_auth_data_facebook.id']).toBe('10000000000000001');
|
||||
|
||||
// Test that for non-User classes, authData.facebook.id is NOT transformed
|
||||
const customInput = {
|
||||
'authData.facebook.id': '10000000000000001',
|
||||
};
|
||||
const customOutput = transform.transformWhere('SpamAlerts', customInput, { fields: {} });
|
||||
expect(customOutput['authData.facebook.id']).toBe('10000000000000001');
|
||||
expect(customOutput['_auth_data_facebook.id']).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot have a custom field name beginning with underscore', done => {
|
||||
|
||||
@@ -305,7 +305,7 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
|
||||
default: {
|
||||
// Other auth data
|
||||
const authDataMatch = key.match(/^authData\.([a-zA-Z0-9_]+)\.id$/);
|
||||
if (authDataMatch) {
|
||||
if (authDataMatch && className === '_User') {
|
||||
const provider = authDataMatch[1];
|
||||
// Special-case auth data.
|
||||
return { key: `_auth_data_${provider}.id`, value };
|
||||
|
||||
Reference in New Issue
Block a user