Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zostay committed Jan 16, 2024
1 parent 4d00455 commit dac4b88
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions pkg/text/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package text_test

import (
"html/template"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/zostay/today/pkg/ref"
"github.com/zostay/today/pkg/text"
)

const fjn41 = `Beloved, do not believe every spirit, but test the spirits to see whether they are from God, for many false prophets have gone out into the world.`

type testResolver struct {
lastRef *ref.Resolved
}

func (t *testResolver) Verse(ref *ref.Resolved) (string, error) {
t.lastRef = ref
return fjn41, nil
}

func (t *testResolver) VerseHTML(ref *ref.Resolved) (template.HTML, error) {
t.lastRef = ref
return fjn41, nil
}

var _ text.Resolver = (*testResolver)(nil)

func TestService(t *testing.T) {

Check failure on line 32 in pkg/text/service_test.go

View workflow job for this annotation

GitHub Actions / test

Function TestService missing the call to method parallel
tr := &testResolver{}
svc := text.NewService(tr)
assert.NotNil(t, svc)

b, err := ref.Canonical.Book("1 John")
require.NoError(t, err)
require.NotNil(t, b)

txt, err := svc.Verse("1 John 4:1")
assert.NoError(t, err)
assert.Equal(t, fjn41, txt)
assert.Equal(t, &ref.Resolved{
Book: b,
First: ref.CV{Chapter: 4, Verse: 1},
Last: ref.CV{Chapter: 4, Verse: 1},
}, tr.lastRef)

htxt, err := svc.VerseHTML("1 John 4:1")
assert.NoError(t, err)
assert.Equal(t, template.HTML(fjn41), htxt)

Check failure on line 52 in pkg/text/service_test.go

View workflow job for this annotation

GitHub Actions / test

G203: The used method does not auto-escape HTML. This can potentially lead to 'Cross-site Scripting' vulnerabilities, in case the attacker controls the input. (gosec)
assert.Equal(t, &ref.Resolved{
Book: b,
First: ref.CV{Chapter: 4, Verse: 1},
Last: ref.CV{Chapter: 4, Verse: 1},
}, tr.lastRef)
}

0 comments on commit dac4b88

Please sign in to comment.