Skip to content

Commit

Permalink
Update to latest goflow and add tests for field modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Jun 26, 2020
1 parent cffeda2 commit 401e656
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nyaruka/ezconf v0.2.1
github.com/nyaruka/gocommon v1.2.0
github.com/nyaruka/goflow v0.93.1
github.com/nyaruka/goflow v0.94.0
github.com/nyaruka/librato v1.0.0
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d
github.com/nyaruka/null v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ 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.2.0 h1:gCmVCXYZFwKDMqQj8R1jNlK+7a06khKFq3zX8fBBbzw=
github.com/nyaruka/gocommon v1.2.0/go.mod h1:9Y21Fd6iZXDLHWTRiZAc6b4LQSCi6HEEQK4SB45Yav4=
github.com/nyaruka/goflow v0.93.1 h1:7sh4B6iLEdKS4MMwVqRqI2q7Q8kKd5MKbR0FfXUywjY=
github.com/nyaruka/goflow v0.93.1/go.mod h1:PDah2hr5WzODnUFK4VWWQkg7SqnYclf7P9Ik5u/VOG0=
github.com/nyaruka/goflow v0.94.0 h1:fmUdADrFsJjClsbxJMd0R0uMyYWtQNr4aiURBI31ZKo=
github.com/nyaruka/goflow v0.94.0/go.mod h1:PDah2hr5WzODnUFK4VWWQkg7SqnYclf7P9Ik5u/VOG0=
github.com/nyaruka/librato v1.0.0 h1:Vznj9WCeC1yZXbBYyYp40KnbmXLbEkjKmHesV/v2SR0=
github.com/nyaruka/librato v1.0.0/go.mod h1:pkRNLFhFurOz0QqBz6/DuTFhHHxAubWxs4Jx+J7yUgg=
github.com/nyaruka/logrus_sentry v0.8.2-0.20190129182604-c2962b80ba7d h1:hyp9u36KIwbTCo2JAJ+TuJcJBc+UZzEig7RI/S5Dvkc=
Expand Down
13 changes: 6 additions & 7 deletions models/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/excellent/types"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/goflow/utils/uuids"
"github.com/nyaruka/null"
"github.com/olivere/elastic"
Expand Down Expand Up @@ -421,12 +420,12 @@ func (c *Contact) Status() flows.ContactStatus {

// fieldValueEnvelope is our utility struct for the value of a field
type fieldValueEnvelope struct {
Text types.XText `json:"text"`
Datetime *types.XDateTime `json:"datetime,omitempty"`
Number *types.XNumber `json:"number,omitempty"`
State utils.LocationPath `json:"state,omitempty"`
District utils.LocationPath `json:"district,omitempty"`
Ward utils.LocationPath `json:"ward,omitempty"`
Text types.XText `json:"text"`
Datetime *types.XDateTime `json:"datetime,omitempty"`
Number *types.XNumber `json:"number,omitempty"`
State envs.LocationPath `json:"state,omitempty"`
District envs.LocationPath `json:"district,omitempty"`
Ward envs.LocationPath `json:"ward,omitempty"`
}

type ContactURN struct {
Expand Down
7 changes: 4 additions & 3 deletions models/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/json"
"time"

"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/envs"

"github.com/jmoiron/sqlx"
"github.com/lib/pq"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/utils"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -102,7 +103,7 @@ func loadLocations(ctx context.Context, db sqlx.Queryer, orgID OrgID) ([]assets.
}

// then read it in
hierarchy, err := utils.ReadLocationHierarchy(locationJSON)
hierarchy, err := envs.ReadLocationHierarchy(locationJSON)
if err != nil {
return nil, errors.Wrapf(err, "error unmarshalling hierarchy: %s", string(locationJSON))
}
Expand Down
5 changes: 3 additions & 2 deletions models/locations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package models
import (
"testing"

"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/mailroom/testsuite"

"github.com/stretchr/testify/assert"
)

Expand All @@ -30,7 +31,7 @@ func TestLocations(t *testing.T) {

tcs := []struct {
Name string
Level utils.LocationLevel
Level envs.LocationLevel
Aliases []string
NumChildren int
}{
Expand Down
3 changes: 3 additions & 0 deletions models/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func (o *Org) MaxValueLength() int { return o.env.MaxValueLength() }
// DefaultLocale combines the default languages and countries into a locale
func (o *Org) DefaultLocale() envs.Locale { return o.env.DefaultLocale() }

// LocationResolver returns a resolver for locations
func (o *Org) LocationResolver() envs.LocationResolver { return o.env.LocationResolver() }

// Equal return whether we are equal to the passed in environment
func (o *Org) Equal(env envs.Environment) bool { return o.env.Equal(env) }

Expand Down
5 changes: 4 additions & 1 deletion web/contact/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ func handleModify(ctx context.Context, s *web.Server, r *http.Request) (interfac

results := make(map[models.ContactID]modifyResult)

// create an environment instance with location support
env := flows.NewEnvironment(org.Env(), org.SessionAssets().Locations())

// create scenes for our contacts
scenes := make([]*models.Scene, 0, len(contacts))
for _, contact := range contacts {
Expand All @@ -324,7 +327,7 @@ func handleModify(ctx context.Context, s *web.Server, r *http.Request) (interfac

// apply our modifiers
for _, mod := range mods {
mod.Apply(org.Env(), org.SessionAssets(), flowContact, func(e flows.Event) { result.Events = append(result.Events, e) })
mod.Apply(env, org.SessionAssets(), flowContact, func(e flows.Event) { result.Events = append(result.Events, e) })
}

results[contact.ID()] = result
Expand Down
Loading

0 comments on commit 401e656

Please sign in to comment.