diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c4b35ebb..eb81c4efa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,7 @@ jobs: uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} - fail_ci_if_error: true + fail_ci_if_error: false release: name: Release diff --git a/core/handlers/msg_created.go b/core/handlers/msg_created.go index 8677ecee0..fc1a8aa2d 100644 --- a/core/handlers/msg_created.go +++ b/core/handlers/msg_created.go @@ -101,8 +101,6 @@ func handleMsgCreated(ctx context.Context, rt *runtime.Runtime, tx *sqlx.Tx, oa if _, valid := validLanguageCodes[languageCode]; !valid { languageCode = "" } - - event.Msg.TextLanguage = envs.Language(languageCode) } } } diff --git a/core/models/msgs.go b/core/models/msgs.go index c7b090eb8..fd876a5f7 100644 --- a/core/models/msgs.go +++ b/core/models/msgs.go @@ -365,9 +365,6 @@ func buildMsgMetadata(m *flows.MsgOut) map[string]interface{} { if m.Topic() != flows.NilMsgTopic { metadata["topic"] = string(m.Topic()) } - if m.TextLanguage != "" { - metadata["text_language"] = m.TextLanguage - } return metadata } @@ -552,8 +549,7 @@ SELECT channel_id, contact_id, contact_urn_id, - org_id, - topup_id + org_id FROM msgs_msg WHERE diff --git a/core/models/msgs_test.go b/core/models/msgs_test.go index c25fecf37..a69087285 100644 --- a/core/models/msgs_test.go +++ b/core/models/msgs_test.go @@ -534,17 +534,17 @@ func insertTestSession(t *testing.T, ctx context.Context, rt *runtime.Runtime, o } func TestSelectContactMessages(t *testing.T) { - ctx, _, db, _ := testsuite.Get() + ctx, rt := testsuite.Runtime() defer testsuite.Reset(testsuite.ResetData) thisMoment := time.Now() - testdata.InsertIncomingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "in 1", models.MsgStatusHandled) - testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "out 1", []utils.Attachment{"image/jpeg:hi.jpg"}, models.MsgStatusSent, false) - testdata.InsertOutgoingMsg(db, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "out 2", nil, models.MsgStatusSent, false) - testdata.InsertOutgoingMsg(db, testdata.Org2, testdata.Org2Channel, testdata.Org2Contact, "out 3", nil, models.MsgStatusSent, false) + testdata.InsertIncomingMsg(rt, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "in 1", models.MsgStatusHandled) + testdata.InsertOutgoingMsg(rt, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "out 1", []utils.Attachment{"image/jpeg:hi.jpg"}, models.MsgStatusSent, false) + testdata.InsertOutgoingMsg(rt, testdata.Org1, testdata.TwilioChannel, testdata.Cathy, "out 2", nil, models.MsgStatusSent, false) + testdata.InsertOutgoingMsg(rt, testdata.Org2, testdata.Org2Channel, testdata.Org2Contact, "out 3", nil, models.MsgStatusSent, false) - msgs, err := models.SelectContactMessages(ctx, db, int(testdata.Cathy.ID), thisMoment) + msgs, err := models.SelectContactMessages(ctx, rt.DB, int(testdata.Cathy.ID), thisMoment) // shoud only return messages for testdata.Cathy assert.NoError(t, err) diff --git a/go.mod b/go.mod index e755b4bd5..5819a106c 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,8 @@ require ( golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 ) +require gopkg.in/go-playground/validator.v9 v9.31.0 // indirect + require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/Shopify/gomail v0.0.0-20220729171026-0784ece65e69 // indirect diff --git a/go.sum b/go.sum index 2990fbf8e..38d81866a 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ github.com/Shopify/gomail v0.0.0-20220729171026-0784ece65e69 h1:gPoXdwo3sKq8qcfM github.com/Shopify/gomail v0.0.0-20220729171026-0784ece65e69/go.mod h1:RS+Gaowa0M+gCuiFAiRMGBCMqxLrNA7TESTU/Wbblm8= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 h1:npHgfD4Tl2WJS3AJaMUi5ynGDPUBfkg3U3fCzDyXZ+4= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= -github.com/aws/aws-sdk-go v1.44.204 h1:7/tPUXfNOHB390A63t6fJIwmlwVQAkAwcbzKsU2/6OQ= -github.com/aws/aws-sdk-go v1.44.204/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go v1.44.305 h1:fU/5lY3WyBjGU9fkmQYd8o4fZu+2RaOv/i+sPaJVvFg= github.com/aws/aws-sdk-go v1.44.305/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/blevesearch/segment v0.9.1 h1:+dThDy+Lvgj5JMxhmOVlgFfkUtZV2kw49xax4+jTfSU= @@ -47,23 +45,12 @@ github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws= github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= @@ -82,14 +69,12 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -104,8 +89,6 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8= github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/nyaruka/ezconf v0.2.1 h1:TDXWoqjqYya1uhou1mAJZg7rgFYL98EB0Tb3+BWtUh0= github.com/nyaruka/ezconf v0.2.1/go.mod h1:ey182kYkw2MIi4XiWe1FR/mzI33WCmTWuceDYYxgnQw= -github.com/nyaruka/gocommon v1.37.0 h1:1wCSJtdjpBQ4FXWQy5zXBSiHENGEpL6sTy5IN79+0Iw= -github.com/nyaruka/gocommon v1.37.0/go.mod h1:HaUQmWPrZfKS9MLnXKQj28zF4KlJrzFou+DGuqT7RbE= github.com/nyaruka/goflow v0.187.0 h1:HvMtTSLNdQwC2hCILkeA7jiffRuN7qpe5dLj4WDWMWY= github.com/nyaruka/goflow v0.187.0/go.mod h1:8O8eCOZWBYYapaAQhRkdD9pYWcon4Mj1LQtxXV/GuXY= github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0= @@ -128,12 +111,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= -github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= -github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= -github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y= github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= @@ -141,8 +120,6 @@ github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NF github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -207,6 +184,9 @@ gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk= gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/mailroom.go b/mailroom.go index 906be83e8..07cd1dc4e 100644 --- a/mailroom.go +++ b/mailroom.go @@ -131,7 +131,6 @@ func (mr *Mailroom) Start() error { } mr.rt.AttachmentStorage = storage.NewS3(s3Client, mr.rt.Config.S3AttachmentsBucket, c.S3Region, s3.BucketCannedACLPublicRead, 32) mr.rt.SessionStorage = storage.NewS3(s3Client, mr.rt.Config.S3SessionsBucket, c.S3Region, s3.ObjectCannedACLPrivate, 32) - mr.rt.LogStorage = storage.NewS3(s3Client, mr.rt.Config.S3LogsBucket, c.S3Region, s3.ObjectCannedACLPrivate, 32) } else { mr.rt.AttachmentStorage = storage.NewFS("_storage/attachments", 0766) mr.rt.SessionStorage = storage.NewFS("_storage/sessions", 0766) diff --git a/mailroom_test.dump b/mailroom_test.dump index 3b20e978b..91f4179b4 100644 Binary files a/mailroom_test.dump and b/mailroom_test.dump differ diff --git a/runtime/config.go b/runtime/config.go index 4fe88c373..39c39b54e 100644 --- a/runtime/config.go +++ b/runtime/config.go @@ -57,7 +57,7 @@ type Config struct { S3Region string `help:"the S3 region we will write attachments to"` S3AttachmentsBucket string `help:"the S3 bucket we will write attachments to"` S3AttachmentsPrefix string `help:"the prefix that will be added to attachment filenames"` - S3SessionBucket string `help:"the S3 bucket we will write attachments to"` + S3SessionsBucket string `help:"the S3 bucket we will write attachments to"` S3SessionPrefix string `help:"the prefix that will be added to attachment filenames"` S3MediaPrefixZendesk string `help:"the prefix that will be added to file attachment names for Zendesk tickets"` S3DisableSSL bool `help:"whether we disable SSL when accessing S3. Should always be set to False unless you're hosting an S3 compatible service within a secure internal network"` @@ -124,7 +124,6 @@ func NewDefaultConfig() *Config { S3AttachmentsBucket: "attachments-bucket", S3AttachmentsPrefix: "attachments/", S3SessionsBucket: "sessions-bucket", - S3LogsBucket: "logs-bucket", S3DisableSSL: false, S3ForcePathStyle: false, diff --git a/services/tickets/rocketchat/client_test.go b/services/tickets/rocketchat/client_test.go index 48b01bb57..feea4a04b 100644 --- a/services/tickets/rocketchat/client_test.go +++ b/services/tickets/rocketchat/client_test.go @@ -42,7 +42,7 @@ func TestCreateRoom(t *testing.T) { assert.EqualError(t, err, "unable to connect to server") _, _, err = client.CreateRoom(room) - assert.EqualError(t, err, "Could not find a department for name: kitchen") + assert.EqualError(t, err, "There's no agents online") id, trace, err := client.CreateRoom(room) assert.NoError(t, err) diff --git a/services/tickets/rocketchat/testdata/TestOpenAndForward_open_ticket.snap b/services/tickets/rocketchat/testdata/TestOpenAndForward_open_ticket.snap index cf7e9ddee..76ab63f5f 100644 --- a/services/tickets/rocketchat/testdata/TestOpenAndForward_open_ticket.snap +++ b/services/tickets/rocketchat/testdata/TestOpenAndForward_open_ticket.snap @@ -1,9 +1,9 @@ GET /api/apps/public/684202ed-1461-4983-9ea7-fde74b15026c/room HTTP/1.1 Host: my.rocket.chat User-Agent: Go-http-client/1.1 -Content-Length: 237 +Content-Length: 199 Authorization: Token **************** Content-Type: application/json Accept-Encoding: gzip -{"visitor":{"token":"1234567","contactUUID":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","email":"foo@bar.com","phone":"+12024561111"},"ticketID":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","sessionStart":"2019-10-07T15:20:30Z"} \ No newline at end of file +{"visitor":{"token":"1234567","contactUUID":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","email":"foo@bar.com","phone":"+12024561111"},"ticketID":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c"} \ No newline at end of file diff --git a/services/tickets/twilioflex/service_test.go b/services/tickets/twilioflex/service_test.go index 8ff0f20ea..72489d3fc 100644 --- a/services/tickets/twilioflex/service_test.go +++ b/services/tickets/twilioflex/service_test.go @@ -24,7 +24,7 @@ import ( ) func TestOpenAndForward(t *testing.T) { - ctx, rt, _, _ := testsuite.Get() + ctx, rt := testsuite.Runtime() testsuite.Reset(testsuite.ResetData | testsuite.ResetStorage) defer dates.SetNowSource(dates.DefaultNowSource) @@ -353,7 +353,7 @@ func TestOpenAndForward(t *testing.T) { } func TestCloseAndReopen(t *testing.T) { - _, rt, _, _ := testsuite.Get() + _, rt := testsuite.Runtime() defer uuids.SetGenerator(uuids.DefaultGenerator) defer httpx.SetRequestor(httpx.DefaultRequestor) diff --git a/services/tickets/twilioflex/testdata/event_callback.json b/services/tickets/twilioflex/testdata/event_callback.json index 24e497830..14d59c09c 100644 --- a/services/tickets/twilioflex/testdata/event_callback.json +++ b/services/tickets/twilioflex/testdata/event_callback.json @@ -123,7 +123,7 @@ }, "db_assertions": [ { - "query": "select count(*) from msgs_msg where direction = 'O' and attachments = '{image/jpeg:https:///_test_media_storage/media/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716}'", + "query": "select count(*) from msgs_msg where direction = 'O' and attachments = '{image/jpeg:https:///_test_attachments_storage/attachments/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716}'", "count": 1 } ] diff --git a/services/tickets/twilioflex/web.go b/services/tickets/twilioflex/web.go index c5da9a193..629e08093 100644 --- a/services/tickets/twilioflex/web.go +++ b/services/tickets/twilioflex/web.go @@ -20,7 +20,7 @@ import ( func init() { base := "/mr/tickets/types/twilioflex" - web.RegisterJSONRoute(http.MethodPost, base+"/event_callback/{ticketer:[a-f0-9\\-]+}/{ticket:[a-f0-9\\-]+}", web.WithHTTPLogs(handleEventCallback)) + web.RegisterRoute(http.MethodPost, base+"/event_callback/{ticketer:[a-f0-9\\-]+}/{ticket:[a-f0-9\\-]+}", web.MarshaledResponse(web.WithHTTPLogs(handleEventCallback))) } type eventCallbackRequest struct { diff --git a/services/tickets/twilioflex/web_test.go b/services/tickets/twilioflex/web_test.go index 2f2109105..ca10a21cd 100644 --- a/services/tickets/twilioflex/web_test.go +++ b/services/tickets/twilioflex/web_test.go @@ -3,19 +3,19 @@ package twilioflex_test import ( "testing" "time" + "github.com/nyaruka/mailroom/testsuite" "github.com/nyaruka/mailroom/testsuite/testdata" - "github.com/nyaruka/mailroom/web" ) func TestEventCallback(t *testing.T) { - ctx, rt, db, _ := testsuite.Get() + ctx, rt := testsuite.Runtime() testsuite.Reset(testsuite.ResetData | testsuite.ResetStorage) defer testsuite.Reset(testsuite.ResetData | testsuite.ResetStorage) ticket := testdata.InsertOpenTicket( - db, + rt, testdata.Org1, testdata.Cathy, testdata.Twilioflex, @@ -26,5 +26,5 @@ func TestEventCallback(t *testing.T) { testdata.Viewer, ) - web.RunWebTests(t, ctx, rt, "testdata/event_callback.json", map[string]string{"cathy_ticket_uuid": string(ticket.UUID)}) + testsuite.RunWebTests(t, ctx, rt, "testdata/event_callback.json", map[string]string{"cathy_ticket_uuid": string(ticket.UUID)}) } diff --git a/services/tickets/wenichats/service_test.go b/services/tickets/wenichats/service_test.go index 2115ec9a9..a87b6feb5 100644 --- a/services/tickets/wenichats/service_test.go +++ b/services/tickets/wenichats/service_test.go @@ -26,7 +26,7 @@ import ( ) func TestOpenAndForward(t *testing.T) { - ctx, rt, _, _ := testsuite.Get() + ctx, rt := testsuite.Runtime() testsuite.Reset(testsuite.ResetData | testsuite.ResetStorage) defer dates.SetNowSource(dates.DefaultNowSource) @@ -264,7 +264,7 @@ func TestOpenAndForward(t *testing.T) { } func TestCloseAndReopen(t *testing.T) { - _, rt, _, _ := testsuite.Get() + _, rt := testsuite.Runtime() defer uuids.SetGenerator(uuids.DefaultGenerator) defer httpx.SetRequestor(httpx.DefaultRequestor) diff --git a/services/tickets/wenichats/testdata/TestOpenAndForward_open_ticket.snap b/services/tickets/wenichats/testdata/TestOpenAndForward_open_ticket.snap index 0c0380731..5b7b7c69d 100644 --- a/services/tickets/wenichats/testdata/TestOpenAndForward_open_ticket.snap +++ b/services/tickets/wenichats/testdata/TestOpenAndForward_open_ticket.snap @@ -1,9 +1,9 @@ POST /v1/external/rooms/ HTTP/1.1 Host: chats-engine.dev.cloud.weni.ai User-Agent: Go-http-client/1.1 -Content-Length: 583 +Content-Length: 532 Authorization: Bearer **************** Content-Type: application/json Accept-Encoding: gzip -{"queue_uuid":"5cc1848a-357c-4de9-9720-45770ec18d11","sector_uuid":"1a4bae05-993c-4f3b-91b5-80f4e09951f2","contact":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","urn":"tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d","groups":[{"uuid":"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d","name":"Testers"},{"uuid":"4f1f98fc-27a7-4a69-bbdb-24744ba739a9","name":"Males"}]},"custom_fields":{"activation_****************":"AACC55","age":"23","country":"brazil","gender":"Male","join_date":"2017-12-02","mood":"angry"},"flow_uuid":"50c3706e-fedb-42c0-8eab-dda3335714b7"} \ No newline at end of file +{"queue_uuid":"5cc1848a-357c-4de9-9720-45770ec18d11","sector_uuid":"1a4bae05-993c-4f3b-91b5-80f4e09951f2","contact":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis","urn":"tel:+12024561111?channel=57f1078f-88aa-46f4-a59a-948a5739c03d","groups":[{"uuid":"b7cf0d83-f1c9-411c-96fd-c511a4cfa86d","name":"Testers"},{"uuid":"4f1f98fc-27a7-4a69-bbdb-24744ba739a9","name":"Males"}]},"custom_fields":{"activation_****************":"AACC55","age":"23","country":"brazil","gender":"Male","join_date":"2017-12-02","mood":"angry"}} \ No newline at end of file diff --git a/services/tickets/wenichats/testdata/event_callback.json b/services/tickets/wenichats/testdata/event_callback.json index eefd77e4d..8bf41f1fd 100644 --- a/services/tickets/wenichats/testdata/event_callback.json +++ b/services/tickets/wenichats/testdata/event_callback.json @@ -99,7 +99,7 @@ }, "db_assertions": [ { - "query": "select count(*) from msgs_msg where direction = 'O' and attachments = '{text/plain:https:///_test_media_storage/media/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716.jpg}'", + "query": "select count(*) from msgs_msg where direction = 'O' and attachments = '{text/plain:https:///_test_attachments_storage/attachments/1/6929/26ea/692926ea-09d6-4942-bd38-d266ec8d3716.jpg}'", "count": 1 } ] diff --git a/services/tickets/wenichats/web.go b/services/tickets/wenichats/web.go index c6ff6ab69..cb0bfe0a2 100644 --- a/services/tickets/wenichats/web.go +++ b/services/tickets/wenichats/web.go @@ -41,7 +41,7 @@ var mediaTypeMaxBodyBytes = map[string]int{ func init() { base := "/mr/tickets/types/wenichats" - web.RegisterJSONRoute(http.MethodPost, base+"/event_callback/{ticketer:[a-f0-9\\-]+}/{ticket:[a-f0-9\\-]+}", web.WithHTTPLogs(handleEventCallback)) + web.RegisterRoute(http.MethodPost, base+"/event_callback/{ticketer:[a-f0-9\\-]+}/{ticket:[a-f0-9\\-]+}", web.MarshaledResponse(web.WithHTTPLogs(handleEventCallback))) } type eventCallbackRequest struct { diff --git a/services/tickets/wenichats/web_test.go b/services/tickets/wenichats/web_test.go index 2969b88d8..238a76653 100644 --- a/services/tickets/wenichats/web_test.go +++ b/services/tickets/wenichats/web_test.go @@ -6,17 +6,16 @@ import ( "github.com/nyaruka/mailroom/testsuite" "github.com/nyaruka/mailroom/testsuite/testdata" - "github.com/nyaruka/mailroom/web" ) func TestEventCallback(t *testing.T) { - ctx, rt, db, _ := testsuite.Get() + ctx, rt := testsuite.Runtime() testsuite.Reset(testsuite.ResetData | testsuite.ResetStorage) defer testsuite.Reset(testsuite.ResetData | testsuite.ResetStorage) ticket := testdata.InsertOpenTicket( - db, + rt, testdata.Org1, testdata.Cathy, testdata.Wenichats, @@ -27,5 +26,5 @@ func TestEventCallback(t *testing.T) { nil, ) - web.RunWebTests(t, ctx, rt, "testdata/event_callback.json", map[string]string{"cathy_ticket_uuid": string(ticket.UUID)}) + testsuite.RunWebTests(t, ctx, rt, "testdata/event_callback.json", map[string]string{"cathy_ticket_uuid": string(ticket.UUID)}) } diff --git a/services/tickets/zendesk/testdata/TestCloseAndReopen_close_tickets.snap b/services/tickets/zendesk/testdata/TestCloseAndReopen_close_tickets.snap deleted file mode 100644 index f24d2c1bd..000000000 --- a/services/tickets/zendesk/testdata/TestCloseAndReopen_close_tickets.snap +++ /dev/null @@ -1,9 +0,0 @@ -PUT /api/v2/tickets/update_many.json?ids=12,14 HTTP/1.1 -Host: nyaruka.zendesk.com -User-Agent: Go-http-client/1.1 -Content-Length: 30 -Authorization: Bearer **************** -Content-Type: application/json -Accept-Encoding: gzip - -{"ticket":{"status":"closed"}} \ No newline at end of file diff --git a/services/tickets/zendesk/testdata/TestCloseAndReopen_reopen_tickets.snap b/services/tickets/zendesk/testdata/TestCloseAndReopen_reopen_tickets.snap deleted file mode 100644 index 89354cd6d..000000000 --- a/services/tickets/zendesk/testdata/TestCloseAndReopen_reopen_tickets.snap +++ /dev/null @@ -1,9 +0,0 @@ -PUT /api/v2/tickets/update_many.json?ids=14 HTTP/1.1 -Host: nyaruka.zendesk.com -User-Agent: Go-http-client/1.1 -Content-Length: 28 -Authorization: Bearer **************** -Content-Type: application/json -Accept-Encoding: gzip - -{"ticket":{"status":"open"}} \ No newline at end of file diff --git a/services/tickets/zendesk/testdata/TestOpenAndForward_forward_message.snap b/services/tickets/zendesk/testdata/TestOpenAndForward_forward_message.snap deleted file mode 100644 index 08b2950f6..000000000 --- a/services/tickets/zendesk/testdata/TestOpenAndForward_forward_message.snap +++ /dev/null @@ -1,9 +0,0 @@ -POST /api/v2/any_channel/push.json HTTP/1.1 -Host: nyaruka.zendesk.com -User-Agent: Go-http-client/1.1 -Content-Length: 425 -Authorization: Bearer **************** -Content-Type: application/json -Accept-Encoding: gzip - -{"instance_push_id":"1234-abcd","request_id":"sesame:1570461700000000000","external_resources":[{"external_id":"ca5607f0-cba8-4c94-9cd5-c4fbc24aa767","message":"It's urgent","thread_id":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","created_at":"2019-10-07T15:21:39Z","author":{"external_id":"6393abc0-283d-4c9b-a1b3-641a035c34bf","name":"Cathy"},"allow_channelback":true,"file_urls":["https:///api/v2/file/0123/attachment1.jpg"]}]} \ No newline at end of file diff --git a/services/tickets/zendesk/testdata/TestOpenAndForward_open_ticket.snap b/services/tickets/zendesk/testdata/TestOpenAndForward_open_ticket.snap deleted file mode 100644 index 15ffdd99b..000000000 --- a/services/tickets/zendesk/testdata/TestOpenAndForward_open_ticket.snap +++ /dev/null @@ -1,9 +0,0 @@ -POST /api/v2/any_channel/push.json HTTP/1.1 -Host: nyaruka.zendesk.com -User-Agent: Go-http-client/1.1 -Content-Length: 708 -Authorization: Bearer **************** -Content-Type: application/json -Accept-Encoding: gzip - -{"instance_push_id":"1234-abcd","request_id":"sesame:1570461696000000000","external_resources":[{"external_id":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","message":"Cookies","thread_id":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c","created_at":"2019-10-07T15:21:35Z","author":{"external_id":"5d76d86b-3bb9-4d5a-b822-c9d86f5d8e4f","name":"Ryan Lewis"},"allow_channelback":true,"fields":[{"id":"message","value":"Cookies"},{"id":"priority","value":"high"},{"id":"subject","value":"Where are my cookies?"},{"id":"description","value":"I want to know where is my cookie."},{"id":"21938362","value":"hd_3000"},{"id":"tags","value":["TAG_01","TAG_02"]},{"id":"external_id","value":"59d74b86-3e2f-4a93-aece-b05d2fdcde0c"}]}]} \ No newline at end of file diff --git a/services/tickets/zendesk/testdata/target.json b/services/tickets/zendesk/testdata/target.json new file mode 100644 index 000000000..3e237dc17 --- /dev/null +++ b/services/tickets/zendesk/testdata/target.json @@ -0,0 +1,132 @@ +[ + { + "label": "404 response if URL malformed", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/XYZ", + "body": {}, + "status": 404, + "response": { + "error": "not found: /mr/tickets/types/zendesk/target/XYZ" + } + }, + { + "label": "404 response if no such ticketer", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/122a91d5-cfc0-4777-88ef-d5b1e013e031", + "body": {}, + "status": 404, + "response": { + "error": "no such ticketer 122a91d5-cfc0-4777-88ef-d5b1e013e031" + } + }, + { + "label": "unauthorized response if basic auth missing", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/4ee6d4f3-f92b-439b-9718-8da90c05490b", + "body": { + "event": "status_changed", + "id": 1234, + "status": "New" + }, + "status": 401, + "response": { + "status": "unauthorized" + } + }, + { + "label": "unauthorized response if basic auth fails", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/4ee6d4f3-f92b-439b-9718-8da90c05490b", + "headers": { + "Authorization": "Basic emVuZGVzazoyMzUy" + }, + "body": { + "event": "status_changed", + "id": 1234, + "status": "New" + }, + "status": 401, + "response": { + "status": "unauthorized" + } + }, + { + "label": "error response if missing required field", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/4ee6d4f3-f92b-439b-9718-8da90c05490b", + "headers": { + "Authorization": "Basic emVuZGVzazpzZXNhbWU=" + }, + "body": { + "event": "status_changed", + "status": "New" + }, + "status": 400, + "response": { + "error": "field 'id' is required" + } + }, + { + "label": "ignored response if can't find ticket", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/4ee6d4f3-f92b-439b-9718-8da90c05490b", + "headers": { + "Authorization": "Basic emVuZGVzazpzZXNhbWU=" + }, + "body": { + "event": "status_changed", + "id": 34567845, + "status": "New" + }, + "status": 200, + "response": { + "status": "ignored" + } + }, + { + "label": "ticket updated if credentials correct", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/4ee6d4f3-f92b-439b-9718-8da90c05490b", + "headers": { + "Authorization": "Basic emVuZGVzazpzZXNhbWU=" + }, + "body": { + "event": "status_changed", + "id": 1234, + "status": "Solved" + }, + "status": 200, + "response": { + "status": "handled" + }, + "db_assertions": [ + { + "query": "select count(*) from tickets_ticket where status = 'C'", + "count": 1 + } + ] + }, + { + "label": "ticket updated also when status is non-English", + "method": "POST", + "path": "/mr/tickets/types/zendesk/target/4ee6d4f3-f92b-439b-9718-8da90c05490b", + "headers": { + "Authorization": "Basic emVuZGVzazpzZXNhbWU=" + }, + "body": { + "event": "status_changed", + "id": 1234, + "status": "Abierto" + }, + "status": 200, + "response": { + "status": "handled" + }, + "db_assertions": [ + { + "query": "select count(*) from tickets_ticket where status = 'O'", + "count": 1 + } + ] + } +] \ No newline at end of file diff --git a/services/tickets/zendesk/web.go b/services/tickets/zendesk/web.go index e66e2fd58..24cb42ab6 100644 --- a/services/tickets/zendesk/web.go +++ b/services/tickets/zendesk/web.go @@ -198,7 +198,7 @@ func processChannelEvent(ctx context.Context, rt *runtime.Runtime, event *channe } // delete config values that came from adding this account - remConfig := utils.Set([]string{configPushID, configPushToken, configTargetID, configTriggerID}) + remConfig := utils.Set([]string{configPushID, configPushToken, configWebhookID, configTriggerID}) if err := ticketer.UpdateConfig(ctx, rt.DB, nil, remConfig); err != nil { return errors.Wrapf(err, "error updating config for ticketer %s", ticketer.UUID()) }