@@ -10,6 +10,12 @@ const SchemaController = require('../lib/Controllers/SchemaController');
10
10
const TestUtils = require ( '../lib/TestUtils' ) ;
11
11
12
12
const userSchema = SchemaController . convertSchemaToAdapterSchema ( { className : '_User' , fields : Object . assign ( { } , SchemaController . defaultColumns . _Default , SchemaController . defaultColumns . _User ) } ) ;
13
+ const headers = {
14
+ 'Content-Type' : 'application/json' ,
15
+ 'X-Parse-Application-Id' : 'test' ,
16
+ 'X-Parse-REST-API-Key' : 'rest' ,
17
+ 'X-Parse-Installation-Id' : 'yolo'
18
+ }
13
19
14
20
describe_only_db ( 'mongo' ) ( 'miscellaneous' , ( ) => {
15
21
it ( 'test rest_create_app' , function ( done ) {
@@ -67,91 +73,79 @@ describe('miscellaneous', function() {
67
73
} , done . fail ) ;
68
74
} ) ;
69
75
70
- it ( 'fail to create a duplicate username' , async done => {
71
- try {
72
- await Parse . User . logOut ( ) ;
73
- } catch ( e ) { /* ignore */ }
74
- let numCreated = 0 ;
76
+ it ( 'fail to create a duplicate username' , async ( ) => {
75
77
let numFailed = 0 ;
76
- const p1 = createTestUser ( ) ;
77
- p1 . then ( ( ) => {
78
+ let numCreated = 0 ;
79
+ const p1 = rp . post ( Parse . serverURL + '/users' , {
80
+ json : {
81
+ password : 'asdf' ,
82
+ username : 'u1' ,
83
+
84
+ } ,
85
+ headers
86
+ } ) . then ( ( ) => {
78
87
numCreated ++ ;
79
88
expect ( numCreated ) . toEqual ( 1 ) ;
80
- } )
81
- . catch ( error => {
82
- numFailed ++ ;
83
- expect ( numFailed ) . toEqual ( 1 ) ;
84
- expect ( error . code ) . toEqual ( Parse . Error . USERNAME_TAKEN ) ;
85
- } ) ;
86
- const p2 = createTestUser ( ) ;
87
- p2 . then ( ( ) => {
89
+ } , ( { error } ) => {
90
+ numFailed ++ ;
91
+ expect ( error . code ) . toEqual ( Parse . Error . USERNAME_TAKEN ) ;
92
+ } ) ;
93
+
94
+ const p2 = rp . post ( Parse . serverURL + '/users' , {
95
+ json : {
96
+ password : 'asdf' ,
97
+ username : 'u1' ,
98
+
99
+ } ,
100
+ headers
101
+ } ) . then ( ( ) => {
88
102
numCreated ++ ;
89
- expect ( numCreated ) . toEqual ( 1 ) ;
90
- } )
91
- . catch ( error => {
92
- numFailed ++ ;
93
- expect ( numFailed ) . toEqual ( 1 ) ;
94
- expect ( error . code ) . toEqual ( Parse . Error . USERNAME_TAKEN ) ;
95
- } ) ;
96
- Promise . all ( [ p1 , p2 ] )
97
- . then ( ( ) => {
98
- fail ( 'one of the users should not have been created' ) ;
99
- done ( ) ;
100
- } )
101
- . catch ( ( ) => { } )
102
- . finally ( async ( ) => {
103
- try {
104
- await Parse . User . logOut ( ) ;
105
- } catch ( e ) { /* ignore */ }
106
- done ( ) ;
107
- } ) ;
103
+ } , ( { error } ) => {
104
+ numFailed ++ ;
105
+ expect ( error . code ) . toEqual ( Parse . Error . USERNAME_TAKEN ) ;
106
+ } ) ;
107
+
108
+ await Promise . all ( [ p1 , p2 ] )
109
+ expect ( numFailed ) . toEqual ( 1 ) ;
110
+ expect ( numCreated ) . toBe ( 1 ) ;
108
111
} ) ;
109
112
110
- it ( 'ensure that email is uniquely indexed' , async done => {
111
- try {
112
- await Parse . User . logOut ( ) ;
113
- } catch ( e ) { /* ignore */ }
113
+ it ( 'ensure that email is uniquely indexed' , async ( ) => {
114
114
let numFailed = 0 ;
115
115
let numCreated = 0 ;
116
- const user1 = new Parse . User ( ) ;
117
- user1 . setPassword ( 'asdf' ) ;
118
- user1 . setUsername ( 'u1' ) ;
119
- user1 . setEmail ( '[email protected] ' ) ;
120
- const p1 = user1 . signUp ( ) ;
121
- p1 . then ( ( ) => {
116
+ const p1 = rp . post ( Parse . serverURL + '/users' , {
117
+ json : {
118
+ password : 'asdf' ,
119
+ username : 'u1' ,
120
+
121
+ } ,
122
+ headers
123
+ } ) . then ( ( ) => {
122
124
numCreated ++ ;
123
125
expect ( numCreated ) . toEqual ( 1 ) ;
124
- } , error => {
126
+ } , ( { error } ) => {
125
127
numFailed ++ ;
126
- expect ( numFailed ) . toEqual ( 1 ) ;
127
128
expect ( error . code ) . toEqual ( Parse . Error . EMAIL_TAKEN ) ;
128
129
} ) ;
129
130
130
- const user2 = new Parse . User ( ) ;
131
- user2 . setPassword ( 'asdf' ) ;
132
- user2 . setUsername ( 'u2' ) ;
133
- user2 . setEmail ( '[email protected] ' ) ;
134
- const p2 = user2 . signUp ( ) ;
135
- p2 . then ( ( ) => {
131
+ const p2 = rp . post ( Parse . serverURL + '/users' , {
132
+ json : {
133
+ password : 'asdf' ,
134
+ username : 'u2' ,
135
+
136
+ } ,
137
+ headers
138
+ } ) . then ( ( ) => {
136
139
numCreated ++ ;
137
140
expect ( numCreated ) . toEqual ( 1 ) ;
138
- } , error => {
141
+ } , ( { error } ) => {
139
142
numFailed ++ ;
140
- expect ( numFailed ) . toEqual ( 1 ) ;
141
143
expect ( error . code ) . toEqual ( Parse . Error . EMAIL_TAKEN ) ;
142
144
} ) ;
143
145
144
- Promise . all ( [ p1 , p2 ] )
145
- . then ( ( ) => {
146
- fail ( 'one of the users should not have been created' ) ;
147
- } )
148
- . catch ( ( ) => { } )
149
- . finally ( async ( ) => {
150
- try {
151
- await Parse . User . logOut ( ) ;
152
- } catch ( e ) { /* ignore */ }
153
- done ( ) ;
154
- } ) ;
146
+ await Promise . all ( [ p1 , p2 ] )
147
+ expect ( numFailed ) . toEqual ( 1 ) ;
148
+ expect ( numCreated ) . toBe ( 1 ) ;
155
149
} ) ;
156
150
157
151
it ( 'ensure that if people already have duplicate users, they can still sign up new users' , async done => {
0 commit comments