Skip to content

Commit

Permalink
Interactively update tasks via multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
carpeliam committed Jan 21, 2025
1 parent c5bb733 commit c0ad96a
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 15 deletions.
4 changes: 2 additions & 2 deletions browse/browse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (browserSpy *BrowserSpy) OpenURL(URL string) (*exec.Cmd, error) {
var _ = Describe("BrowseStory", func() {
It("should open the browser to the URL of the story", func() {
mockGitRepo := &support.MockGitRepository{CurrentBranchName: "gitshorty-sc-123"}
mockShortcutClient := support.MockShortcutClient{
mockShortcutClient := &support.MockShortcutClient{
Stories: map[int]sc.Story{
123: {AppUrl: "https://app.shortcut.com/gitshorty/story/123"},
},
Expand All @@ -38,7 +38,7 @@ var _ = Describe("BrowseStory", func() {

It("should return an error if the story is not found", func() {
mockGitRepo := &support.MockGitRepository{CurrentBranchName: "main"}
mockShortcutClient := support.MockShortcutClient{
mockShortcutClient := &support.MockShortcutClient{
Stories: map[int]sc.Story{},
}
browserSpy := &BrowserSpy{}
Expand Down
23 changes: 22 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,43 @@ go 1.23.1
require (
github.com/Songmu/prompter v0.5.1
github.com/antihax/optional v1.0.0
github.com/charmbracelet/huh v0.6.0
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/urfave/cli/v2 v2.27.5
golang.org/x/oauth2 v0.25.0
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
github.com/charmbracelet/bubbletea v1.2.4 // indirect
github.com/charmbracelet/lipgloss v1.0.0 // indirect
github.com/charmbracelet/x/ansi v0.4.5 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
Expand Down
52 changes: 49 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/Songmu/prompter v0.5.1 h1:IAsttKsOZWSDw7bV1mtGn9TAmLFAjXbp9I/eYmUUogo=
github.com/Songmu/prompter v0.5.1/go.mod h1:CS3jEPD6h9IaLaG6afrl1orTgII9+uDWuw95dr6xHSw=
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.2.4 h1:KN8aCViA0eps9SCOThb2/XPIlea3ANJLUkv3KnQRNCE=
github.com/charmbracelet/bubbletea v1.2.4/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
github.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=
github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM=
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
Expand All @@ -14,14 +40,31 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg=
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ=
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand All @@ -34,7 +77,10 @@ golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
Expand Down
36 changes: 31 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/carpeliam/gitshorty/shortcut"
"github.com/carpeliam/gitshorty/tasks"
"github.com/carpeliam/gitshorty/version"
"github.com/charmbracelet/huh"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -94,15 +95,32 @@ func main() {
{
Name: "tasks",
Usage: "display tasks associated with the current branch's story",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "interactive",
Usage: "check tasks off as you complete them",
Value: true,
},
},
Action: func(ctx *cli.Context) error {
git := git.NewRepository()
shortcutClient := shortcut.NewShortcutClient(ctx.String("api-token"))
tasks, err := tasks.ListTasks(git, shortcutClient)
shortcutTasks, err := tasks.ListTasks(git, shortcutClient)
if err == nil {
if len(tasks) == 0 {
fmt.Println("No tasks found")
if len(shortcutTasks) == 0 {
fmt.Println("No shortcutTasks found")
} else {
fmt.Println(strings.Join(taskList(tasks), "\n"))
if ctx.Bool("interactive") {
var values []int64
if err = taskListDynamic(shortcutTasks).Value(&values).Run(); err != nil {
return err
} else {
storyId := shortcutTasks[0].StoryId
return tasks.UpdateTasks(shortcutClient, int(storyId), tasks.GetTaskChanges(shortcutTasks, values))
}
} else {
fmt.Println(strings.Join(taskListStatic(shortcutTasks), "\n"))
}
}
}
return err
Expand All @@ -116,7 +134,7 @@ func main() {
}
}

func taskList(tasks []sc.Task) []string {
func taskListStatic(tasks []sc.Task) []string {
taskStrings := make([]string, len(tasks))
for i, task := range tasks {
var taskString strings.Builder
Expand All @@ -132,3 +150,11 @@ func taskList(tasks []sc.Task) []string {
}
return taskStrings
}

func taskListDynamic(tasks []sc.Task) *huh.MultiSelect[int64] {
options := make([]huh.Option[int64], len(tasks))
for i, task := range tasks {
options[i] = huh.NewOption(task.Description, task.Id).Selected(task.Complete)
}
return huh.NewMultiSelect[int64]().Options(options...).Title("Press SPACE to toggle, ENTER to submit")
}
12 changes: 12 additions & 0 deletions shortcut/shortcut_client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

type Client interface {
GetStory(storyID int) (sc.Story, error)
UpdateTask(storyID int, tasks map[int64]sc.UpdateTask) error
}

type ShortcutClient struct {
Expand All @@ -30,3 +31,14 @@ func (shortcut ShortcutClient) GetStory(publicID int) (sc.Story, error) {
}
return story, err
}

func (shortcut ShortcutClient) UpdateTask(storyID int, tasks map[int64]sc.UpdateTask) error {
for taskId, taskUpdates := range tasks {
_, resp, err := shortcut.client.DefaultApi.UpdateTask(shortcut.auth, taskUpdates, int64(storyID), taskId)
if err != nil {
slog.Debug("Error received from Shortcut", "http response", resp)
return err
}
}
return nil
}
11 changes: 10 additions & 1 deletion support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ func (repository *MockGitRepository) DeleteRemoteBranch(branchName string) error
}

type MockShortcutClient struct {
Stories map[int]sc.Story
Stories map[int]sc.Story
TaskUpdates map[int]map[int64]sc.UpdateTask
}

func (mockShortcutClient MockShortcutClient) GetStory(publicID int) (sc.Story, error) {
return mockShortcutClient.Stories[publicID], nil
}

func (mockShortcutClient *MockShortcutClient) UpdateTask(storyID int, tasks map[int64]sc.UpdateTask) error {
if mockShortcutClient.TaskUpdates == nil {
mockShortcutClient.TaskUpdates = make(map[int]map[int64]sc.UpdateTask)
}
mockShortcutClient.TaskUpdates[storyID] = tasks
return nil
}
29 changes: 28 additions & 1 deletion tasks/tasks.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package tasks

import (
"fmt"
"slices"

sc "github.com/carpeliam/gitshorty/generated"
"github.com/carpeliam/gitshorty/git"
"github.com/carpeliam/gitshorty/shortcut"
"github.com/carpeliam/gitshorty/usecases"
)

func ListTasks(repo git.Repository, shortcutClient shortcut.Client) ([]sc.Task, error) {
story, err := usecases.GetStoryByBranchName(repo.GetCurrentBranchName(), shortcutClient)
currentBranch := repo.GetCurrentBranchName()
story, err := usecases.GetStoryByBranchName(currentBranch, shortcutClient)
if story == nil {
return nil, fmt.Errorf("tasks not found for branch '%s'", currentBranch)
}
return story.Tasks, err
}

func GetTaskChanges(tasks []sc.Task, ids []int64) map[int64]sc.UpdateTask {
updates := make(map[int64]sc.UpdateTask)
for _, task := range tasks {
shouldBeCompleted := slices.ContainsFunc(ids, func(id int64) bool {
return id == task.Id
})
if task.Complete != shouldBeCompleted {
updates[task.Id] = sc.UpdateTask{
Complete: shouldBeCompleted,
}
}

}
return updates
}

func UpdateTasks(shortcutClient shortcut.Client, storyId int, updates map[int64]sc.UpdateTask) error {
return shortcutClient.UpdateTask(storyId, updates)
}
44 changes: 43 additions & 1 deletion tasks/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("Tasks", func() {
{Id: 3, Description: "Task 3"},
}
mockGitRepo := &support.MockGitRepository{CurrentBranchName: "magic-sc-123"}
mockShortcutClient := support.MockShortcutClient{
mockShortcutClient := &support.MockShortcutClient{
Stories: map[int]sc.Story{
123: {
Tasks: expectedTasks,
Expand All @@ -29,4 +29,46 @@ var _ = Describe("Tasks", func() {
Expect(err).To(BeNil())
Expect(returnedTasks).To(Equal(expectedTasks))
})

It("should return an error if the story is not found", func() {
mockGitRepo := &support.MockGitRepository{CurrentBranchName: "main"}
mockShortcutClient := &support.MockShortcutClient{}

returnedTasks, err := tasks.ListTasks(mockGitRepo, mockShortcutClient)

Expect(err).NotTo(BeNil())
Expect(returnedTasks).To(BeNil())
})

It("detects changes in task completion", func() {
storyTasks := []sc.Task{
{Id: 1, StoryId: 123, Description: "Task 1", Complete: false},
{Id: 2, StoryId: 123, Description: "Task 2", Complete: false},
{Id: 3, StoryId: 123, Description: "Task 3", Complete: true},
{Id: 4, StoryId: 123, Description: "Task 4", Complete: true},
}
ids := []int64{1, 3}

changes := tasks.GetTaskChanges(storyTasks, ids)
Expect(changes).To(HaveKeyWithValue(int64(1), sc.UpdateTask{Complete: true}))
Expect(changes).To(HaveKeyWithValue(int64(4), sc.UpdateTask{Complete: false}))
})

It("submits tasks updates to Shortcut", func() {
mockShortcutClient := &support.MockShortcutClient{
Stories: map[int]sc.Story{
123: {
Tasks: []sc.Task{
{Id: 1, StoryId: 123, Description: "Task 1", Complete: false},
},
},
},
}
err := tasks.UpdateTasks(mockShortcutClient, 123, map[int64]sc.UpdateTask{
1: {Complete: true},
})

Expect(err).To(BeNil())
Expect(mockShortcutClient.TaskUpdates[123]).To(HaveKeyWithValue(int64(1), sc.UpdateTask{Complete: true}))
})
})
2 changes: 1 addition & 1 deletion usecases/get_story_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var _ = Describe("Getting stories", func() {
Describe("GetStoryByBranchName", func() {
It("gets a Shortcut Story based on the given git branch name", func() {
mockShortcutClient := support.MockShortcutClient{
mockShortcutClient := &support.MockShortcutClient{
Stories: map[int]sc.Story{
123: {Id: 123},
},
Expand Down

0 comments on commit c0ad96a

Please sign in to comment.