Exemple #1
0
func TestNewWebsiteSetGroupsStores(t *testing.T) {
	w, err := store.NewWebsite(
		&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
		store.SetWebsiteGroupsStores(
			store.TableGroupSlice{
				&store.TableGroup{GroupID: 3, WebsiteID: 2, Name: "Australia", RootCategoryID: 2, DefaultStoreID: 5},
				&store.TableGroup{GroupID: 1, WebsiteID: 1, Name: "DACH Group", RootCategoryID: 2, DefaultStoreID: 2},
				&store.TableGroup{GroupID: 0, WebsiteID: 0, Name: "Default", RootCategoryID: 0, DefaultStoreID: 0},
				&store.TableGroup{GroupID: 2, WebsiteID: 1, Name: "UK Group", RootCategoryID: 2, DefaultStoreID: 4},
			},
			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},
			},
		),
	)
	assert.NoError(t, err)

	dg, err := w.DefaultGroup()
	assert.NotNil(t, dg)
	assert.EqualValues(t, "DACH Group", dg.Data.Name, "get default group: %#v", dg)
	assert.NoError(t, err)

	ds, err := w.DefaultStore()
	assert.NotNil(t, ds)
	assert.EqualValues(t, "at", ds.Data.Code.String, "get default store: %#v", ds)
	assert.NoError(t, err)

	assert.NotNil(t, dg.Stores)
	assert.EqualValues(t, utils.StringSlice{"de", "at", "ch"}, dg.Stores.Codes())

	for _, st := range dg.Stores {
		assert.EqualValues(t, "DACH Group", st.Group.Data.Name)
		assert.EqualValues(t, "Europe", st.Website.Data.Name.String)
	}

	assert.NotNil(t, w.Stores)
	assert.EqualValues(t, utils.StringSlice{"de", "uk", "at", "ch"}, w.Stores.Codes())

	assert.NotNil(t, w.Groups)
	assert.EqualValues(t, utils.Int64Slice{1, 2}, w.Groups.IDs())

	assert.Exactly(t, int64(2), w.StoreID())
	assert.Exactly(t, int64(1), w.GroupID())
	assert.Equal(t, "euro", w.WebsiteCode())
}
Exemple #2
0
func TestNewWebsiteSetGroupsStoresError1(t *testing.T) {
	w, err := store.NewWebsite(
		&store.TableWebsite{WebsiteID: 1, Code: dbr.NewNullString("euro"), Name: dbr.NewNullString("Europe"), SortOrder: 0, DefaultGroupID: 1, IsDefault: dbr.NewNullBool(true)},
		store.SetWebsiteGroupsStores(
			store.TableGroupSlice{
				&store.TableGroup{GroupID: 0, WebsiteID: 0, Name: "Default", RootCategoryID: 0, DefaultStoreID: 0},
			},
			store.TableStoreSlice{
				&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},
			},
		),
	)
	assert.Nil(t, w)
	assert.Contains(t, err.Error(), "Integrity error")
}