@@ -6,6 +6,17 @@ const Parse = require('../../node');
6
6
7
7
const TestObject = Parse . Object . extend ( 'TestObject' ) ;
8
8
9
+ class CustomUser extends Parse . User {
10
+ constructor ( attributes ) {
11
+ super ( attributes ) ;
12
+ }
13
+
14
+ doSomething ( ) {
15
+ return 5 ;
16
+ }
17
+ }
18
+ Parse . Object . registerSubclass ( 'CustomUser' , CustomUser ) ;
19
+
9
20
describe ( 'Parse User' , ( ) => {
10
21
beforeAll ( ( ) => {
11
22
Parse . initialize ( 'integration' , null , 'notsosecret' ) ;
@@ -509,4 +520,46 @@ describe('Parse User', () => {
509
520
expect ( error . message ) . toBe ( 'Object not found.' ) ;
510
521
}
511
522
} ) ;
523
+
524
+ it ( 'can signUp user with subclass' , async ( ) => {
525
+ Parse . User . enableUnsafeCurrentUser ( ) ;
526
+
527
+ const customUser = new CustomUser ( { foo : 'bar' } ) ;
528
+ customUser . setUsername ( 'username' ) ;
529
+ customUser . setPassword ( 'password' ) ;
530
+
531
+ const user = await customUser . signUp ( ) ;
532
+
533
+ expect ( user instanceof CustomUser ) . toBe ( true ) ;
534
+ expect ( user . doSomething ( ) ) . toBe ( 5 ) ;
535
+ expect ( user . get ( 'foo' ) ) . toBe ( 'bar' ) ;
536
+ } ) ;
537
+
538
+ it ( 'can logIn user with subclass' , async ( ) => {
539
+ Parse . User . enableUnsafeCurrentUser ( ) ;
540
+
541
+ await Parse . User . signUp ( 'username' , 'password' ) ;
542
+
543
+ const customUser = new CustomUser ( { foo : 'bar' } ) ;
544
+ customUser . setUsername ( 'username' ) ;
545
+ customUser . setPassword ( 'password' ) ;
546
+
547
+ const user = await customUser . logIn ( ) ;
548
+
549
+ expect ( user instanceof CustomUser ) . toBe ( true ) ;
550
+ expect ( user . doSomething ( ) ) . toBe ( 5 ) ;
551
+ expect ( user . get ( 'foo' ) ) . toBe ( 'bar' ) ;
552
+ } ) ;
553
+
554
+ it ( 'can signUp / logIn user with subclass static' , async ( ) => {
555
+ Parse . User . enableUnsafeCurrentUser ( ) ;
556
+
557
+ let user = await CustomUser . signUp ( 'username' , 'password' ) ;
558
+ expect ( user instanceof CustomUser ) . toBe ( true ) ;
559
+ expect ( user . doSomething ( ) ) . toBe ( 5 ) ;
560
+
561
+ user = await CustomUser . logIn ( 'username' , 'password' ) ;
562
+ expect ( user instanceof CustomUser ) . toBe ( true ) ;
563
+ expect ( user . doSomething ( ) ) . toBe ( 5 ) ;
564
+ } ) ;
512
565
} ) ;
0 commit comments