Backend: Add unit tests for internal/entity
This commit is contained in:
parent
62c8830a89
commit
b480bbefcc
34
internal/entity/location_fixtures_test.go
Normal file
34
internal/entity/location_fixtures_test.go
Normal 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)
|
||||
})
|
||||
}
|
|
@ -44,6 +44,11 @@ func TestLocation_Keywords(t *testing.T) {
|
|||
r := m.Keywords()
|
||||
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) {
|
||||
|
@ -63,3 +68,26 @@ func TestLocation_Find(t *testing.T) {
|
|||
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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue