-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
828201c
commit 33437cd
Showing
5 changed files
with
176 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package flows_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nyaruka/gocommon/uuids" | ||
"github.com/nyaruka/goflow/assets" | ||
"github.com/nyaruka/goflow/assets/static" | ||
"github.com/nyaruka/goflow/envs" | ||
"github.com/nyaruka/goflow/excellent/types" | ||
"github.com/nyaruka/goflow/flows" | ||
"github.com/nyaruka/goflow/flows/engine" | ||
"github.com/nyaruka/goflow/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOptIns(t *testing.T) { | ||
defer uuids.SetGenerator(uuids.DefaultGenerator) | ||
uuids.SetGenerator(uuids.NewSeededGenerator(12345)) | ||
|
||
env := envs.NewBuilder().Build() | ||
|
||
source, err := static.NewSource([]byte(`{ | ||
"channels": [ | ||
{ | ||
"uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", | ||
"name": "Facebook", | ||
"address": "457547478475", | ||
"schemes": [ | ||
"facebook" | ||
], | ||
"roles": [ | ||
"send", | ||
"receive" | ||
] | ||
} | ||
], | ||
"optins": [ | ||
{ | ||
"uuid": "248be71d-78e9-4d71-a6c4-9981d369e5cb", | ||
"name": "Joke Of The Day", | ||
"channel": { | ||
"uuid": "58e9b092-fe42-4173-876c-ff45a14a24fe", | ||
"name": "Facebook" | ||
} | ||
} | ||
] | ||
}`)) | ||
require.NoError(t, err) | ||
|
||
sa, err := engine.NewSessionAssets(env, source, nil) | ||
require.NoError(t, err) | ||
|
||
jotd := sa.OptIns().Get("248be71d-78e9-4d71-a6c4-9981d369e5cb") | ||
assert.Equal(t, assets.OptInUUID("248be71d-78e9-4d71-a6c4-9981d369e5cb"), jotd.UUID()) | ||
assert.Equal(t, "Joke Of The Day", jotd.Name()) | ||
assert.Equal(t, "Facebook", jotd.Channel().Name()) | ||
assert.Equal(t, assets.NewOptInReference("248be71d-78e9-4d71-a6c4-9981d369e5cb", "Joke Of The Day"), jotd.Reference()) | ||
|
||
// check use in expressions | ||
test.AssertXEqual(t, types.NewXObject(map[string]types.XValue{ | ||
"__default__": types.NewXText("Joke Of The Day"), | ||
"uuid": types.NewXText("248be71d-78e9-4d71-a6c4-9981d369e5cb"), | ||
"name": types.NewXText("Joke Of The Day"), | ||
"channel": types.NewXObject(map[string]types.XValue{ | ||
"__default__": types.NewXText("Facebook"), | ||
"uuid": types.NewXText("58e9b092-fe42-4173-876c-ff45a14a24fe"), | ||
"name": types.NewXText("Facebook"), | ||
"address": types.NewXText("457547478475"), | ||
}), | ||
}), flows.Context(env, jotd)) | ||
|
||
assert.Nil(t, (*flows.OptIn)(nil).Reference()) | ||
} |
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