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
Hide 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
...
@@ -12,6 +12,15 @@ RSpec.describe Groups::EmailCampaignsController do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:track
)
{
'create'
}
let
(
:track
)
{
'create'
}
let
(
:series
)
{
'0'
}
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
before
do
sign_in
(
user
)
sign_in
(
user
)
...
@@ -19,71 +28,57 @@ RSpec.describe Groups::EmailCampaignsController do
...
@@ -19,71 +28,57 @@ RSpec.describe Groups::EmailCampaignsController do
allow
(
Gitlab
::
Tracking
).
to
receive
(
:self_describing_event
)
allow
(
Gitlab
::
Tracking
).
to
receive
(
:self_describing_event
)
end
end
subject
(
:get_index
)
do
subject
do
get
group_email_campaigns_url
(
group
,
track:
track
,
series:
series
)
get
group_email_campaigns_url
(
group
,
track:
track
,
series:
series
)
response
response
end
end
RSpec
::
Matchers
.
define
:track_event
do
|*
args
|
shared_examples
'track and redirect'
do
match
do
it
do
expect
(
Gitlab
::
Tracking
).
to
have_received
(
:self_describing_event
).
with
(
is_expected
.
to
track_self_describing_event
(
schema
,
data
)
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
,
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
data:
{
namespace_id:
group
.
id
,
track:
track
.
to_sym
,
series:
series
.
to_i
,
subject_line:
subject_line
(
track
.
to_sym
,
series
.
to_i
)
}
)
end
end
end
match_when_negated
do
shared_examples
'no track and 404'
do
expect
(
Gitlab
::
Tracking
).
not_to
have_received
(
:self_describing_event
)
it
do
is_expected
.
not_to
track_self_describing_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
end
end
end
end
context
'track parameter'
do
describe
'track parameter'
do
where
(
:track
,
:valid
)
do
context
'when valid'
do
'create'
|
true
where
(
track:
Namespaces
::
InProductMarketingEmailsService
::
TRACKS
.
keys
)
'verify'
|
true
'trial'
|
true
with_them
do
'team'
|
true
it_behaves_like
'track and redirect'
'xxxx'
|
false
end
nil
|
false
end
end
with_them
do
context
'when invalid'
do
it
do
where
(
track:
[
nil
,
'xxxx'
])
if
valid
is_expected
.
to
track_event
with_them
do
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
it_behaves_like
'no track and 404'
else
is_expected
.
not_to
track_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
end
end
end
end
end
end
end
context
'series parameter'
do
describe
'series parameter'
do
where
(
:series
,
:valid
)
do
context
'when valid'
do
'0'
|
true
where
(
series:
(
0
..
Namespaces
::
InProductMarketingEmailsService
::
INTERVAL_DAYS
.
length
-
1
).
to_a
)
'1'
|
true
'2'
|
true
with_them
do
'-1'
|
false
it_behaves_like
'track and redirect'
'3'
|
false
end
nil
|
false
end
end
with_them
do
context
'when invalid'
do
it
do
where
(
series:
[
-
1
,
nil
,
Namespaces
::
InProductMarketingEmailsService
::
INTERVAL_DAYS
.
length
])
if
valid
is_expected
.
to
track_event
with_them
do
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
it_behaves_like
'no track and 404'
else
is_expected
.
not_to
track_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
end
end
end
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