Esempio n. 1
0
  it_('Should find and add friend', function * () {
    var friend = yield Friend.findAndAddFriend(SeedObj.user1Id.user_id, 'GregB');
    expect(friend.name).to.equal('Greg Brady');
    expect(friend.username).to.equal('GregB');

    // - if friend's username does not exist
  });
Esempio n. 2
0
UserAPI.post('/friends', function (request, response) {
  var searchString = request.body.searchString.trim().toLowerCase();
  var user_id = request.body.user_id;

  Friends.findAndAddFriend(user_id, searchString)
    .then((friend) => {
      // Just start the async call, we don't have to continue the chain.
      User.findUserById(user_id)
        .then((requestingUser) => io.to(friend.user_id).emit('new_friend', requestingUser));

      return friend;
    })
    .then(sendStatusAndData(response, 201))
    .catch(sendStatusAndError(response, 500, 'Server error creating friendship'));
});