-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from LerianStudio/feature/MZ-606
Feature/MZ-606
- Loading branch information
Showing
9 changed files
with
206 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
components/mdz/internal/domain/repository/organization_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package organization | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" | ||
"github.com/LerianStudio/midaz/components/mdz/internal/rest" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/factory" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/output" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/tui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type factoryOrganizationDelete struct { | ||
factory *factory.Factory | ||
repoOrganization repository.Organization | ||
tuiInput func(message string) (string, error) | ||
organizationID string | ||
} | ||
|
||
func (f *factoryOrganizationDelete) runE(cmd *cobra.Command, _ []string) error { | ||
if !cmd.Flags().Changed("username") && len(f.organizationID) < 1 { | ||
id, err := tui.Input("Enter your organization-id") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.organizationID = id | ||
} | ||
|
||
err := f.repoOrganization.Delete(f.organizationID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output.Printf(f.factory.IOStreams.Out, | ||
fmt.Sprintf("The Organization %s has been successfully deleted.", f.organizationID)) | ||
|
||
return nil | ||
} | ||
|
||
func (f *factoryOrganizationDelete) setFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVarP(&f.organizationID, "organization-id", "i", "", | ||
"Specify the organization ID to delete") | ||
cmd.Flags().BoolP("help", "h", false, "Displays more information about the Mdz CLI") | ||
} | ||
|
||
func newInjectFacDelete(f *factory.Factory) *factoryOrganizationDelete { | ||
return &factoryOrganizationDelete{ | ||
factory: f, | ||
repoOrganization: rest.NewOrganization(f), | ||
tuiInput: tui.Input, | ||
} | ||
} | ||
|
||
func newCmdOrganizationDelete(f *factoryOrganizationDelete) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "Remove a specific organization in Midaz", | ||
Long: "The /`organization delete/` command allows you to remove a specific organization in Midaz " + | ||
"by specifying the organization ID.", | ||
Example: utils.Format( | ||
"$ mdz organization delete --organization-id 12312", | ||
"$ mdz organization delete -i 12314", | ||
"$ mdz organization delete -h", | ||
), | ||
RunE: f.runE, | ||
} | ||
|
||
f.setFlags(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package organization | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/factory" | ||
"github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestNewCmdOrganizationDelete(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
runTest func(t *testing.T) | ||
}{ | ||
{ | ||
name: "happy road", | ||
runTest: func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockRepo := repository.NewMockOrganization(ctrl) | ||
|
||
orgFactory := factoryOrganizationDelete{ | ||
factory: &factory.Factory{IOStreams: &iostreams.IOStreams{ | ||
Out: &bytes.Buffer{}, | ||
Err: &bytes.Buffer{}, | ||
}}, | ||
repoOrganization: mockRepo, | ||
organizationID: "123", | ||
} | ||
|
||
cmd := newCmdOrganizationDelete(&orgFactory) | ||
cmd.SetArgs([]string{ | ||
"--organization-id", "123", | ||
}) | ||
|
||
mockRepo.EXPECT().Delete(gomock.Any()).Return(nil) | ||
|
||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
|
||
output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() | ||
assert.Contains(t, output, "The Organization 123 has been successfully deleted.") | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, tc.runTest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters