Skip to content

Commit 9aa9fab

Browse files
Fixed api functions
1 parent f7ca17a commit 9aa9fab

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

api/http/healthcheck_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestHealthCheck(t *testing.T) {
2828
{
2929
name: "Test if HealthCheck returns correct response",
3030
mock: func() {
31-
// No mocks needed for this simple function
31+
mockLogger.EXPECT().NewInfo(gomock.Any()).Times(1)
3232
},
3333
assertions: func(res error, rec *httptest.ResponseRecorder) {
3434
if assert.NoError(t, res) {

api/http/receivemessage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func (integrator *APIIntegrator) ReceiveMessage(c echo.Context) error {
2727
ToUserID: req.ToUserID,
2828
Timestamp: req.Timestamp,
2929
})
30-
if isOnline && err != nil {
31-
integrator.Logger.NewError(fmt.Sprintf("[Integrator][ReceiveMesssage] Error when sending message to online user, err: %s", err.Error()))
30+
if err != nil {
31+
integrator.Logger.NewError(fmt.Sprintf("[Integrator][ReceiveMesssage] Error when sending message to user with ID %s, online: %v, err: %s", req.ToUserID, isOnline, err.Error()))
3232
return c.JSON(http.StatusInternalServerError, structs.ErrorRet{
3333
Error: err.Error(),
3434
})

api/http/receivemessage_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ func TestReceiveMessage(t *testing.T) {
5050
ToUserID: "user2",
5151
Timestamp: "2025-04-02T06:53:00Z",
5252
}).Return(true, nil).Times(1)
53+
mockLogger.EXPECT().NewInfo(gomock.Any()).Times(1)
5354
},
5455
assertions: func(res error, rec *httptest.ResponseRecorder) {
5556
if assert.NoError(t, res) {
5657
assert.Equal(t, http.StatusOK, rec.Code)
5758
expected, _ := json.Marshal(ReceiveMessageRes{
5859
IsOnline: true,
5960
})
60-
assert.Equal(t, expected, rec.Body.String())
61+
assert.Equal(t, string(expected)+"\n", rec.Body.String())
6162
}
6263
},
6364
},
@@ -78,14 +79,15 @@ func TestReceiveMessage(t *testing.T) {
7879
ToUserID: "user2",
7980
Timestamp: "2025-04-02T06:53:00Z",
8081
}).Return(false, nil).Times(1)
82+
mockLogger.EXPECT().NewInfo(gomock.Any()).Times(1)
8183
},
8284
assertions: func(res error, rec *httptest.ResponseRecorder) {
8385
if assert.NoError(t, res) {
8486
assert.Equal(t, http.StatusOK, rec.Code)
8587
expected, _ := json.Marshal(ReceiveMessageRes{
8688
IsOnline: false,
8789
})
88-
assert.Equal(t, expected, rec.Body.String())
90+
assert.Equal(t, string(expected)+"\n", rec.Body.String())
8991
}
9092
},
9193
},
@@ -105,7 +107,8 @@ func TestReceiveMessage(t *testing.T) {
105107
Type: 1,
106108
ToUserID: "user2",
107109
Timestamp: "2025-04-02T06:53:00Z",
108-
}).Return(errors.New("foo")).Times(1)
110+
}).Return(false, errors.New("foo")).Times(1)
111+
mockLogger.EXPECT().NewError(gomock.Any()).Times(1)
109112
},
110113
assertions: func(res error, rec *httptest.ResponseRecorder) {
111114
if assert.NoError(t, res) {
@@ -120,7 +123,9 @@ func TestReceiveMessage(t *testing.T) {
120123
{
121124
name: "Test if wrong body returns error",
122125
wrongBody: true,
123-
mock: func() {},
126+
mock: func() {
127+
mockLogger.EXPECT().NewError(gomock.Any()).Times(1)
128+
},
124129
assertions: func(res error, rec *httptest.ResponseRecorder) {
125130
if assert.NoError(t, res) {
126131
assert.Equal(t, http.StatusInternalServerError, rec.Code)

api/http/registeraccount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (integrator APIIntegrator) RegisterAccount(c echo.Context) error {
2121
})
2222
}
2323
//Validate password length. Since we're using BCrypt it must be 72 characters or less, starting from the 0 index.
24-
if len(req.Password) < 72 {
24+
if len(req.Password) > 72 {
2525
integrator.Logger.NewInfo(fmt.Sprintf("[Integrator][RegisterAccount] Password is not shorter than 72 bytes, ID: %s", req.UserID))
2626
return c.JSON(http.StatusBadRequest, structs.ErrorRet{
2727
Error: "",

cmd/app/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ redis:
1111

1212
database:
1313
dsn: "user:pass@tcp(mysql:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"
14-
pepper: "x"
14+

0 commit comments

Comments
 (0)