Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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{})
}