|
|
|
|
@@ -29,7 +29,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
testName string
|
|
|
|
|
|
|
|
|
|
queryExecutor func(ctrl *gomock.Controller) database.QueryExecutor
|
|
|
|
|
orgRepo func(ctrl *gomock.Controller) domain.OrganizationRepository
|
|
|
|
|
orgRepo func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository
|
|
|
|
|
|
|
|
|
|
inputID string
|
|
|
|
|
inputName string
|
|
|
|
|
@@ -52,13 +52,13 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when retrieving org fails should return error",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
Times(1).
|
|
|
|
|
Return(nil, getErr)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
@@ -66,7 +66,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when org name is not changed should return name not changed error",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -75,7 +75,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
ID: "org-1",
|
|
|
|
|
Name: "test org update",
|
|
|
|
|
}, nil)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
@@ -83,7 +83,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when org is inactive should return not found error",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -93,7 +93,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
Name: "old org name",
|
|
|
|
|
State: domain.OrgStateInactive,
|
|
|
|
|
}, nil)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
@@ -101,7 +101,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when setting domain info fails should return error",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -116,7 +116,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
{IsPrimary: false, IsVerified: true, Domain: "old primary org name"},
|
|
|
|
|
},
|
|
|
|
|
}, nil)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
@@ -124,7 +124,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when org update fails should return error",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -144,7 +144,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
Update(gomock.Any(), repo.IDCondition("org-1"), "instance-1", repo.SetName("test org update")).
|
|
|
|
|
Times(1).
|
|
|
|
|
Return(int64(0), updateErr)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
@@ -154,7 +154,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
testName: "when org update returns 0 rows updated should return not found error",
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -175,7 +175,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
Update(gomock.Any(), repo.IDCondition("org-1"), "instance-1", repo.SetName("test org update")).
|
|
|
|
|
Times(1).
|
|
|
|
|
Return(int64(0), nil)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
expectedError: domain.NewOrgNotFoundError("DOM-7PfSUn"),
|
|
|
|
|
expectedOldDomainName: gu.Ptr("old-org-name."),
|
|
|
|
|
@@ -183,7 +183,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when org update returns more than 1 row updated should return internal error",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -204,7 +204,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
Update(gomock.Any(), repo.IDCondition("org-1"), "instance-1", repo.SetName("test org update")).
|
|
|
|
|
Times(1).
|
|
|
|
|
Return(int64(2), nil)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
@@ -214,7 +214,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: "when org update returns 1 row updated should return no error and set non-primary verified domain",
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) domain.OrganizationRepository {
|
|
|
|
|
orgRepo: func(ctrl *gomock.Controller) func(client database.QueryExecutor) domain.OrganizationRepository {
|
|
|
|
|
repo := domainmock.NewOrgRepo(ctrl)
|
|
|
|
|
repo.EXPECT().
|
|
|
|
|
Get(gomock.Any(), gomock.Any()).
|
|
|
|
|
@@ -235,7 +235,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) {
|
|
|
|
|
Update(gomock.Any(), repo.IDCondition("org-1"), "instance-1", repo.SetName("test org update")).
|
|
|
|
|
Times(1).
|
|
|
|
|
Return(int64(1), nil)
|
|
|
|
|
return repo
|
|
|
|
|
return func(_ database.QueryExecutor) domain.OrganizationRepository { return repo }
|
|
|
|
|
},
|
|
|
|
|
inputID: "org-1",
|
|
|
|
|
inputName: "test org update",
|
|
|
|
|
|