diff --git a/spec/RestCreate.spec.js b/spec/RestCreate.spec.js index b6015c50..9af188c6 100644 --- a/spec/RestCreate.spec.js +++ b/spec/RestCreate.spec.js @@ -143,6 +143,7 @@ describe('rest create', () => { expect(typeof r.response.objectId).toEqual('string'); expect(typeof r.response.createdAt).toEqual('string'); expect(typeof r.response.sessionToken).toEqual('string'); + expect(typeof r.response.username).toEqual('string'); return rest.create(config, auth.nobody(config), '_User', data1); }).then((r) => { expect(typeof r.response.objectId).toEqual('string'); diff --git a/src/RestWrite.js b/src/RestWrite.js index 9d4dc947..695e5a1b 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -351,6 +351,7 @@ RestWrite.prototype.transformUser = function() { if (!this.data.username) { if (!this.query) { this.data.username = cryptoUtils.randomString(25); + this.responseShouldHaveUsername = true; } return; } @@ -790,6 +791,10 @@ RestWrite.prototype.runDatabaseOperation = function() { .then(response => { response.objectId = this.data.objectId; response.createdAt = this.data.createdAt; + + if (this.responseShouldHaveUsername) { + response.username = this.data.username; + } if (this.storage.changedByTrigger) { Object.keys(this.data).forEach(fieldName => { response[fieldName] = response[fieldName] || this.data[fieldName];