Skip to content

Commit

Permalink
Refactor error check, change variable and update test sleep time in T…
Browse files Browse the repository at this point in the history
…weets Editor

Refactored the error checking in the longStorySend function in tweetseditor to improve readability and prevent possible 'nil' error returns. The variable name in another part of the code was changed from 'existMessages' to 'longStoryMessages' for better clarity. Additionally, the sleep time in the related unit test was increased to ensure all actions are properly executed before ending.
  • Loading branch information
lueurxax committed Dec 24, 2023
1 parent 7009d4a commit 3056750
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions internal/tweetseditor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ func (e *editor) longStoryProcess(ctx context.Context, tweets []common.Tweet) er
e.longStoryIndex++

if e.longStoryIndex == 20 {
if err := e.longStorySend(ctx); err != nil {
return err
}
err := e.longStorySend(ctx)

e.longStoryIndex = 0

if err != nil {
return err
}
}
}

Expand All @@ -260,7 +262,7 @@ func (e *editor) longStorySend(ctx context.Context) error {
}

request := ""
if len(e.existMessages) == 0 {
if len(e.longStoryMessages) == 0 {
request = fmt.Sprintf(longStoryPrompt, tweetsStr)
} else {
request = fmt.Sprintf(longStoryNextPrompt, tweetsStr)
Expand Down
2 changes: 1 addition & 1 deletion internal/tweetseditor/editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestLongStory(t *testing.T) {
s.Send(ctx, output)
time.Sleep(time.Second)
r.data = moreTestTweets
time.Sleep(time.Minute)
time.Sleep(10 * time.Minute)
cancel()
})
}

0 comments on commit 3056750

Please sign in to comment.