-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add bubbletea list component * Extract components to cli/components and added tests to components * Fix lint problems * Add Makefile and update file structure * Remove unused method and extracted method to correct package * Add correios TUI * Add tests to correios_tui * Add flag old_ui (o) to render old ui * Add spinner to list when the service is running - Now the status bar only shows when the service has answered - Changed title default style on correios_tui * Update tests * Update README.md with new examples
- Loading branch information
1 parent
eefd3a8
commit 129e2a2
Showing
22 changed files
with
674 additions
and
222 deletions.
There are no files selected for viewing
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,4 @@ | ||
lint: | ||
go mod tidy | ||
go fmt ./... | ||
go vet ./... |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestCorreiosCmd_ValidateArgs(t *testing.T) { | ||
t.Run("Should return error when there's no args", func(t *testing.T) { | ||
result := ValidateArgs(&cobra.Command{}, []string{}) | ||
|
||
expected := "you need to provide an order number" | ||
if result == nil && result.Error() != expected { | ||
t.Fatalf("Should return the error '%s', got '%s'", expected, result) | ||
} | ||
}) | ||
|
||
t.Run("Should not return error when there's a arg", func(t *testing.T) { | ||
result := ValidateArgs(&cobra.Command{}, []string{"param"}) | ||
|
||
if result != nil { | ||
t.Fatalf("Shouldn't return errors, got '%s'", result) | ||
} | ||
}) | ||
} | ||
|
||
// func TestCorreiosCmd_CorreiosRun(t *testing.T) { | ||
// t.Run("Should render OLD UI when there's the flag -o", func(t *testing.T) { | ||
// cmd := cobra.Command{} | ||
// cmd.Flags().BoolP("old_ui", "o", true, "") | ||
|
||
// //CorreiosRun(&cmd, []string{"test"}) | ||
|
||
// }) | ||
// } |
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
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,15 @@ | ||
package components | ||
|
||
// Item represents a item in the list | ||
type Item struct { | ||
Text, Time string | ||
} | ||
|
||
// Title retrieves de Text of the item | ||
func (i Item) Title() string { return i.Text } | ||
|
||
// Description retrieves de Time of the item | ||
func (i Item) Description() string { return i.Time } | ||
|
||
// FilterValue from list.Item | ||
func (i Item) FilterValue() string { return i.Text } |
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,22 @@ | ||
package components | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestItem(t *testing.T) { | ||
item := Item{ | ||
Text: "test text", | ||
Time: "02 Jan 06 15:04", | ||
} | ||
|
||
if item.Title() != "test text" { | ||
t.Fatalf("Title should be test text") | ||
} | ||
if item.Description() != "02 Jan 06 15:04" { | ||
t.Fatalf("Description should be 02 Jan 06 15:04") | ||
} | ||
if item.FilterValue() != "test text" { | ||
t.Fatalf("FilterValue should be test text") | ||
} | ||
} |
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,38 @@ | ||
package correios | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cristovaoolegario/orders-tracker-cli/internal/pkg/cli/correios/format" | ||
"github.com/cristovaoolegario/orders-tracker-cli/internal/pkg/http/dto" | ||
"github.com/cristovaoolegario/orders-tracker-cli/internal/pkg/http/services" | ||
) | ||
|
||
// CorreiosCLI provides the cli validation for correios command | ||
type CorreiosCLI struct { | ||
service services.ICorreiosService | ||
} | ||
|
||
// ProvideCorreiosCLI provides a CorreiosCLI | ||
var ProvideCorreiosCLI = func(baseURL string) CorreiosCLI { | ||
return CorreiosCLI{service: services.ProvideCorreiosService(baseURL)} | ||
} | ||
|
||
// RetrieveOrder prints the order data on the terminal | ||
func (cli *CorreiosCLI) RetrieveOrder(orderNumber string) { | ||
response, err := cli.service.FindOrderByNumber(orderNumber) | ||
fmt.Print(formatListToString(response, err)) | ||
} | ||
|
||
func formatListToString(response *dto.CorreiosResponse, err error) string { | ||
var resultString = "\n" | ||
if err == nil { | ||
for _, event := range response.Objects[0].Events { | ||
resultString += fmt.Sprintf("%s\n%s\n\n", format.FormatEventByEventCodeAndEventType(event), format.FormatDateTimeCreated(event.DateTimeCreated)) | ||
} | ||
} else { | ||
resultString += fmt.Sprintf("❌\t%s\n", err.Error()) | ||
} | ||
|
||
return resultString | ||
} |
Oops, something went wrong.