Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions spec/MongoTransform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Loading