Skip to content

Commit

Permalink
chore: handle nil steps and session
Browse files Browse the repository at this point in the history
  • Loading branch information
zikani03 committed Jul 12, 2024
1 parent c2cd20c commit 547059d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/africastalking/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
)

func ConcatText(session *core.Session) string {
if session == nil {
return ""
}

inputs := make([]string, 0)
for _, step := range session.Steps {
inputs = append(inputs, step.Text)
Expand Down
13 changes: 13 additions & 0 deletions pkg/africastalking/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ import (
"github.com/stretchr/testify/assert"
)

func TestConcatTextWithNilSession(t *testing.T) {
got := africastalking.ConcatText(nil)
assert.Equal(t, "", got)
}

func TestConcatTextWithNilSteps(t *testing.T) {
got := africastalking.ConcatText(&core.Session{
Steps: nil,
})

assert.Equal(t, "", got)
}

func TestConcatText(t *testing.T) {
got := africastalking.ConcatText(&core.Session{
Steps: []*core.Step{
Expand Down

0 comments on commit 547059d

Please sign in to comment.