Add test for country.go

This commit is contained in:
Theresa Gresch 2020-01-06 20:16:31 +01:00
parent 3d990fc3fd
commit 4cf7cd98b1
3 changed files with 42 additions and 22 deletions

View file

@ -5,3 +5,4 @@ INSERT INTO cameras (id, camera_slug, camera_model, camera_make, camera_type, ca
INSERT INTO cameras (id, camera_slug, camera_model, camera_make, camera_type, camera_owner, camera_description, camera_notes, created_at, updated_at, deleted_at) VALUES (5, 'canon-eos-6d', 'EOS 6D', 'Canon', '', '', '', '', '2020-01-06 02:06:35', '2020-01-06 02:06:54', null);
INSERT INTO cameras (id, camera_slug, camera_model, camera_make, camera_type, camera_owner, camera_description, camera_notes, created_at, updated_at, deleted_at) VALUES (6, 'apple-iphone-6', 'iPhone 6', 'Apple', '', '', '', '', '2020-01-06 02:06:42', '2020-01-06 02:06:42', null);
INSERT INTO cameras (id, camera_slug, camera_model, camera_make, camera_type, camera_owner, camera_description, camera_notes, created_at, updated_at, deleted_at) VALUES (7, 'apple-iphone-7', 'iPhone 7', 'Apple', '', '', '', '', '2020-01-06 02:06:51', '2020-01-06 02:06:51', null);
INSERT INTO countries (id, country_slug, country_name, country_description, country_notes, country_photo_id) VALUES ('pp', 'photoprism', 'PhotoPrism', '', '', '');

View file

@ -1,22 +0,0 @@
package entity
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewCountry(t *testing.T) {
t.Run("name Fantasy code fy", func(t *testing.T) {
country := NewCountry("fy", "Fantasy")
assert.Equal(t, "fy", country.ID)
assert.Equal(t, "Fantasy", country.CountryName)
assert.Equal(t, "fantasy", country.CountrySlug)
})
t.Run("name Unknown code Unknown", func(t *testing.T) {
country := NewCountry("", "")
assert.Equal(t, "zz", country.ID)
assert.Equal(t, "Unknown", country.CountryName)
assert.Equal(t, "unknown", country.CountrySlug)
})
}

View file

@ -0,0 +1,41 @@
package query
import (
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/entity"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewCountry(t *testing.T) {
t.Run("name Fantasy code fy", func(t *testing.T) {
country := entity.NewCountry("fy", "Fantasy")
assert.Equal(t, "fy", country.ID)
assert.Equal(t, "Fantasy", country.CountryName)
assert.Equal(t, "fantasy", country.CountrySlug)
})
t.Run("name Unknown code Unknown", func(t *testing.T) {
country := entity.NewCountry("", "")
assert.Equal(t, "zz", country.ID)
assert.Equal(t, "Unknown", country.CountryName)
assert.Equal(t, "unknown", country.CountrySlug)
})
}
func TestCountry_FirstOrCreate(t *testing.T) {
t.Run("country already existing", func(t *testing.T) {
country := entity.NewCountry("pp", "PhotoPrism")
c := config.TestConfig()
country.FirstOrCreate(c.Db())
assert.Equal(t, "pp", country.Code())
assert.Equal(t, "PhotoPrism", country.Name())
})
t.Run("country not yet existing", func(t *testing.T) {
country := entity.NewCountry("wl", "Wonder Land")
c := config.TestConfig()
country.FirstOrCreate(c.Db())
assert.Equal(t, "wl", country.Code())
assert.Equal(t, "Wonder Land", country.Name())
})
}