Skip to content

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
michellebrier committed Jan 14, 2023
1 parent d2e5bb0 commit 6d0dc6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
19 changes: 10 additions & 9 deletions comms/internal/rpcz/chat_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpcz
import (
"fmt"
"math/rand"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -37,10 +38,10 @@ func TestChatBlocking(t *testing.T) {

// validate user1Id can block user2Id
{
hashUserId, err := misc.EncodeHashId(int(user2Id))
encodedUserId, err := misc.EncodeHashId(int(user2Id))
assert.NoError(t, err)
exampleRpc := schema.RawRPC{
Params: []byte(fmt.Sprintf(`{"user_id": "%s"}`, hashUserId)),
Params: []byte(fmt.Sprintf(`{"user_id": "%s"}`, encodedUserId)),
}

chatBlock := string(schema.RPCMethodChatBlock)
Expand All @@ -49,7 +50,7 @@ func TestChatBlocking(t *testing.T) {
assert.NoError(t, err)
}

// user user1Id blocks user2Id
// user1Id blocks user2Id
messageTs := time.Now()
err = chatBlock(tx, user1Id, user2Id, messageTs)
assert.NoError(t, err)
Expand All @@ -64,14 +65,14 @@ func TestChatBlocking(t *testing.T) {

// validate user1Id and user2Id cannot create a chat with each other
{
chatId := "chat1"
useruser1IdHashId, err := misc.EncodeHashId(int(user1Id))
chatId := strconv.Itoa(seededRand.Int())
user1IdEncoded, err := misc.EncodeHashId(int(user1Id))
assert.NoError(t, err)
useruser2IdHashId, err := misc.EncodeHashId(int(user2Id))
user2IdEncoded, err := misc.EncodeHashId(int(user2Id))
assert.NoError(t, err)

exampleRpc := schema.RawRPC{
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "1"}, {"user_id": "%s", "invite_code": "2"}]}`, chatId, useruser1IdHashId, useruser2IdHashId)),
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "1"}, {"user_id": "%s", "invite_code": "2"}]}`, chatId, user1IdEncoded, user2IdEncoded)),
}

chatCreate := string(schema.RPCMethodChatCreate)
Expand All @@ -83,7 +84,7 @@ func TestChatBlocking(t *testing.T) {
// validate user1Id and user2Id cannot message each other
{
// Assume chat was already created before blocking
chatId := "chat1"
chatId := strconv.Itoa(seededRand.Int())
SetupChatWithMembers(t, tx, chatId, user1Id, user2Id)

exampleRpc := schema.RawRPC{
Expand All @@ -96,7 +97,7 @@ func TestChatBlocking(t *testing.T) {
assert.ErrorContains(t, err, "Cannot chat with a user you have blocked or user who has blocked you")
}

// user user1Id unblocks user2Id
// user1Id unblocks user2Id
err = chatUnblock(tx, user1Id, user2Id)
assert.NoError(t, err)
assertBlocked(user1Id, user2Id, messageTs, 0)
Expand Down
22 changes: 11 additions & 11 deletions comms/internal/rpcz/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ func TestRateLimit(t *testing.T) {
user4Id := seededRand.Int31()
user5Id := seededRand.Int31()

useruser1IdEncoded, err := misc.EncodeHashId(int(user1Id))
user1IdEncoded, err := misc.EncodeHashId(int(user1Id))
assert.NoError(t, err)
useruser3IdEncoded, err := misc.EncodeHashId(int(user3Id))
user3IdEncoded, err := misc.EncodeHashId(int(user3Id))
assert.NoError(t, err)
useruser4IdEncoded, err := misc.EncodeHashId(int(user4Id))
user4IdEncoded, err := misc.EncodeHashId(int(user4Id))
assert.NoError(t, err)
useruser5IdEncoded, err := misc.EncodeHashId(int(user5Id))
user5IdEncoded, err := misc.EncodeHashId(int(user5Id))
assert.NoError(t, err)

// user1Id created a new chat with user2Id 48 hours ago
chatId1 := "chat1"
chatId1 := strconv.Itoa(seededRand.Int())
chatTs := time.Now().UTC().Add(-time.Hour * time.Duration(48))
_, err = tx.Exec("insert into chat (chat_id, created_at, last_message_at) values ($1, $2, $2)", chatId1, chatTs)
assert.NoError(t, err)
Expand Down Expand Up @@ -119,9 +119,9 @@ func TestRateLimit(t *testing.T) {
assert.ErrorContains(t, err, "User has exceeded the maximum number of new messages")

// user1Id creates a new chat with user3Id (1 chat created in 24h)
chatId2 := "chat2"
chatId2 := strconv.Itoa(seededRand.Int())
createRpc := schema.RawRPC{
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "%s"}, {"user_id": "%s", "invite_code": "%s"}]}`, chatId2, useruser1IdEncoded, chatId2, useruser3IdEncoded, chatId2)),
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "%s"}, {"user_id": "%s", "invite_code": "%s"}]}`, chatId2, user1IdEncoded, chatId2, user3IdEncoded, chatId2)),
}
err = Validators[chatCreate](tx, user1Id, createRpc)
assert.NoError(t, err)
Expand All @@ -147,9 +147,9 @@ func TestRateLimit(t *testing.T) {
assert.NoError(t, err)

// user1Id creates a new chat with user4Id (2 chats created in 24h)
chatId3 := "chat3"
chatId3 := strconv.Itoa(seededRand.Int())
createRpc = schema.RawRPC{
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "%s"}, {"user_id": "%s", "invite_code": "%s"}]}`, chatId3, useruser1IdEncoded, chatId3, useruser4IdEncoded, chatId3)),
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "%s"}, {"user_id": "%s", "invite_code": "%s"}]}`, chatId3, user1IdEncoded, chatId3, user4IdEncoded, chatId3)),
}
err = Validators[chatCreate](tx, user1Id, createRpc)
assert.NoError(t, err)
Expand All @@ -176,9 +176,9 @@ func TestRateLimit(t *testing.T) {

// user1Id creates a new chat with user5Id (3 chats created in 24h)
// Blocked by rate limiter (hit max # new chats)
chatId4 := "chat4"
chatId4 := strconv.Itoa(seededRand.Int())
createRpc = schema.RawRPC{
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "%s"}, {"user_id": "%s", "invite_code": "%s"}]}`, chatId4, useruser1IdEncoded, chatId2, useruser5IdEncoded, chatId4)),
Params: []byte(fmt.Sprintf(`{"chat_id": "%s", "invites": [{"user_id": "%s", "invite_code": "%s"}, {"user_id": "%s", "invite_code": "%s"}]}`, chatId4, user1IdEncoded, chatId2, user5IdEncoded, chatId4)),
}
err = Validators[chatCreate](tx, user1Id, createRpc)
assert.ErrorContains(t, err, "An invited user has exceeded the maximum number of new chats")
Expand Down

0 comments on commit 6d0dc6e

Please sign in to comment.