Skip to content

Commit

Permalink
Fix package import and ticketer contract implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
koallann committed Oct 5, 2020
1 parent 5c9ef85 commit 00fa663
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions services/tickets/rocketchat/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package rocketchat
import (
"bytes"
"fmt"
"github.com/nyaruka/goflow/utils/httpx"
"github.com/nyaruka/goflow/utils/jsonx"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
"github.com/pkg/errors"
"io"
"net/http"
Expand Down Expand Up @@ -125,8 +125,8 @@ func (c *Client) CloseRoom(visitor *Visitor) (*httpx.Trace, error) {
}

type VisitorMsg struct {
Visitor Visitor `json:"visitor"`
Text string `json:"text"`
Visitor Visitor `json:"visitor"`
Text string `json:"text"`
}

func (c *Client) SendMessage(msg *VisitorMsg) (string, *httpx.Trace, error) {
Expand Down
9 changes: 4 additions & 5 deletions services/tickets/rocketchat/client_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rocketchat_test

import (
"github.com/nyaruka/goflow/utils/httpx"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/mailroom/services/tickets/rocketchat"
"github.com/stretchr/testify/assert"
"net/http"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestCloseRoom(t *testing.T) {
}))

client := rocketchat.NewClient(http.DefaultClient, nil, baseURL, secret)
visitor := &rocketchat.Visitor{ Token: "1234" }
visitor := &rocketchat.Visitor{Token: "1234"}

_, err := client.CloseRoom(visitor)
assert.EqualError(t, err, "unable to connect to server")
Expand All @@ -88,8 +88,8 @@ func TestSendMessage(t *testing.T) {

client := rocketchat.NewClient(http.DefaultClient, nil, baseURL, secret)
msg := &rocketchat.VisitorMsg{
Visitor: rocketchat.Visitor{ Token: "1234" },
Text: "Can you help me?",
Visitor: rocketchat.Visitor{Token: "1234"},
Text: "Can you help me?",
}

_, _, err := client.SendMessage(msg)
Expand All @@ -98,7 +98,6 @@ func TestSendMessage(t *testing.T) {
_, _, err = client.SendMessage(msg)
assert.EqualError(t, err, "Could not find a room for visitor token: 1234")


id, trace, err := client.SendMessage(msg)
assert.NoError(t, err)
assert.Equal(t, id, "tyLrD97j8TFZmT3Y6")
Expand Down
8 changes: 4 additions & 4 deletions services/tickets/rocketchat/service.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package rocketchat

import (
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/goflow/utils/httpx"
"github.com/nyaruka/goflow/utils/jsonx"
"github.com/nyaruka/goflow/utils/uuids"
"github.com/nyaruka/mailroom/models"
"github.com/pkg/errors"
"net/http"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (s *service) Open(session flows.Session, subject, body string, logHTTP flow
return flows.NewTicket(ticketUUID, s.ticketer.Reference(), subject, body, roomID), nil
}

func (s *service) Forward(ticket *models.Ticket, msgUUID flows.MsgUUID, text string, logHTTP flows.HTTPLogCallback) error {
func (s *service) Forward(ticket *models.Ticket, msgUUID flows.MsgUUID, text string, attachments []utils.Attachment, logHTTP flows.HTTPLogCallback) error {
visitor := Visitor{
Token: VisitorToken(ticket.ContactID()).String(),
}
Expand Down
10 changes: 5 additions & 5 deletions services/tickets/rocketchat/service_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package rocketchat_test

import (
"github.com/nyaruka/gocommon/dates"
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/assets/static/types"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/test"
"github.com/nyaruka/goflow/utils/dates"
"github.com/nyaruka/goflow/utils/httpx"
"github.com/nyaruka/goflow/utils/uuids"
"github.com/nyaruka/mailroom/models"
"github.com/nyaruka/mailroom/services/tickets/rocketchat"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -85,11 +85,11 @@ func TestOpenAndForward(t *testing.T) {
"contact-display": "Cathy",
})
logger = &flows.HTTPLogger{}
err = svc.Forward(dbTicket, flows.MsgUUID("4fa340ae-1fb0-4666-98db-2177fe9bf31c"), "It's urgent", logger.Log)
err = svc.Forward(dbTicket, flows.MsgUUID("4fa340ae-1fb0-4666-98db-2177fe9bf31c"), "It's urgent", nil, logger.Log)
assert.EqualError(t, err, "error calling RocketChat: unable to connect to server")

logger = &flows.HTTPLogger{}
err = svc.Forward(dbTicket, flows.MsgUUID("4fa340ae-1fb0-4666-98db-2177fe9bf31c"), "It's urgent", logger.Log)
err = svc.Forward(dbTicket, flows.MsgUUID("4fa340ae-1fb0-4666-98db-2177fe9bf31c"), "It's urgent", nil, logger.Log)
assert.Equal(t, 1, len(logger.Logs))
test.AssertSnapshot(t, "forward_message", logger.Logs[0].Request)
}
Expand Down
2 changes: 1 addition & 1 deletion services/tickets/rocketchat/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func handleEventCallback(ctx context.Context, s *web.Server, r *http.Request, l
return err, http.StatusBadRequest, nil
}

_, err = tickets.SendReply(ctx, s.DB, s.RP, ticket, data.Text)
_, err = tickets.SendReply(ctx, s.DB, s.RP, s.Storage, ticket, data.Text, nil)

case "close-room":
err = models.CloseTickets(ctx, s.DB, nil, []*models.Ticket{ticket}, false, l)
Expand Down

0 comments on commit 00fa663

Please sign in to comment.