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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
56403b97
Commit
56403b97
authored
Oct 21, 2019
by
allison.browne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the new zoom link service interface
parent
5753de3a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
110 deletions
+96
-110
app/helpers/issuables_helper.rb
app/helpers/issuables_helper.rb
+1
-1
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+0
-1
app/models/zoom_meeting.rb
app/models/zoom_meeting.rb
+6
-7
app/services/issues/zoom_link_service.rb
app/services/issues/zoom_link_service.rb
+3
-4
spec/helpers/issuables_helper_spec.rb
spec/helpers/issuables_helper_spec.rb
+32
-22
spec/services/issues/zoom_link_service_spec.rb
spec/services/issues/zoom_link_service_spec.rb
+54
-75
No files found.
app/helpers/issuables_helper.rb
View file @
56403b97
...
@@ -281,7 +281,7 @@ module IssuablesHelper
...
@@ -281,7 +281,7 @@ module IssuablesHelper
}
}
data
[
:hasClosingMergeRequest
]
=
issuable
.
merge_requests_count
(
current_user
)
!=
0
if
issuable
.
is_a?
(
Issue
)
data
[
:hasClosingMergeRequest
]
=
issuable
.
merge_requests_count
(
current_user
)
!=
0
if
issuable
.
is_a?
(
Issue
)
data
[
:zoomMeetingUrl
]
=
ZoomMeeting
.
canonical_meeting_url
(
issuable
)
data
[
:zoomMeetingUrl
]
=
ZoomMeeting
.
canonical_meeting_url
(
issuable
)
if
issuable
.
is_a?
(
Issue
)
if
parent
.
is_a?
(
Group
)
if
parent
.
is_a?
(
Group
)
data
[
:groupPath
]
=
parent
.
path
data
[
:groupPath
]
=
parent
.
path
...
...
app/models/concerns/issuable.rb
View file @
56403b97
...
@@ -66,7 +66,6 @@ module Issuable
...
@@ -66,7 +66,6 @@ module Issuable
has_many
:label_links
,
as: :target
,
dependent: :destroy
,
inverse_of: :target
# rubocop:disable Cop/ActiveRecordDependent
has_many
:label_links
,
as: :target
,
dependent: :destroy
,
inverse_of: :target
# rubocop:disable Cop/ActiveRecordDependent
has_many
:labels
,
through: :label_links
has_many
:labels
,
through: :label_links
has_many
:todos
,
as: :target
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:todos
,
as: :target
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:zoom_meetings
has_one
:metrics
has_one
:metrics
...
...
app/models/zoom_meeting.rb
View file @
56403b97
...
@@ -14,14 +14,13 @@ class ZoomMeeting < ApplicationRecord
...
@@ -14,14 +14,13 @@ class ZoomMeeting < ApplicationRecord
scope
:added_to_issue
,
->
{
where
(
issue_status: :added
)
}
scope
:added_to_issue
,
->
{
where
(
issue_status: :added
)
}
scope
:removed_from_issue
,
->
{
where
(
issue_status: :removed
)
}
scope
:removed_from_issue
,
->
{
where
(
issue_status: :removed
)
}
scope
:canonical_meetings
,
->
(
issue
)
{
where
(
issue:
issue
)
&
.
added_to_issue
}
class
<<
self
def
self
.
canonical_meeting
(
issue
)
def
canonical_meeting_url
(
issue
)
canonical_meetings
(
issue
)
&
.
first
canonical_meeting
(
issue
)
&
.
url
end
end
def
canonical_meeting
(
issue
)
def
self
.
canonical_meeting_url
(
issue
)
issue
&
.
zoom_meetings
&
.
added_to_issue
&
.
first
canonical_meeting
(
issue
)
&
.
url
end
end
end
end
end
app/services/issues/zoom_link_service.rb
View file @
56403b97
...
@@ -30,7 +30,7 @@ module Issues
...
@@ -30,7 +30,7 @@ module Issues
end
end
def
can_remove_link?
def
can_remove_link?
can?
&&
@added_meeting
can?
&&
!!
@added_meeting
end
end
def
parse_link
(
link
)
def
parse_link
(
link
)
...
@@ -42,11 +42,11 @@ module Issues
...
@@ -42,11 +42,11 @@ module Issues
attr_reader
:issue
attr_reader
:issue
def
fetch_added_meeting
def
fetch_added_meeting
ZoomMeeting
.
where
(
issue:
@issue
).
added_to_issue
.
first
ZoomMeeting
.
canonical_meeting
(
@issue
)
end
end
def
create_zoom_meeting
(
link
)
def
create_zoom_meeting
(
link
)
meeting
=
ZoomMeeting
.
create
(
ZoomMeeting
.
create
(
issue:
@issue
,
issue:
@issue
,
project:
@issue
.
project
,
project:
@issue
.
project
,
issue_status: :added
,
issue_status: :added
,
...
@@ -72,7 +72,6 @@ module Issues
...
@@ -72,7 +72,6 @@ module Issues
ServiceResponse
.
error
(
message:
message
)
ServiceResponse
.
error
(
message:
message
)
end
end
def
can?
def
can?
current_user
.
can?
(
:update_issue
,
project
)
current_user
.
can?
(
:update_issue
,
project
)
end
end
...
...
spec/helpers/issuables_helper_spec.rb
View file @
56403b97
...
@@ -203,44 +203,54 @@ describe IssuablesHelper do
...
@@ -203,44 +203,54 @@ describe IssuablesHelper do
end
end
describe
'#zoomMeetingUrl in issue'
do
describe
'#zoomMeetingUrl in issue'
do
let
(
:issue
)
{
create
(
:issue
,
author:
user
,
description:
description
)
}
let
(
:issue
)
{
create
(
:issue
,
author:
user
)
}
before
do
before
do
assign
(
:project
,
issue
.
project
)
assign
(
:project
,
issue
.
project
)
end
end
context
'no zoom links in the issue description'
do
shared_examples
'sets zoomMeetingUrl to nil'
do
let
(
:description
)
{
'issue text'
}
specify
do
expect
(
helper
.
issuable_initial_data
(
issue
)[
:zoomMeetingUrl
])
it
'does not set zoomMeetingUrl'
do
.
to
be_nil
expect
(
helper
.
issuable_initial_data
(
issue
))
.
not_to
include
(
:zoomMeetingUrl
)
end
end
end
end
context
'no zoom links in the issue description if it has link but not a zoom link'
do
context
'with no "added" zoom mettings'
do
let
(
:description
)
{
'issue text https://stackoverflow.com/questions/22'
}
it_behaves_like
'sets zoomMeetingUrl to nil'
context
'with multiple removed meetings'
do
before
do
create
(
:zoom_meeting
,
issue:
issue
,
issue_status: :removed
)
create
(
:zoom_meeting
,
issue:
issue
,
issue_status: :removed
)
end
it
'does not set zoomMeetingUrl'
do
it_behaves_like
'sets zoomMeetingUrl to nil'
expect
(
helper
.
issuable_initial_data
(
issue
))
.
not_to
include
(
:zoomMeetingUrl
)
end
end
end
end
context
'with two zoom links in description'
do
context
'with "added" zoom meeting'
do
let
(
:description
)
do
before
{
create
(
:zoom_meeting
,
issue:
issue
)
}
<<~
TEXT
issue text and
shared_examples
'sets zoomMeetingUrl to canonical meeting url'
do
zoom call on https://zoom.us/j/123456789 this url
specify
do
and new zoom url https://zoom.us/s/lastone and some more text
expect
(
helper
.
issuable_initial_data
(
issue
))
TEXT
.
to
include
(
zoomMeetingUrl:
'https://zoom.us/j/123456789'
)
end
end
end
it
'sets zoomMeetingUrl value to the last url'
do
it_behaves_like
'sets zoomMeetingUrl to canonical meeting url'
expect
(
helper
.
issuable_initial_data
(
issue
))
.
to
include
(
zoomMeetingUrl:
'https://zoom.us/s/lastone'
)
context
'with muliple "removed" zoom meetings'
do
before
do
create
(
:zoom_meeting
,
issue:
issue
,
issue_status: :removed
)
create
(
:zoom_meeting
,
issue:
issue
,
issue_status: :removed
)
end
it_behaves_like
'sets zoomMeetingUrl to canonical meeting url'
end
end
end
end
end
end
end
end
...
...
spec/services/issues/zoom_link_service_spec.rb
View file @
56403b97
...
@@ -14,27 +14,16 @@ describe Issues::ZoomLinkService do
...
@@ -14,27 +14,16 @@ describe Issues::ZoomLinkService do
project
.
add_reporter
(
user
)
project
.
add_reporter
(
user
)
end
end
shared_context
'
with Zoom link
'
do
shared_context
'
"added" Zoom meeting
'
do
before
do
before
do
issue
.
update!
(
description:
"Description
\n\n
#{
zoom_link
}
"
)
create
(
:zoom_meeting
,
issue:
issue
)
end
end
end
end
shared_context
'
with Zoom link not at the end
'
do
shared_context
'
"removed" zoom meetings
'
do
before
do
before
do
issue
.
update!
(
description:
"Description with
#{
zoom_link
}
some where"
)
create
(
:zoom_meeting
,
issue:
issue
,
issue_status: :removed
)
end
create
(
:zoom_meeting
,
issue:
issue
,
issue_status: :removed
)
end
shared_context
'without Zoom link'
do
before
do
issue
.
update!
(
description:
"Description
\n\n
http://example.com"
)
end
end
shared_context
'without issue description'
do
before
do
issue
.
update!
(
description:
nil
)
end
end
end
end
...
@@ -45,16 +34,16 @@ describe Issues::ZoomLinkService do
...
@@ -45,16 +34,16 @@ describe Issues::ZoomLinkService do
end
end
describe
'#add_link'
do
describe
'#add_link'
do
shared_examples
'can add
link
'
do
shared_examples
'can add
meeting
'
do
it
'appends the link to issue description'
do
it
'appends the link to issue description'
do
expect
(
result
).
to
be_success
expect
(
result
).
to
be_success
expect
(
result
.
payload
[
:
description
]
)
expect
(
result
.
payload
[
:
zoom_meetings
].
map
(
&
:url
)
)
.
to
eq
(
"
#{
issue
.
description
}
\n\n
#{
zoom_link
}
"
)
.
to
include
(
zoom_link
)
end
end
end
end
shared_examples
'cannot add
link
'
do
shared_examples
'cannot add
meeting
'
do
it
'cannot add the
link
'
do
it
'cannot add the
meeting
'
do
expect
(
result
).
to
be_error
expect
(
result
).
to
be_error
expect
(
result
.
message
).
to
eq
(
'Failed to add a Zoom meeting'
)
expect
(
result
.
message
).
to
eq
(
'Failed to add a Zoom meeting'
)
end
end
...
@@ -62,43 +51,31 @@ describe Issues::ZoomLinkService do
...
@@ -62,43 +51,31 @@ describe Issues::ZoomLinkService do
subject
(
:result
)
{
service
.
add_link
(
zoom_link
)
}
subject
(
:result
)
{
service
.
add_link
(
zoom_link
)
}
context
'without Zoom link in the issue description'
do
context
'without existing Zoom meeting'
do
include_context
'without Zoom link'
include_examples
'can add meeting'
include_examples
'can add link'
context
'with invalid Zoom
link
'
do
context
'with invalid Zoom
meeting
'
do
let
(
:zoom_link
)
{
'https://not-zoom.link'
}
let
(
:zoom_link
)
{
'https://not-zoom.link'
}
include_examples
'cannot add
link
'
include_examples
'cannot add
meeting
'
end
end
context
'with insufficient permissions'
do
context
'with insufficient permissions'
do
include_context
'insufficient permissions'
include_context
'insufficient permissions'
include_examples
'cannot add
link
'
include_examples
'cannot add
meeting
'
end
end
end
end
context
'with Zoom link in the issue description'
do
context
'with "added" Zoom meeting'
do
include_context
'with Zoom link'
include_context
'"added" Zoom meeting'
include_examples
'cannot add link'
include_examples
'cannot add meeting'
context
'but not at the end'
do
include_context
'with Zoom link not at the end'
include_examples
'can add link'
end
end
context
'without issue description'
do
include_context
'without issue description'
include_examples
'can add link'
end
end
end
end
describe
'#can_add_link?'
do
describe
'#can_add_link?'
do
subject
{
service
.
can_add_link?
}
subject
{
service
.
can_add_link?
}
context
'without Zoom link in the issue description'
do
context
'without Zoom link'
do
include_context
'without Zoom link'
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
true
)
}
...
@@ -109,74 +86,76 @@ describe Issues::ZoomLinkService do
...
@@ -109,74 +86,76 @@ describe Issues::ZoomLinkService do
end
end
end
end
context
'with Zoom
link
in the issue description'
do
context
'with Zoom
meeting
in the issue description'
do
include_context
'with Zoom link
'
include_context
'"added" Zoom meeting
'
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
end
describe
'#remove_link'
do
describe
'#remove_link'
do
shared_examples
'cannot remove
link
'
do
shared_examples
'cannot remove
meeting
'
do
it
'cannot remove the
link
'
do
it
'cannot remove the
meeting
'
do
expect
(
result
).
to
be_error
expect
(
result
).
to
be_error
expect
(
result
.
message
).
to
eq
(
'Failed to remove a Zoom meeting'
)
expect
(
result
.
message
).
to
eq
(
'Failed to remove a Zoom meeting'
)
end
end
end
end
shared_examples
'can remove meeting'
do
it
'can remove the meeting'
do
expect
(
result
).
to
be_success
expect
(
result
.
payload
[
:zoom_meetings
].
filter
{
|
z
|
z
.
issue_status
==
1
})
.
to
be_empty
end
end
subject
(
:result
)
{
service
.
remove_link
}
subject
(
:result
)
{
service
.
remove_link
}
context
'with Zoom
link in the issue description
'
do
context
'with Zoom
meeting
'
do
include_context
'
with Zoom link
'
include_context
'
"added" Zoom meeting
'
it
'removes the link from the issue description'
do
context
'removes the link'
do
expect
(
result
).
to
be_success
include_examples
'can remove meeting'
expect
(
result
.
payload
[
:description
])
.
to
eq
(
issue
.
description
.
delete_suffix
(
"
\n\n
#{
zoom_link
}
"
))
end
end
context
'with insufficient permissions'
do
context
'with insufficient permissions'
do
include_context
'insufficient permissions'
include_context
'insufficient permissions'
include_examples
'cannot remove
link
'
include_examples
'cannot remove
meeting
'
end
end
context
'but not at the end'
do
include_context
'with Zoom link not at the end'
include_examples
'cannot remove link'
end
end
context
'without Zoom link in the issue description'
do
include_context
'without Zoom link'
include_examples
'cannot remove link'
end
end
context
'without
issue description
'
do
context
'without
"added" Zoom meeting
'
do
include_context
'
without issue description
'
include_context
'
"removed" zoom meetings
'
include_examples
'cannot remove
link
'
include_examples
'cannot remove
meeting
'
end
end
end
end
describe
'#can_remove_link?'
do
describe
'#can_remove_link?'
do
subject
{
service
.
can_remove_link?
}
subject
{
service
.
can_remove_link?
}
context
'with Zoom link in the issue description'
do
context
'without Zoom meeting'
do
include_context
'with Zoom link'
it
{
is_expected
.
to
eq
(
false
)
}
end
context
'with only "removed" zoom meetings'
do
include_context
'"removed" zoom meetings'
it
{
is_expected
.
to
eq
(
false
)
}
end
context
'with "added" Zoom meeting'
do
include_context
'"added" Zoom meeting'
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
true
)
}
context
'with "removed" zoom meetings'
do
include_context
'"removed" zoom meetings'
it
{
is_expected
.
to
eq
(
true
)
}
end
context
'with insufficient permissions'
do
context
'with insufficient permissions'
do
include_context
'insufficient permissions'
include_context
'insufficient permissions'
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
end
context
'without Zoom link in the issue description'
do
include_context
'without Zoom link'
it
{
is_expected
.
to
eq
(
false
)
}
end
end
end
describe
'#parse_link'
do
describe
'#parse_link'
do
...
...
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