diff --git a/pachca.go b/pachca.go index 4911b6a..93ff8d6 100644 --- a/pachca.go +++ b/pachca.go @@ -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) } diff --git a/pachca_test.go b/pachca_test.go index b96931d..86814bd 100644 --- a/pachca_test.go +++ b/pachca_test.go @@ -9,6 +9,7 @@ package pachca import ( "testing" + "time" . "github.com/essentialkaos/check" ) @@ -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(`MalformedPOSTRequestThe body of your POST request is not well-formed multipart/form-data./26dbc55e-ab66-4d23-9334-6b684e25ebf8`) + 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:]") +}