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
ae79a7c1
Commit
ae79a7c1
authored
Mar 04, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the payload_example to empty JSON when nil
parent
1de7d11e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
27 deletions
+98
-27
app/models/alert_management/http_integration.rb
app/models/alert_management/http_integration.rb
+5
-0
ee/spec/requests/api/graphql/mutations/alert_management/http_integration/update_spec.rb
...utations/alert_management/http_integration/update_spec.rb
+67
-27
spec/models/alert_management/http_integration_spec.rb
spec/models/alert_management/http_integration_spec.rb
+26
-0
No files found.
app/models/alert_management/http_integration.rb
View file @
ae79a7c1
...
...
@@ -27,6 +27,7 @@ module AlertManagement
before_validation
:prevent_token_assignment
before_validation
:prevent_endpoint_identifier_assignment
before_validation
:ensure_token
before_validation
:ensure_payload_example_not_nil
scope
:for_endpoint_identifier
,
->
(
endpoint_identifier
)
{
where
(
endpoint_identifier:
endpoint_identifier
)
}
scope
:active
,
->
{
where
(
active:
true
)
}
...
...
@@ -74,5 +75,9 @@ module AlertManagement
self
.
endpoint_identifier
=
endpoint_identifier_was
end
end
def
ensure_payload_example_not_nil
self
.
payload_example
||=
{}
end
end
end
ee/spec/requests/api/graphql/mutations/alert_management/http_integration/update_spec.rb
View file @
ae79a7c1
...
...
@@ -88,12 +88,12 @@ RSpec.describe 'Updating an existing HTTP Integration' do
)
end
context
'when the
custom mappings attributes are not part of the mutation variable
s'
do
let_it_be
(
:payload_example
)
do
context
'when the
integration already has custom mapping param
s'
do
let_it_be
(
:
current_
payload_example
)
do
{
'alert'
=>
{
'name'
=>
'Test alert'
,
'desc'
=>
'Description'
}
}
end
let_it_be
(
:mapping
)
do
let_it_be
(
:
current_
mapping
)
do
{
'title'
=>
{
'path'
=>
%w(alert name)
,
'type'
=>
'string'
,
'label'
=>
'Title'
},
'description'
=>
{
'path'
=>
%w(alert desc)
,
'type'
=>
'string'
}
...
...
@@ -101,9 +101,48 @@ RSpec.describe 'Updating an existing HTTP Integration' do
end
let_it_be
(
:integration
)
do
create
(
:alert_management_http_integration
,
project:
project
,
payload_example:
payload_example
,
payload_attribute_mapping:
mapping
)
create
(
:alert_management_http_integration
,
project:
project
,
payload_example:
current_payload_example
,
payload_attribute_mapping:
current_
mapping
)
end
context
'when the custom mappings attributes are blank'
do
let
(
:payload_example
)
{
"{}"
}
let
(
:payload_attribute_mappings
)
{
[]
}
it
'resets the custom mapping params'
,
:aggregate_failures
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
integration_response
=
mutation_response
[
'integration'
]
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
integration_response
[
'id'
]).
to
eq
(
GitlabSchema
.
id_from_object
(
integration
).
to_s
)
expect
(
integration_response
[
'name'
]).
to
eq
(
'Modified Name'
)
integration
.
reload
expect
(
integration
.
payload_example
).
to
eq
({})
expect
(
integration
.
payload_attribute_mapping
).
to
eq
({})
end
end
context
'when the custom mappings attributes are nils'
do
let
(
:payload_example
)
{
nil
}
let
(
:payload_attribute_mappings
)
{
nil
}
it
'resets the custom mapping params'
,
:aggregate_failures
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
integration_response
=
mutation_response
[
'integration'
]
expect
(
response
).
to
have_gitlab_http_status
(
:success
)
expect
(
integration_response
[
'id'
]).
to
eq
(
GitlabSchema
.
id_from_object
(
integration
).
to_s
)
expect
(
integration_response
[
'name'
]).
to
eq
(
'Modified Name'
)
integration
.
reload
expect
(
integration
.
payload_example
).
to
eq
({})
expect
(
integration
.
payload_attribute_mapping
).
to
eq
({})
end
end
context
'when the custom mappings attributes are not part of the mutation variables'
do
let
(
:mutation
)
do
variables
=
{
id:
GitlabSchema
.
id_from_object
(
integration
).
to_s
,
...
...
@@ -131,8 +170,9 @@ RSpec.describe 'Updating an existing HTTP Integration' do
expect
(
integration_response
[
'name'
]).
to
eq
(
'Modified Name'
)
integration
.
reload
expect
(
integration
.
payload_example
).
to
eq
(
payload_example
)
expect
(
integration
.
payload_attribute_mapping
).
to
eq
(
mapping
)
expect
(
integration
.
payload_example
).
to
eq
(
current_payload_example
)
expect
(
integration
.
payload_attribute_mapping
).
to
eq
(
current_mapping
)
end
end
end
...
...
spec/models/alert_management/http_integration_spec.rb
View file @
ae79a7c1
...
...
@@ -81,6 +81,32 @@ RSpec.describe AlertManagement::HttpIntegration do
end
end
describe
'before validation'
do
describe
'#ensure_payload_example_not_nil'
do
subject
(
:integration
)
{
build
(
:alert_management_http_integration
,
payload_example:
payload_example
)
}
context
'when the payload_example is nil'
do
let
(
:payload_example
)
{
nil
}
it
'sets the payload_example to empty JSON'
do
integration
.
valid?
expect
(
integration
.
payload_example
).
to
eq
({})
end
end
context
'when the payload_example is not nil'
do
let
(
:payload_example
)
{
{
'key'
=>
'value'
}
}
it
'sets the payload_example to specified value'
do
integration
.
valid?
expect
(
integration
.
payload_example
).
to
eq
(
payload_example
)
end
end
end
end
describe
'#token'
do
subject
{
integration
.
token
}
...
...
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