Skip to content
Snippets Groups Projects
Select Git revision
  • 5aa60fa97d11c601e93f5b714644fd3285e0ba9e
  • master default protected
  • feature/PRXS-3383-CollectionsSort
  • feature/2781-SpacesLoggingMiddleware
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • PRXS-3421-RecursiveReferences
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • feature/3272-GoVersionUp
  • feature/PRXS-3218-HideTemplateActions
  • feature/PRXS-3234-PruneIdents
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

user.go

Blame
  • object_id_test.go 21.96 KiB
    package test
    
    import (
    	"testing"
    
    	"git.perx.ru/perxis/perxis-go/id"
    	_ "git.perx.ru/perxis/perxis-go/id/system"
    	"git.perx.ru/perxis/perxis-go/pkg/clients"
    	"git.perx.ru/perxis/perxis-go/pkg/collections"
    	"git.perx.ru/perxis/perxis-go/pkg/environments"
    	"git.perx.ru/perxis/perxis-go/pkg/items"
    	"git.perx.ru/perxis/perxis-go/pkg/locales"
    	"git.perx.ru/perxis/perxis-go/pkg/organizations"
    	"git.perx.ru/perxis/perxis-go/pkg/roles"
    	"git.perx.ru/perxis/perxis-go/pkg/spaces"
    	"git.perx.ru/perxis/perxis-go/pkg/users"
    	"github.com/stretchr/testify/require"
    )
    
    func Test_OrganizationId(t *testing.T) {
    
    	tests := []struct {
    		name   string
    		in     any
    		out    string
    		result *id.ObjectId
    		err    error
    	}{
    		{
    			name:   "valid string",
    			in:     "/orgs/<org_id>",
    			result: &id.ObjectId{Descriptor: &id.OrganizationId{OrganizationID: "<org_id>"}},
    		},
    		{
    			name:   "valid object",
    			in:     &organizations.Organization{ID: "<org_id>"},
    			out:    "/orgs/<org_id>",
    			result: &id.ObjectId{Descriptor: &id.OrganizationId{OrganizationID: "<org_id>"}},
    		},
    		{
    			name:   "valid map",
    			in:     map[string]any{"type": "organization", "org_id": "<org_id>"},
    			out:    "/orgs/<org_id>",
    			result: &id.ObjectId{Descriptor: &id.OrganizationId{OrganizationID: "<org_id>"}},
    		},
    		{
    			name:   "invalid map",
    			in:     map[string]any{"type": "organization"},
    			out:    "/orgs/<org_id>",
    			result: &id.ObjectId{Descriptor: &id.OrganizationId{OrganizationID: "<org_id>"}},
    			err:    id.ErrInvalidID,
    		},
    	}
    
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			i, err := id.NewObjectId(tt.in)
    
    			if tt.err != nil {
    				require.ErrorIs(t, err, tt.err)
    				return
    			}
    
    			require.NoError(t, err)
    			require.Equal(t, tt.result, i)
    			if tt.out == "" {
    				require.Equal(t, tt.in, i.String())
    			} else {
    				require.Equal(t, tt.out, i.String())
    			}