Skip to content

Commit

Permalink
Leverage GetChannelByNameForTeamName (#2)
Browse files Browse the repository at this point in the history
* update to reflect GetChannelByName taking teamId first

* switch to using GetChannelByNameForTeamName
  • Loading branch information
lieut-data authored and jwilander committed Jul 20, 2018
1 parent 19a26d0 commit 1c11b41
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
58 changes: 29 additions & 29 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req
http.Error(w, "You must provide a channel.", http.StatusBadRequest)
} else if user, err := p.API.GetUserByUsername(p.UserName); err != nil {
http.Error(w, err.Message, err.StatusCode)
} else if team, err := p.API.GetTeamByName(r.URL.Query().Get("team")); err != nil {
http.Error(w, err.Message, err.StatusCode)
} else if channel, err := p.API.GetChannelByName(r.URL.Query().Get("channel"), team.Id); err != nil {
} else if channel, err := p.API.GetChannelByNameForTeamName(r.URL.Query().Get("team"), r.URL.Query().Get("channel")); err != nil {
http.Error(w, err.Message, err.StatusCode)
} else if _, err := p.API.CreatePost(&model.Post{
ChannelId: channel.Id,
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ backend:
executable: plugin.exe
name: JIRA
description: Receives webhook events from JIRA and makes Mattermost posts for them.
version: '1.0.0'
version: '1.0.1'
settings_schema:
settings:
- key: Enabled
Expand Down
10 changes: 3 additions & 7 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,14 @@ func TestPlugin(t *testing.T) {
}, (*model.AppError)(nil))
api.On("GetUserByUsername", "nottheuser").Return((*model.User)(nil), model.NewAppError("foo", "bar", nil, "", http.StatusBadRequest))

api.On("GetTeamByName", "theteam").Return(&model.Team{
Id: "theteamid",
}, (*model.AppError)(nil))
api.On("GetTeamByName", "nottheteam").Return((*model.Team)(nil), model.NewAppError("foo", "bar", nil, "", http.StatusBadRequest))

api.On("GetChannelByName", "thechannel", "theteamid").Run(func(args mock.Arguments) {
api.On("GetChannelByNameForTeamName", "nottheteam", "thechannel").Return((*model.Channel)(nil), model.NewAppError("foo", "bar", nil, "", http.StatusBadRequest))
api.On("GetChannelByNameForTeamName", "theteam", "notthechannel").Return((*model.Channel)(nil), model.NewAppError("foo", "bar", nil, "", http.StatusBadRequest))
api.On("GetChannelByNameForTeamName", "theteam", "thechannel").Run(func(args mock.Arguments) {
api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(&model.Post{}, tc.CreatePostError)
}).Return(&model.Channel{
Id: "thechannelid",
TeamId: "theteamid",
}, (*model.AppError)(nil))
api.On("GetChannelByName", "notthechannel", "theteamid").Return((*model.Channel)(nil), model.NewAppError("foo", "bar", nil, "", http.StatusBadRequest))

p := Plugin{}
p.Enabled = tc.Configuration.Enabled
Expand Down

0 comments on commit 1c11b41

Please sign in to comment.