-
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.
Closes #37
- Loading branch information
Showing
8 changed files
with
213 additions
and
1 deletion.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package presence | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
type discord interface { | ||
SetActivity(ctx context.Context, activity *discordgo.Activity) error | ||
} |
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,29 @@ | ||
package presence | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/nijeti/cinema-keeper/internal/discord/commands/responses" | ||
) | ||
|
||
type Service struct { | ||
discord discord | ||
} | ||
|
||
func New( | ||
discord discord, | ||
) *Service { | ||
return &Service{ | ||
discord: discord, | ||
} | ||
} | ||
|
||
func (s *Service) Set(ctx context.Context) error { | ||
err := s.discord.SetActivity(ctx, responses.Activity()) | ||
if err != nil { | ||
return fmt.Errorf("failed to set activity: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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,57 @@ | ||
package presence_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/nijeti/cinema-keeper/internal/discord/commands/responses" | ||
mocks "github.com/nijeti/cinema-keeper/internal/generated/mocks/services/presence" | ||
"github.com/nijeti/cinema-keeper/internal/services/presence" | ||
) | ||
|
||
func TestService_Set(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
type setup func(t *testing.T, err error) *presence.Service | ||
|
||
tests := map[string]struct { | ||
err error | ||
setup setup | ||
}{ | ||
"set_activity_error": { | ||
err: errors.New("set activity error"), | ||
setup: func(t *testing.T, err error) *presence.Service { | ||
d := mocks.NewMockDiscord(t) | ||
|
||
d.EXPECT().SetActivity(ctx, responses.Activity()).Return(err) | ||
|
||
return presence.New(d) | ||
}, | ||
}, | ||
"success": { | ||
err: nil, | ||
setup: func(t *testing.T, _ error) *presence.Service { | ||
d := mocks.NewMockDiscord(t) | ||
|
||
d.EXPECT().SetActivity(ctx, responses.Activity()).Return(nil) | ||
|
||
return presence.New(d) | ||
}, | ||
}, | ||
} | ||
|
||
for name, tt := range tests { | ||
t.Run( | ||
name, func(t *testing.T) { | ||
s := tt.setup(t, tt.err) | ||
err := s.Set(ctx) | ||
assert.ErrorIs(t, err, tt.err) | ||
}, | ||
) | ||
} | ||
} |