Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove dialog action from lex event #240

Merged
merged 5 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions events/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type LexEvent struct {
OutputDialogMode string `json:"outputDialogMode,omitempty"`
CurrentIntent *LexCurrentIntent `json:"currentIntent,omitempty"`
AlternativeIntents []LexAlternativeIntents `json:"alternativeIntents,omitempty"`
DialogAction *LexDialogAction `json:"dialogAction,omitempty"`
// Deprecated: the DialogAction field is never populated by Lex events
DialogAction *LexDialogAction `json:"dialogAction,omitempty"`
}

type LexBot struct {
Expand Down Expand Up @@ -77,5 +78,4 @@ type Attachment struct {
func (h *LexEvent) Clear() {
h.Bot = nil
h.CurrentIntent = nil
h.DialogAction = nil
}
42 changes: 28 additions & 14 deletions events/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,41 @@ import (
)

func TestLexEventMarshaling(t *testing.T) {
tests := []struct {
filePath string
}{{"./testdata/lex-response.json"}, {"./testdata/lex-event.json"}}
inputJSON := test.ReadJSONFromFile(t, "./testdata/lex-event.json")

for _, te := range tests {
inputJSON := test.ReadJSONFromFile(t, te.filePath)
var inputEvent LexEvent
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

var inputEvent LexEvent
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

assert.JSONEq(t, string(inputJSON), string(outputJSON))
func TestLexResponseMarshaling(t *testing.T) {
inputJSON := test.ReadJSONFromFile(t, "./testdata/lex-response.json")

var inputEvent LexResponse
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestLexMarshalingMalformedJson(t *testing.T) {
test.TestMalformedJson(t, LexEvent{})
}

func TestLexResponseMalformedJson(t *testing.T) {
test.TestMalformedJson(t, LexResponse{})
}