add(test):添加单元测试
This commit is contained in:
@@ -63,7 +63,7 @@ namespace IM_API.Services
|
||||
|
||||
public async Task<List<FriendInfoDto>> GetFriendListAsync(int userId, int page, int limit, bool desc)
|
||||
{
|
||||
var query = _context.Friends.Where(x => x.UserId == userId && x.StatusEnum == FriendStatus.Added);
|
||||
var query = _context.Friends.Where(x => x.UserId == userId && x.Status == (sbyte)FriendStatus.Added);
|
||||
if (desc)
|
||||
{
|
||||
query = query.OrderByDescending(x => x.UserId);
|
||||
@@ -149,14 +149,14 @@ namespace IM_API.Services
|
||||
if(!isExistUser2) throw new BaseException(CodeDefine.USER_NOT_FOUND);
|
||||
// 检查是否已有好友关系或待处理请求
|
||||
bool alreadyExists = await _context.FriendRequests.AnyAsync(x =>
|
||||
x.RequestUser == dto.FromUserId && x.ResponseUser == dto.ToUserId && x.StateEnum == FriendRequestState.Pending
|
||||
x.RequestUser == dto.FromUserId && x.ResponseUser == dto.ToUserId && x.State == (sbyte)FriendRequestState.Pending
|
||||
);
|
||||
if (alreadyExists)
|
||||
throw new BaseException(CodeDefine.FRIEND_REQUEST_EXISTS);
|
||||
|
||||
//检查是否被对方拉黑
|
||||
bool isBlocked = await _context.Friends.AnyAsync(x =>
|
||||
x.UserId == dto.FromUserId && x.FriendId == dto.ToUserId && x.StatusEnum == FriendStatus.Blocked
|
||||
x.UserId == dto.FromUserId && x.FriendId == dto.ToUserId && x.Status == (sbyte)FriendStatus.Blocked
|
||||
);
|
||||
if (isBlocked)
|
||||
throw new BaseException(CodeDefine.FRIEND_REQUEST_REJECTED);
|
||||
|
||||
Reference in New Issue
Block a user