func TestNewGroupSetStores(t *testing.T) { g, err := store.NewGroup( &store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2}, nil, // this is just for to confuse the NewGroup ApplyOption function store.SetGroupStores( store.TableStoreSlice{ &store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true}, &store.TableStore{StoreID: 5, Code: dbr.NewNullString("au"), WebsiteID: 2, GroupID: 3, Name: "Australia", SortOrder: 10, IsActive: true}, &store.TableStore{StoreID: 1, Code: dbr.NewNullString("de"), WebsiteID: 1, GroupID: 1, Name: "Germany", SortOrder: 10, IsActive: true}, &store.TableStore{StoreID: 4, Code: dbr.NewNullString("uk"), WebsiteID: 1, GroupID: 2, Name: "UK", SortOrder: 10, IsActive: true}, &store.TableStore{StoreID: 2, Code: dbr.NewNullString("at"), WebsiteID: 1, GroupID: 1, Name: "Österreich", SortOrder: 20, IsActive: true}, &store.TableStore{StoreID: 6, Code: dbr.NewNullString("nz"), WebsiteID: 2, GroupID: 3, Name: "Kiwi", SortOrder: 30, IsActive: true}, &store.TableStore{StoreID: 3, Code: dbr.NewNullString("ch"), WebsiteID: 1, GroupID: 1, Name: "Schweiz", SortOrder: 30, IsActive: true}, }, &store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)}, ), ) assert.NoError(t, err) assert.NotNil(t, g.Stores) assert.EqualValues(t, utils.StringSlice{"de", "at", "ch"}, g.Stores.Codes()) gDefaultStore, err := g.DefaultStore() assert.NoError(t, err) assert.EqualValues(t, "euro", gDefaultStore.Website.Data.Code.String) assert.EqualValues(t, "DACH Group", gDefaultStore.Group.Data.Name) assert.EqualValues(t, "at", gDefaultStore.Data.Code.String) }
func TestNewGroupSetStoresErrorWebsiteIncorrect(t *testing.T) { g, err := store.NewGroup( &store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2}, store.SetGroupStores( store.TableStoreSlice{ &store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true}, }, &store.TableWebsite{WebsiteID: 2, Code: dbr.NewNullString("oz"), Name: dbr.NewNullString("OZ"), SortOrder: 20, DefaultGroupID: 3, IsDefault: dbr.NewNullBool(false)}, ), ) assert.Nil(t, g) assert.EqualError(t, store.ErrGroupWebsiteIntegrityFailed, err.Error()) }
func TestNewGroupSetStoresErrorWebsiteIsNil(t *testing.T) { g, err := store.NewGroup( &store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2}, nil, store.SetGroupStores( store.TableStoreSlice{ &store.TableStore{StoreID: 0, Code: dbr.NewNullString("admin"), WebsiteID: 0, GroupID: 0, Name: "Admin", SortOrder: 0, IsActive: true}, }, nil, ), ) assert.Nil(t, g) assert.EqualError(t, store.ErrGroupWebsiteNotFound, err.Error()) }