[hw-8] add: integration tests

This commit is contained in:
3ybacTuK
2025-07-29 01:10:16 +03:00
parent 61757d1a52
commit 815089ea3f
3 changed files with 242 additions and 5 deletions

View File

@@ -77,8 +77,6 @@ func (r *commentsRepo) InsertComment(ctx context.Context, comment *entity.Commen
r.idMx.Lock()
id := r.curID*1000 + shardID
r.curID++
r.idMx.Unlock()
req := &InsertCommentParams{
UserID: comment.UserID,
@@ -92,6 +90,9 @@ func (r *commentsRepo) InsertComment(ctx context.Context, comment *entity.Commen
return nil, err
}
r.curID++
r.idMx.Unlock()
return mapComment(c), nil
}
@@ -125,12 +126,17 @@ func (r *commentsRepo) ListCommentsByUser(ctx context.Context, userID int64) ([]
return nil, err2
}
alreadyMerged := make(map[int64]struct{}, len(l1)+len(l2))
merged := make([]*entity.Comment, 0, len(l1)+len(l2))
for _, com := range l1 {
merged = append(merged, mapComment(com))
alreadyMerged[com.Sku] = struct{}{}
}
for _, com := range l2 {
merged = append(merged, mapComment(com))
if _, ok := alreadyMerged[com.Sku]; !ok {
merged = append(merged, mapComment(com))
alreadyMerged[com.Sku] = struct{}{}
}
}
return merged, nil