Skip to content

Commit cc9bf07

Browse files
TimMikeladzeAetherall
authored andcommitted
Merge pull request #8 from js-accounts/fix-profile
Don't throw on setProfile
1 parent 35e51d0 commit cc9bf07

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

packages/accounts-mongo/src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,12 @@ class Mongo {
150150
}
151151

152152
async setProfile(userId: string, profile: Object): Promise<Object> {
153-
const ret = await this.collection.update({ _id: userId }, {
153+
await this.collection.update({ _id: userId }, {
154154
$set: {
155155
profile,
156156
[this.options.timestamps.updatedAt]: Date.now(),
157157
},
158158
});
159-
if (ret.result.nModified === 0) {
160-
throw new Error('User not found');
161-
}
162159
const user = await this.findUserById(userId);
163160
return user && user.profile;
164161
}

packages/accounts-mongo/src/index.spec.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ const session = {
1515
userAgent: 'user agent',
1616
};
1717

18+
function dropDatabase(cb) {
19+
db.dropDatabase((err) => {
20+
if (err) return cb(err);
21+
return cb();
22+
});
23+
}
24+
1825
function createConnection(cb) {
1926
const url = 'mongodb://localhost:27017/accounts-mongo-tests';
2027
mongodb.MongoClient.connect(url, (err, dbArg) => {
2128
db = dbArg;
2229
mongo = new Mongo(db);
23-
cb(err);
24-
});
25-
}
26-
27-
function dropDatabase(cb) {
28-
db.dropDatabase((err) => {
2930
if (err) return cb(err);
30-
return cb();
31+
return dropDatabase((error) => {
32+
cb(error);
33+
});
3134
});
3235
}
3336

@@ -292,15 +295,6 @@ describe('Mongo', () => {
292295
});
293296

294297
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-
304298
it('should change profile', async () => {
305299
const userId = await mongo.createUser(user);
306300
await delay(10);

0 commit comments

Comments
 (0)