-
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.
Update SlackClient interface and implementation
- Loading branch information
1 parent
7e3db87
commit 55faddd
Showing
7 changed files
with
156 additions
and
12 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package domain | ||
|
||
type SlackClient interface { | ||
SetUserCustomStatus(emoji string) error | ||
SetUserCustomStatus(emoji string, text string) 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
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,40 @@ | ||
package mockSlack | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type client struct { | ||
emojis []string | ||
emoji string | ||
text string | ||
} | ||
|
||
func NewClient() *client { | ||
return &client{} | ||
} | ||
|
||
func (c *client) SetEmojis(emojis []string) { | ||
emojis = append(emojis, "namakemono", "question") | ||
c.emojis = emojis | ||
} | ||
|
||
func (c *client) SetUserCustomStatus(emoji string, text string) error { | ||
for _, e := range c.emojis { | ||
if e == emoji { | ||
if !(strings.HasPrefix(emoji, ":") && strings.HasSuffix(emoji, ":")) { | ||
emoji = ":" + emoji + ":" | ||
} | ||
|
||
c.emoji = emoji | ||
c.text = text | ||
return nil | ||
} | ||
} | ||
return fmt.Errorf("no such emoji: %v", emoji) | ||
} | ||
|
||
func (c *client) GetStatus() (string, string) { | ||
return c.emoji, c.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
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,97 @@ | ||
package usecase | ||
|
||
import ( | ||
"testing" | ||
|
||
mockSlack "github.com/walnuts1018/wakatime-to-slack-profile/mock/slack" | ||
) | ||
|
||
func TestUsecase_SetUserCustomStatus(t *testing.T) { | ||
c := mockSlack.NewClient() | ||
c.SetEmojis([]string{ | ||
"gopher", | ||
"python", | ||
"TypeScript", | ||
}) | ||
|
||
u := NewUsecase(nil, nil, c, map[string]string{ | ||
"Go": "gopher", | ||
}) | ||
|
||
type args struct { | ||
language string | ||
} | ||
tests := []struct { | ||
name string | ||
u *Usecase | ||
args args | ||
wantEmoji string | ||
wantText string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "normal", | ||
u: u, | ||
args: args{ | ||
language: "TypeScript", | ||
}, | ||
wantEmoji: ":TypeScript:", | ||
wantText: "TypeScript", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "override", | ||
u: u, | ||
args: args{ | ||
language: "Go", | ||
}, | ||
wantEmoji: ":gopher:", | ||
wantText: "Go", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "lowercase", | ||
u: u, | ||
args: args{ | ||
language: "Python", | ||
}, | ||
wantEmoji: ":python:", | ||
wantText: "Python", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "not found", | ||
u: u, | ||
args: args{ | ||
language: "Rust", | ||
}, | ||
wantEmoji: ":question:", | ||
wantText: "Rust", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "empty", | ||
u: u, | ||
args: args{ | ||
language: "", | ||
}, | ||
wantEmoji: ":namakemono:", | ||
wantText: "", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := tt.u.SetUserCustomStatus(tt.args.language); (err != nil) != tt.wantErr { | ||
t.Errorf("Usecase.SetUserCustomStatus() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
gotEmoji, gotText := c.GetStatus() | ||
if gotEmoji != tt.wantEmoji { | ||
t.Errorf("Usecase.SetUserCustomStatus() gotEmoji = %v, want %v", gotEmoji, tt.wantEmoji) | ||
} | ||
if gotText != tt.wantText { | ||
t.Errorf("Usecase.SetUserCustomStatus() gotText = %v, want %v", gotText, tt.wantText) | ||
} | ||
}) | ||
} | ||
} |
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