forked from rapidpro/mailroom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'v7.4.1' into update/v7.4.1-mailroom
* Update to latest goflow
- Loading branch information
Showing
121 changed files
with
3,104 additions
and
2,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/nyaruka/goflow/flows" | ||
"github.com/nyaruka/goflow/flows/events" | ||
"github.com/nyaruka/mailroom/core/hooks" | ||
"github.com/nyaruka/mailroom/core/models" | ||
"github.com/nyaruka/mailroom/runtime" | ||
|
||
"github.com/jmoiron/sqlx" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func init() { | ||
models.RegisterEventHandler(events.TypeFlowEntered, handleFlowEntered) | ||
} | ||
|
||
func handleFlowEntered(ctx context.Context, rt *runtime.Runtime, tx *sqlx.Tx, oa *models.OrgAssets, scene *models.Scene, e flows.Event) error { | ||
event := e.(*events.FlowEnteredEvent) | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"contact_uuid": scene.ContactUUID(), | ||
"session_id": scene.SessionID(), | ||
"flow_name": event.Flow.Name, | ||
"flow_uuid": event.Flow.UUID, | ||
}).Debug("flow entered") | ||
|
||
// we've potentially changed contact flow history.. only way to be sure would be loading contacts with their | ||
// flow history, but not sure that is worth it given how likely we are to be updating modified_on anyway | ||
scene.AppendToEventPreCommitHook(hooks.ContactModifiedHook, event) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package handlers_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nyaruka/goflow/flows" | ||
"github.com/nyaruka/goflow/flows/actions" | ||
"github.com/nyaruka/mailroom/core/handlers" | ||
"github.com/nyaruka/mailroom/testsuite" | ||
"github.com/nyaruka/mailroom/testsuite/testdata" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFlowEntered(t *testing.T) { | ||
ctx, rt, _, _ := testsuite.Get() | ||
|
||
defer testsuite.Reset(testsuite.ResetAll) | ||
|
||
oa := testdata.Org1.Load(rt) | ||
|
||
flow, err := oa.FlowByID(testdata.PickANumber.ID) | ||
assert.NoError(t, err) | ||
|
||
tcs := []handlers.TestCase{ | ||
{ | ||
Actions: handlers.ContactActionMap{ | ||
testdata.Cathy: []flows.Action{ | ||
actions.NewEnterFlow(handlers.NewActionUUID(), flow.Reference(), false), | ||
}, | ||
}, | ||
SQLAssertions: []handlers.SQLAssertion{ | ||
{ | ||
SQL: `select count(*) from contacts_contact where current_flow_id = $1`, | ||
Args: []interface{}{flow.ID()}, | ||
Count: 1, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
handlers.RunTestCases(t, ctx, rt, tcs) | ||
} |
Oops, something went wrong.