Skip to content

Commit

Permalink
Merge pull request #8 from js-accounts/fix-profile
Browse files Browse the repository at this point in the history
Don't throw on setProfile
  • Loading branch information
TimMikeladze authored and Aetherall committed Mar 11, 2018
1 parent 35e51d0 commit cc9bf07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
5 changes: 1 addition & 4 deletions packages/accounts-mongo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,12 @@ class Mongo {
}

async setProfile(userId: string, profile: Object): Promise<Object> {
const ret = await this.collection.update({ _id: userId }, {
await this.collection.update({ _id: userId }, {
$set: {
profile,
[this.options.timestamps.updatedAt]: Date.now(),
},
});
if (ret.result.nModified === 0) {
throw new Error('User not found');
}
const user = await this.findUserById(userId);
return user && user.profile;
}
Expand Down
26 changes: 10 additions & 16 deletions packages/accounts-mongo/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ const session = {
userAgent: 'user agent',
};

function dropDatabase(cb) {
db.dropDatabase((err) => {
if (err) return cb(err);
return cb();
});
}

function createConnection(cb) {
const url = 'mongodb://localhost:27017/accounts-mongo-tests';
mongodb.MongoClient.connect(url, (err, dbArg) => {
db = dbArg;
mongo = new Mongo(db);
cb(err);
});
}

function dropDatabase(cb) {
db.dropDatabase((err) => {
if (err) return cb(err);
return cb();
return dropDatabase((error) => {
cb(error);
});
});
}

Expand Down Expand Up @@ -292,15 +295,6 @@ describe('Mongo', () => {
});

describe('setProfile', () => {
it('should throw if user is not found', async () => {
try {
await mongo.setProfile('unknowuser', {});
throw new Error();
} catch (err) {
expect(err.message).toEqual('User not found');
}
});

it('should change profile', async () => {
const userId = await mongo.createUser(user);
await delay(10);
Expand Down

0 comments on commit cc9bf07

Please sign in to comment.