Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
f9f1a508
Commit
f9f1a508
authored
Dec 16, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SlackSlashCommands tests
parent
ebc3f62b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
127 additions
and
118 deletions
+127
-118
app/models/project_services/chat_slash_commands_service.rb
app/models/project_services/chat_slash_commands_service.rb
+1
-1
app/models/project_services/mattermost_slash_commands_service.rb
...els/project_services/mattermost_slash_commands_service.rb
+1
-1
lib/gitlab/chat_commands/presenter.rb
lib/gitlab/chat_commands/presenter.rb
+1
-1
spec/lib/gitlab/chat_commands/command_spec.rb
spec/lib/gitlab/chat_commands/command_spec.rb
+15
-5
spec/models/project_services/chat_service_spec.rb
spec/models/project_services/chat_service_spec.rb
+0
-15
spec/models/project_services/chat_slash_commands_service_spec.rb
...dels/project_services/chat_slash_commands_service_spec.rb
+103
-0
spec/models/project_services/mattermost_slash_commands_service_spec.rb
...roject_services/mattermost_slash_commands_service_spec.rb
+1
-95
spec/models/project_services/slack_slash_commands_service.rb
spec/models/project_services/slack_slash_commands_service.rb
+5
-0
No files found.
app/models/project_services/chat_slash_commands_service.rb
View file @
f9f1a508
...
@@ -5,7 +5,7 @@ class ChatSlashCommandsService < Service
...
@@ -5,7 +5,7 @@ class ChatSlashCommandsService < Service
prop_accessor
:token
prop_accessor
:token
has_many
:chat_names
,
foreign_key: :service_id
has_many
:chat_names
,
foreign_key: :service_id
,
dependent: :destroy
def
valid_token?
(
token
)
def
valid_token?
(
token
)
self
.
respond_to?
(
:token
)
&&
self
.
respond_to?
(
:token
)
&&
...
...
app/models/project_services/mattermost_slash_commands_service.rb
View file @
f9f1a508
class
MattermostSlashCommandsService
<
ChatService
class
MattermostSlashCommandsService
<
ChatS
lashCommandsS
ervice
include
TriggersHelper
include
TriggersHelper
prop_accessor
:token
prop_accessor
:token
...
...
lib/gitlab/chat_commands/presenter.rb
View file @
f9f1a508
module
Gitlab
module
Gitlab
class
ChatCommands
module
ChatCommands
class
Presenter
class
Presenter
include
Gitlab
::
Routing
.
url_helpers
include
Gitlab
::
Routing
.
url_helpers
...
...
spec/lib/gitlab/chat_commands/command_spec.rb
View file @
f9f1a508
...
@@ -3,9 +3,13 @@ require 'spec_helper'
...
@@ -3,9 +3,13 @@ require 'spec_helper'
describe
Gitlab
::
ChatCommands
::
Command
,
service:
true
do
describe
Gitlab
::
ChatCommands
::
Command
,
service:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:format
)
{
nil
}
describe
'#execute'
do
describe
'#execute'
do
subject
{
described_class
.
new
(
project
,
user
,
params
).
execute
}
subject
do
described_class
.
new
(
project
,
user
,
params
.
merge
(
presenter_format:
format
)).
execute
end
context
'when no command is available'
do
context
'when no command is available'
do
let
(
:params
)
{
{
text:
'issue show 1'
}
}
let
(
:params
)
{
{
text:
'issue show 1'
}
}
...
@@ -47,8 +51,14 @@ describe Gitlab::ChatCommands::Command, service: true do
...
@@ -47,8 +51,14 @@ describe Gitlab::ChatCommands::Command, service: true do
expect
(
subject
[
:text
]).
to
match
(
"my new issue"
)
expect
(
subject
[
:text
]).
to
match
(
"my new issue"
)
end
end
it
'shows a link to the new issue'
do
%w(slack mattermost)
.
each
do
|
format
|
expect
(
subject
[
:text
]).
to
match
(
/\/issues\/\d+/
)
context
"for
#{
format
}
"
do
let
(
:format
)
{
format
}
it
'shows a link to the new issue'
do
expect
(
subject
[
:text
]).
to
match
(
/\/issues\/\d+/
)
end
end
end
end
end
end
...
@@ -64,7 +74,7 @@ describe Gitlab::ChatCommands::Command, service: true do
...
@@ -64,7 +74,7 @@ describe Gitlab::ChatCommands::Command, service: true do
context
'and user can not create deployment'
do
context
'and user can not create deployment'
do
it
'returns action'
do
it
'returns action'
do
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:response_type
]).
to
be
(
:ephemeral
)
expect
(
subject
[
:text
]).
to
start_with
(
'Whoops! Th
is
action is not allowed'
)
expect
(
subject
[
:text
]).
to
start_with
(
'Whoops! Th
at
action is not allowed'
)
end
end
end
end
...
@@ -74,7 +84,7 @@ describe Gitlab::ChatCommands::Command, service: true do
...
@@ -74,7 +84,7 @@ describe Gitlab::ChatCommands::Command, service: true do
end
end
it
'returns action'
do
it
'returns action'
do
expect
(
subject
[
:text
]).
to
include
(
'Deployment
started from staging to production
'
)
expect
(
subject
[
:text
]).
to
include
(
'Deployment
from staging to production started.
'
)
expect
(
subject
[
:response_type
]).
to
be
(
:in_channel
)
expect
(
subject
[
:response_type
]).
to
be
(
:in_channel
)
end
end
...
...
spec/models/project_services/chat_service_spec.rb
deleted
100644 → 0
View file @
ebc3f62b
require
'spec_helper'
describe
ChatService
,
models:
true
do
describe
"Associations"
do
it
{
is_expected
.
to
have_many
:chat_names
}
end
describe
'#valid_token?'
do
subject
{
described_class
.
new
}
it
'is false as it has no token'
do
expect
(
subject
.
valid_token?
(
'wer'
)).
to
be_falsey
end
end
end
spec/models/project_services/chat_slash_commands_service_spec.rb
0 → 100644
View file @
f9f1a508
require
'spec_helper'
describe
ChatSlashCommandsService
,
models:
true
do
describe
"Associations"
do
it
{
is_expected
.
to
respond_to
:token
}
it
{
is_expected
.
to
have_many
:chat_names
}
end
describe
'#valid_token?'
do
subject
{
described_class
.
new
}
context
'when the token is empty'
do
it
'is false'
do
expect
(
subject
.
valid_token?
(
'wer'
)).
to
be_falsey
end
end
context
'when there is a token'
do
before
do
subject
.
token
=
'123'
end
it
'accepts equal tokens'
do
expect
(
subject
.
valid_token?
(
'123'
)).
to
be_truthy
end
end
end
describe
'#trigger'
do
subject
{
described_class
.
new
}
before
do
allow
(
subject
).
to
receive
(
:presenter_format
).
and_return
(
'unknown'
)
end
context
'no token is passed'
do
let
(
:params
)
{
Hash
.
new
}
it
'returns nil'
do
expect
(
subject
.
trigger
(
params
)).
to
be_nil
end
end
context
'with a token passed'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:params
)
{
{
token:
'token'
}
}
before
do
allow
(
subject
).
to
receive
(
:token
).
and_return
(
'token'
)
end
context
'no user can be found'
do
context
'when no url can be generated'
do
it
'responds with the authorize url'
do
response
=
subject
.
trigger
(
params
)
expect
(
response
[
:response_type
]).
to
eq
:ephemeral
expect
(
response
[
:text
]).
to
start_with
":sweat_smile: Couldn't identify you"
end
end
context
'when an auth url can be generated'
do
let
(
:params
)
do
{
team_domain:
'http://domain.tld'
,
team_id:
'T3423423'
,
user_id:
'U234234'
,
user_name:
'mepmep'
,
token:
'token'
}
end
let
(
:service
)
do
project
.
create_mattermost_slash_commands_service
(
properties:
{
token:
'token'
}
)
end
it
'generates the url'
do
response
=
service
.
trigger
(
params
)
expect
(
response
[
:text
]).
to
start_with
(
':wave: Hi there!'
)
end
end
end
context
'when the user is authenticated'
do
let!
(
:chat_name
)
{
create
(
:chat_name
,
service:
subject
)
}
let
(
:params
)
{
{
token:
'token'
,
team_id:
chat_name
.
team_id
,
user_id:
chat_name
.
chat_id
}
}
subject
do
described_class
.
create
(
project:
project
,
properties:
{
token:
'token'
})
end
it
'triggers the command'
do
expect_any_instance_of
(
Gitlab
::
ChatCommands
::
Command
).
to
receive
(
:execute
)
subject
.
trigger
(
params
)
end
end
end
end
end
spec/models/project_services/mattermost_slash_commands_service_spec.rb
View file @
f9f1a508
require
'spec_helper'
require
'spec_helper'
describe
MattermostSlashCommandsService
,
models:
true
do
describe
MattermostSlashCommandsService
,
models:
true
do
describe
"Associations"
do
it
{
is_expected
.
to
respond_to
:presenter_format
}
it
{
is_expected
.
to
respond_to
:token
}
end
describe
'#valid_token?'
do
subject
{
described_class
.
new
}
context
'when the token is empty'
do
it
'is false'
do
expect
(
subject
.
valid_token?
(
'wer'
)).
to
be_falsey
end
end
context
'when there is a token'
do
before
do
subject
.
token
=
'123'
end
it
'accepts equal tokens'
do
expect
(
subject
.
valid_token?
(
'123'
)).
to
be_truthy
end
end
end
describe
'#trigger'
do
subject
{
described_class
.
new
}
context
'no token is passed'
do
let
(
:params
)
{
Hash
.
new
}
it
'returns nil'
do
expect
(
subject
.
trigger
(
params
)).
to
be_nil
end
end
context
'with a token passed'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:params
)
{
{
token:
'token'
}
}
before
do
allow
(
subject
).
to
receive
(
:token
).
and_return
(
'token'
)
end
context
'no user can be found'
do
context
'when no url can be generated'
do
it
'responds with the authorize url'
do
response
=
subject
.
trigger
(
params
)
expect
(
response
[
:response_type
]).
to
eq
:ephemeral
expect
(
response
[
:text
]).
to
start_with
":sweat_smile: Couldn't identify you"
end
end
context
'when an auth url can be generated'
do
let
(
:params
)
do
{
team_domain:
'http://domain.tld'
,
team_id:
'T3423423'
,
user_id:
'U234234'
,
user_name:
'mepmep'
,
token:
'token'
}
end
let
(
:service
)
do
project
.
create_mattermost_slash_commands_service
(
properties:
{
token:
'token'
}
)
end
it
'generates the url'
do
response
=
service
.
trigger
(
params
)
expect
(
response
[
:text
]).
to
start_with
(
':wave: Hi there!'
)
end
end
end
context
'when the user is authenticated'
do
let!
(
:chat_name
)
{
create
(
:chat_name
,
service:
service
)
}
let
(
:service
)
do
project
.
create_mattermost_slash_commands_service
(
properties:
{
token:
'token'
}
)
end
let
(
:params
)
{
{
token:
'token'
,
team_id:
chat_name
.
team_id
,
user_id:
chat_name
.
chat_id
}
}
it
'triggers the command'
do
expect_any_instance_of
(
Gitlab
::
ChatCommands
::
Command
).
to
receive
(
:execute
)
service
.
trigger
(
params
)
end
end
end
end
end
end
spec/models/project_services/slack_slash_commands_service.rb
0 → 100644
View file @
f9f1a508
require
'spec_helper'
describe
SlackSlashCommandsService
,
models:
true
do
it
{
is_expected
.
to
respond_to
:presenter_format
}
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment