Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 26, 2024
1 parent e61736d commit 1da5880
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pachca.go
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,7 @@ func (f ChatFilter) ToQuery() req.Query {
query["last_message_at_before"] = formatDate(f.LastMessageBefore)
}

if !f.LastMessageBefore.IsZero() {
if !f.LastMessageAfter.IsZero() {
query["last_message_at_after"] = formatDate(f.LastMessageAfter)
}

Expand Down
52 changes: 52 additions & 0 deletions pachca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package pachca

import (
"testing"
"time"

. "github.com/essentialkaos/check"
)
Expand Down Expand Up @@ -425,3 +426,54 @@ func (s *PachcaSuite) TestWebhookHelpers(c *C) {
c.Assert(delete.IsDelete(), Equals, true)
c.Assert(message.Command(), Equals, "find-user")
}

func (s *PachcaSuite) TestChatFilterToQuery(c *C) {
cf := ChatFilter{
Public: true,
LastMessageAfter: time.Now(),
LastMessageBefore: time.Now().AddDate(0, 0, 1),
}

q := cf.ToQuery()

c.Assert(q["availability"], Equals, "public")
c.Assert(q["last_message_at_before"], Not(Equals), "")
c.Assert(q["last_message_at_after"], Not(Equals), "")
}

func (s *PachcaSuite) TestAux(c *C) {
cc := &Client{BatchSize: 1}
c.Assert(cc.getBatchSize(), Equals, 5)

err := extractS3Error("TEST")
c.Assert(err.Error(), Equals, "Unknown error")
err = extractS3Error(`<Error><Code>MalformedPOSTRequest</Code><Message>The body of your POST request is not well-formed multipart/form-data.</Message><Resource>/</Resource><RequestId>26dbc55e-ab66-4d23-9334-6b684e25ebf8</RequestId></Error>`)
c.Assert(err.Error(), Equals, "The body of your POST request is not well-formed multipart/form-data.")

c.Assert(guessFileType("text.txt"), Equals, FILE_TYPE_FILE)
c.Assert(guessFileType("TEXT.PNG"), Equals, FILE_TYPE_IMAGE)
}

func (s *PachcaSuite) TestJSONDateDecoder(c *C) {
d := &Date{}

c.Assert(d.UnmarshalJSON([]byte(`ABCD`)), NotNil)

c.Assert(d.UnmarshalJSON([]byte(`null`)), IsNil)
c.Assert(d.IsZero(), Equals, true)

c.Assert(d.UnmarshalJSON([]byte(`"2024-08-08T09:11:50.368Z"`)), IsNil)
c.Assert(d.IsZero(), Equals, false)
}

func (s *PachcaSuite) TestAPIErrorToString(c *C) {
err := APIError{
Key: "system",
Value: "",
Message: "Ошибка выполнения запроса",
Code: "unhandled",
StatusCode: 400,
}

c.Assert(err.Error(), Equals, "(unhandled) Ошибка выполнения запроса [system:]")
}

0 comments on commit 1da5880

Please sign in to comment.