File tree Expand file tree Collapse file tree 2 files changed +11
-20
lines changed
packages/accounts-mongo/src Expand file tree Collapse file tree 2 files changed +11
-20
lines changed Original file line number Diff line number Diff line change @@ -150,15 +150,12 @@ class Mongo {
150
150
}
151
151
152
152
async setProfile ( userId : string , profile : Object ) : Promise < Object > {
153
- const ret = await this . collection . update ( { _id : userId } , {
153
+ await this . collection . update ( { _id : userId } , {
154
154
$set : {
155
155
profile,
156
156
[ this . options . timestamps . updatedAt ] : Date . now ( ) ,
157
157
} ,
158
158
} ) ;
159
- if ( ret . result . nModified === 0 ) {
160
- throw new Error ( 'User not found' ) ;
161
- }
162
159
const user = await this . findUserById ( userId ) ;
163
160
return user && user . profile ;
164
161
}
Original file line number Diff line number Diff line change @@ -15,19 +15,22 @@ const session = {
15
15
userAgent : 'user agent' ,
16
16
} ;
17
17
18
+ function dropDatabase ( cb ) {
19
+ db . dropDatabase ( ( err ) => {
20
+ if ( err ) return cb ( err ) ;
21
+ return cb ( ) ;
22
+ } ) ;
23
+ }
24
+
18
25
function createConnection ( cb ) {
19
26
const url = 'mongodb://localhost:27017/accounts-mongo-tests' ;
20
27
mongodb . MongoClient . connect ( url , ( err , dbArg ) => {
21
28
db = dbArg ;
22
29
mongo = new Mongo ( db ) ;
23
- cb ( err ) ;
24
- } ) ;
25
- }
26
-
27
- function dropDatabase ( cb ) {
28
- db . dropDatabase ( ( err ) => {
29
30
if ( err ) return cb ( err ) ;
30
- return cb ( ) ;
31
+ return dropDatabase ( ( error ) => {
32
+ cb ( error ) ;
33
+ } ) ;
31
34
} ) ;
32
35
}
33
36
@@ -292,15 +295,6 @@ describe('Mongo', () => {
292
295
} ) ;
293
296
294
297
describe ( 'setProfile' , ( ) => {
295
- it ( 'should throw if user is not found' , async ( ) => {
296
- try {
297
- await mongo . setProfile ( 'unknowuser' , { } ) ;
298
- throw new Error ( ) ;
299
- } catch ( err ) {
300
- expect ( err . message ) . toEqual ( 'User not found' ) ;
301
- }
302
- } ) ;
303
-
304
298
it ( 'should change profile' , async ( ) => {
305
299
const userId = await mongo . createUser ( user ) ;
306
300
await delay ( 10 ) ;
You can’t perform that action at this time.
0 commit comments