Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jun 9, 2021
1 parent 4069639 commit e55ba07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
20 changes: 19 additions & 1 deletion flows/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flows_test

import (
"encoding/json"
"fmt"
"io/ioutil"
"testing"
"time"
Expand Down Expand Up @@ -34,6 +35,13 @@ func TestContact(t *testing.T) {
"roles": ["send", "receive"],
"country": "US"
}
],
"ticketers": [
{
"uuid": "d605bb96-258d-4097-ad0a-080937db2212",
"name": "Support Tickets",
"type": "mailgun"
}
]
}`))
require.NoError(t, err)
Expand Down Expand Up @@ -128,7 +136,7 @@ func TestContact(t *testing.T) {

assert.Equal(t, 0, contact.Tickets().Count())

ticket := flows.OpenTicket(sa.Ticketers().Get("19dc6346-9623-4fe4-be80-538d493ecdf5"), "New ticket", "I have issues")
ticket := flows.OpenTicket(sa.Ticketers().Get("d605bb96-258d-4097-ad0a-080937db2212"), "New ticket", "I have issues")
contact.Tickets().Add(ticket)

assert.Equal(t, 1, contact.Tickets().Count())
Expand Down Expand Up @@ -166,6 +174,16 @@ func TestContact(t *testing.T) {
assert.True(t, contact.ClearURNs()) // did have URNs
assert.False(t, contact.ClearURNs())
assert.Equal(t, flows.URNList{}, contact.URNs())

marshaled, err := jsonx.Marshal(contact)
require.NoError(t, err)

fmt.Println(string(marshaled))

unmarshaled, err := flows.ReadContact(sa, marshaled, assets.PanicOnMissing)
require.NoError(t, err)

assert.True(t, contact.Equal(unmarshaled))
}

func TestReadContact(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions flows/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/excellent/types"
"github.com/nyaruka/goflow/utils"
"github.com/pkg/errors"
)

// TicketUUID is the UUID of a ticket
Expand Down Expand Up @@ -66,7 +65,7 @@ func (t *Ticket) Context(env envs.Environment) map[string]types.XValue {

type ticketEnvelope struct {
UUID TicketUUID `json:"uuid" validate:"required,uuid4"`
Ticketer *assets.TicketerReference `json:"ticketer" validate:"required,dive"`
Ticketer *assets.TicketerReference `json:"ticketer" validate:"omitempty,dive"`
Subject string `json:"subject"`
Body string `json:"body"`
ExternalID string `json:"external_id,omitempty"`
Expand All @@ -78,7 +77,7 @@ func ReadTicket(sa SessionAssets, data []byte, missing assets.MissingCallback) (
e := &ticketEnvelope{}

if err := utils.UnmarshalAndValidate(data, e); err != nil {
return nil, errors.Wrap(err, "unable to read ticket")
return nil, err
}

ticketer := sa.Ticketers().Get(e.Ticketer.UUID)
Expand Down
3 changes: 3 additions & 0 deletions flows/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func TestTickets(t *testing.T) {
missingRefs = append(missingRefs, ref)
}

_, err = flows.ReadTicket(sa, []byte(`{}`), missing)
assert.EqualError(t, err, "field 'uuid' is required")

ticket1, err := flows.ReadTicket(sa, []byte(`{
"uuid": "349c851f-3f8e-4353-8bf2-8e90b6d73530",
"ticketer": {"uuid": "0a0b5ce4-35c9-47b7-b124-40258f0a5b53", "name": "Deleted"},
Expand Down

0 comments on commit e55ba07

Please sign in to comment.