Backend: Add unit tests for internal/entity

This commit is contained in:
Theresa Gresch 2020-07-10 10:29:56 +02:00
parent 62c8830a89
commit b480bbefcc
2 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package entity
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestLocationMap_Get(t *testing.T) {
t.Run("get existing location", func(t *testing.T) {
r := LocationFixtures.Get("mexico")
assert.Equal(t, "Adosada Platform", r.LocName)
assert.Equal(t, "s2:85d1ea7d382c", r.ID)
assert.IsType(t, Location{}, r)
})
t.Run("get not existing location", func(t *testing.T) {
r := LocationFixtures.Get("Fusion 3333")
assert.Equal(t, "zz", r.ID)
assert.IsType(t, Location{}, r)
})
}
func TestLocationMap_Pointer(t *testing.T) {
t.Run("get existing location pointer", func(t *testing.T) {
r := LocationFixtures.Pointer("mexico")
assert.Equal(t, "Adosada Platform", r.LocName)
assert.Equal(t, "s2:85d1ea7d382c", r.ID)
assert.IsType(t, &Location{}, r)
})
t.Run("get not existing location pointer", func(t *testing.T) {
r := LocationFixtures.Pointer("Fusion 444")
assert.Equal(t, "zz", r.ID)
assert.IsType(t, &Location{}, r)
})
}

View file

@ -44,6 +44,11 @@ func TestLocation_Keywords(t *testing.T) {
r := m.Keywords() r := m.Keywords()
assert.Equal(t, []string{"camping", "caravan", "kwazulu-natal", "lobotes", "mandeni", "park", "south-africa"}, r) assert.Equal(t, []string{"camping", "caravan", "kwazulu-natal", "lobotes", "mandeni", "park", "south-africa"}, r)
}) })
t.Run("place id empty", func(t *testing.T) {
m := &Location{}
r := m.Keywords()
assert.Empty(t, r)
})
} }
func TestLocation_Find(t *testing.T) { func TestLocation_Find(t *testing.T) {
@ -63,3 +68,26 @@ func TestLocation_Find(t *testing.T) {
assert.Equal(t, "maps: reverse lookup disabled", err.Error()) assert.Equal(t, "maps: reverse lookup disabled", err.Error())
}) })
} }
func TestFirstOrCreateLocation(t *testing.T) {
t.Run("id empty", func(t *testing.T) {
loc := &Location{}
assert.Nil(t, FirstOrCreateLocation(loc))
})
t.Run("place id empty", func(t *testing.T) {
loc := &Location{ID: "1234jhy"}
assert.Nil(t, FirstOrCreateLocation(loc))
})
t.Run("success", func(t *testing.T) {
loc := LocationFixtures.Pointer("caravan park")
result := FirstOrCreateLocation(loc)
if result == nil {
t.Fatal("result should not be nil")
}
assert.NotEmpty(t, result.ID)
})
}