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
ba9feac9
Commit
ba9feac9
authored
Feb 01, 2021
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract RSpec matcher and make test more robust
Introduce shared matcher for Snowplow tracking
parent
fb418287
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
48 deletions
+55
-48
spec/requests/groups/email_campaigns_controller_spec.rb
spec/requests/groups/email_campaigns_controller_spec.rb
+43
-48
spec/support/matchers/track_self_describing_event_matcher.rb
spec/support/matchers/track_self_describing_event_matcher.rb
+12
-0
No files found.
spec/requests/groups/email_campaigns_controller_spec.rb
View file @
ba9feac9
...
...
@@ -12,6 +12,15 @@ RSpec.describe Groups::EmailCampaignsController do
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:track
)
{
'create'
}
let
(
:series
)
{
'0'
}
let
(
:schema
)
{
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
}
let
(
:data
)
do
{
namespace_id:
group
.
id
,
track:
track
.
to_sym
,
series:
series
.
to_i
,
subject_line:
subject_line
(
track
.
to_sym
,
series
.
to_i
)
}
end
before
do
sign_in
(
user
)
...
...
@@ -19,72 +28,58 @@ RSpec.describe Groups::EmailCampaignsController do
allow
(
Gitlab
::
Tracking
).
to
receive
(
:self_describing_event
)
end
subject
(
:get_index
)
do
subject
do
get
group_email_campaigns_url
(
group
,
track:
track
,
series:
series
)
response
end
RSpec
::
Matchers
.
define
:track_event
do
|*
args
|
match
do
expect
(
Gitlab
::
Tracking
).
to
have_received
(
:self_describing_event
).
with
(
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data:
{
namespace_id:
group
.
id
,
track:
track
.
to_sym
,
series:
series
.
to_i
,
subject_line:
subject_line
(
track
.
to_sym
,
series
.
to_i
)
}
)
shared_examples
'track and redirect'
do
it
do
is_expected
.
to
track_self_describing_event
(
schema
,
data
)
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
end
end
match_when_negated
do
expect
(
Gitlab
::
Tracking
).
not_to
have_received
(
:self_describing_event
)
shared_examples
'no track and 404'
do
it
do
is_expected
.
not_to
track_self_describing_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'track parameter'
do
where
(
:track
,
:valid
)
do
'create'
|
true
'verify'
|
true
'trial'
|
true
'team'
|
true
'xxxx'
|
false
nil
|
false
end
describe
'track parameter'
do
context
'when valid'
do
where
(
track:
Namespaces
::
InProductMarketingEmailsService
::
TRACKS
.
keys
)
with_them
do
it
do
if
valid
is_expected
.
to
track_event
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
else
is_expected
.
not_to
track_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
it_behaves_like
'track and redirect'
end
end
context
'when invalid'
do
where
(
track:
[
nil
,
'xxxx'
])
with_them
do
it_behaves_like
'no track and 404'
end
end
context
'series parameter'
do
where
(
:series
,
:valid
)
do
'0'
|
true
'1'
|
true
'2'
|
true
'-1'
|
false
'3'
|
false
nil
|
false
end
describe
'series parameter'
do
context
'when valid'
do
where
(
series:
(
0
..
Namespaces
::
InProductMarketingEmailsService
::
INTERVAL_DAYS
.
length
-
1
).
to_a
)
with_them
do
it
do
if
valid
is_expected
.
to
track_event
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
else
is_expected
.
not_to
track_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
it_behaves_like
'track and redirect'
end
end
context
'when invalid'
do
where
(
series:
[
-
1
,
nil
,
Namespaces
::
InProductMarketingEmailsService
::
INTERVAL_DAYS
.
length
])
with_them
do
it_behaves_like
'no track and 404'
end
end
end
end
...
...
spec/support/matchers/track_self_describing_event_matcher.rb
0 → 100644
View file @
ba9feac9
# frozen_string_literal: true
RSpec
::
Matchers
.
define
:track_self_describing_event
do
|
schema
,
data
|
match
do
expect
(
Gitlab
::
Tracking
).
to
have_received
(
:self_describing_event
)
.
with
(
schema
,
data:
data
)
end
match_when_negated
do
expect
(
Gitlab
::
Tracking
).
not_to
have_received
(
:self_describing_event
)
end
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