Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

MLIBZ-2503: User.me() does not delete newly-empty fields on the SDK #299

Merged
merged 3 commits into from
May 24, 2018
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
6 changes: 6 additions & 0 deletions src/core/request/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ const Auth = {
);
}

if (!isDefined(activeUser._kmd) || !isDefined(activeUser._kmd.authtoken)) {
return Promise.reject(
new NoActiveUserError('The active user does not have a valid auth token.')
);
}

return Promise.resolve({
scheme: 'Kinvey',
credentials: activeUser._kmd.authtoken
Expand Down
3 changes: 0 additions & 3 deletions src/core/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,6 @@ export class User {
return request.execute()
.then(response => response.data)
.then((data) => {
// Merge returned data
data = assign(this.data, data);

// Remove sensitive data
delete data.password;

Expand Down
63 changes: 8 additions & 55 deletions src/core/user/user.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import expect from 'expect';
import chai from 'chai';
import nock from 'nock';
import assign from 'lodash/assign';
import localStorage from 'local-storage';
Expand All @@ -16,6 +17,8 @@ import { init } from '../kinvey';
import { getLiveService } from '../live';
import { UserMock } from './user-mock';

chai.use(require('chai-as-promised'));

const rpcNamespace = process.env.KINVEY_RPC_NAMESPACE || 'rpc';

describe('User', () => {
Expand Down Expand Up @@ -742,7 +745,7 @@ describe('User', () => {

describe('me()', () => {
it('should refresh the users data', () => {
const user = new User({ _id: randomString() });
const user = new User({ _id: randomString(), name: randomString() });
const reply = {
_id: user._id,
username: randomString()
Expand All @@ -756,6 +759,7 @@ describe('User', () => {
return user.me()
.then((user) => {
expect(user.username).toEqual(reply.username);
expect(user.data.name).toEqual(undefined);
});
});

Expand All @@ -779,44 +783,6 @@ describe('User', () => {
});
});

it('should set authtoken if one was not provided and user is active user', () => {
const activeUser = User.getActiveUser();
const reply = {
_id: activeUser._id,
username: randomString()
};

// Kinvey API response
nock(activeUser.client.apiHostname, { encodedQueryParams: true })
.get(`${activeUser.pathname}/_me`)
.reply(200, reply);

return activeUser.me()
.then((user) => {
expect(user.username).toEqual(reply.username);
expect(user.authtoken).toEqual(activeUser.authtoken);
});
});

it('should not set authtoken if one was not provided and user is not active user', () => {
const user = new User({ _id: randomString() });
const reply = {
_id: user._id,
username: randomString()
};

// Kinvey API response
nock(user.client.apiHostname, { encodedQueryParams: true })
.get(`${user.pathname}/_me`)
.reply(200, reply);

return user.me()
.then((user) => {
expect(user.username).toEqual(reply.username);
expect(user.authtoken).toEqual(null);
});
});

it('should update active user', () => {
const user = User.getActiveUser();
const reply = {
Expand All @@ -835,22 +801,9 @@ describe('User', () => {
});
});

it('should not update active user if not active user', () => {
const user = new User({ _id: randomString() });
const reply = {
_id: user._id,
username: randomString()
};

// Kinvey API response
nock(user.client.apiHostname, { encodedQueryParams: true })
.get(`${user.pathname}/_me`)
.reply(200, reply);

return user.me()
.then((user) => {
expect(user.data).toNotEqual(User.getActiveUser().data);
});
it('should fail for a user that is not active', () => {
const user = new User();
return chai.expect(user.me()).to.eventually.be.rejected;
});
});

Expand Down