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

UserSubclass.logIn and UserSubclass.signUp returns subclass #756

Merged
merged 2 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 41 additions & 0 deletions integration/test/ParseUserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ const Parse = require('../../node');

const TestObject = Parse.Object.extend('TestObject');

class CustomUser extends Parse.User {
constructor(attributes) {
super(attributes);
}

doSomething() {
return 5;
}
}
Parse.Object.registerSubclass('CustomUser', CustomUser);

describe('Parse User', () => {
beforeAll(() => {
Parse.initialize('integration', null, 'notsosecret');
Expand Down Expand Up @@ -509,4 +520,34 @@ describe('Parse User', () => {
expect(error.message).toBe('Object not found.');
}
});

it('can signUp user with subclass', async () => {
Parse.User.enableUnsafeCurrentUser();

const customUser = new CustomUser({ foo: 'bar' });
customUser.setUsername('username');
customUser.setPassword('password');

const user = await customUser.signUp();

expect(user instanceof CustomUser).toBe(true);
expect(user.doSomething()).toBe(5);
expect(user.get('foo')).toBe('bar');
});

it('can logIn user with subclass', async () => {
Parse.User.enableUnsafeCurrentUser();

await Parse.User.signUp('username', 'password');

const customUser = new CustomUser({ foo: 'bar' });
customUser.setUsername('username');
customUser.setPassword('password');

const user = await customUser.logIn();

expect(user instanceof CustomUser).toBe(true);
expect(user.doSomething()).toBe(5);
expect(user.get('foo')).toBe('bar');
});
});
4 changes: 2 additions & 2 deletions src/ParseUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class ParseUser extends ParseObject {
attrs = attrs || {};
attrs.username = username;
attrs.password = password;
const user = new ParseUser(attrs);
const user = new this(attrs);
return user.signUp({}, options);
}

Expand Down Expand Up @@ -600,7 +600,7 @@ class ParseUser extends ParseObject {
)
);
}
const user = new ParseUser();
const user = new this();
user._finishFetch({ username: username, password: password });
return user.logIn(options);
}
Expand Down