Esempio n. 1
0
func TestApplyCode(t *testing.T) {
	tests := []struct {
		wantStoreCode   string
		wantWebsiteCode string
		haveCode        string
		s               scope.Scope
		err             error
	}{
		{"", "de1", "de1", scope.WebsiteID, nil},
		{"de2", "", "de2", scope.StoreID, nil},
		{"", "", "de3", scope.GroupID, scope.ErrUnsupportedScope},
		{"", "", "de4", scope.AbsentID, scope.ErrUnsupportedScope},
	}

	for _, test := range tests {
		so, err := scope.SetByCode(test.haveCode, test.s)
		assert.NotNil(t, so)
		if test.err != nil {
			assert.EqualError(t, err, test.err.Error())
		} else {
			assert.NoError(t, err)
			assert.Equal(t, test.s, so.Scope())
			assert.Equal(t, test.wantStoreCode, so.StoreCode())
			assert.Equal(t, test.wantWebsiteCode, so.WebsiteCode())
		}
	}
}
Esempio n. 2
0
func setByCode(scopeCode string) (o scope.Option, err error) {
	err = ValidateStoreCode(scopeCode)
	if err == nil {
		o, err = scope.SetByCode(scopeCode, scope.StoreID)
	}
	return
}