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
ea6abdb8
Commit
ea6abdb8
authored
Apr 12, 2022
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for alert api
parent
6741df10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
0 deletions
+140
-0
spec/frontend/api/alert_management_alerts_api_spec.js
spec/frontend/api/alert_management_alerts_api_spec.js
+140
-0
No files found.
spec/frontend/api/alert_management_alerts_api_spec.js
0 → 100644
View file @
ea6abdb8
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
*
as
alertManagementAlertsApi
from
'
~/api/alert_management_alerts_api
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
describe
(
'
~/api/alert_management_alerts_api.js
'
,
()
=>
{
let
mock
;
let
originalGon
;
const
projectId
=
1
;
const
alertIid
=
2
;
const
imageData
=
{
filePath
:
'
test
'
,
filename
:
'
hello
'
,
id
:
5
,
url
:
null
};
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
originalGon
=
window
.
gon
;
window
.
gon
=
{
api_version
:
'
v4
'
};
});
afterEach
(()
=>
{
mock
.
restore
();
window
.
gon
=
originalGon
;
});
describe
(
'
fetchAlertMetricImages
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
axios
,
'
get
'
);
});
it
(
'
retrieves metric images from the correct URL and returns them in the response data
'
,
()
=>
{
const
expectedUrl
=
`/api/v4/projects/
${
projectId
}
/alert_management_alerts/
${
alertIid
}
/metric_images`
;
const
expectedData
=
[
imageData
];
const
options
=
{
alertIid
,
id
:
projectId
};
mock
.
onGet
(
expectedUrl
).
reply
(
200
,
{
data
:
expectedData
});
return
alertManagementAlertsApi
.
fetchAlertMetricImages
(
options
).
then
(({
data
})
=>
{
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
expectedUrl
);
expect
(
data
.
data
).
toEqual
(
expectedData
);
});
});
});
describe
(
'
uploadAlertMetricImage
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
axios
,
'
post
'
);
});
it
(
'
uploads a metric image to the correct URL and returns it in the response data
'
,
()
=>
{
const
expectedUrl
=
`/api/v4/projects/
${
projectId
}
/alert_management_alerts/
${
alertIid
}
/metric_images`
;
const
expectedData
=
[
imageData
];
const
file
=
new
File
([
'
zip contents
'
],
'
hello
'
);
const
url
=
'
https://www.example.com
'
;
const
urlText
=
'
Example website
'
;
const
expectedFormData
=
new
FormData
();
expectedFormData
.
append
(
'
file
'
,
file
);
expectedFormData
.
append
(
'
url
'
,
url
);
expectedFormData
.
append
(
'
url_text
'
,
urlText
);
mock
.
onPost
(
expectedUrl
).
reply
(
201
,
{
data
:
expectedData
});
return
alertManagementAlertsApi
.
uploadAlertMetricImage
({
alertIid
,
id
:
projectId
,
file
,
url
,
urlText
,
})
.
then
(({
data
})
=>
{
expect
(
data
).
toEqual
({
data
:
expectedData
});
expect
(
axios
.
post
).
toHaveBeenCalledWith
(
expectedUrl
,
expectedFormData
,
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
},
});
});
});
});
describe
(
'
updateAlertMetricImage
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
axios
,
'
put
'
);
});
it
(
'
updates a metric image to the correct URL and returns it in the response data
'
,
()
=>
{
const
imageIid
=
3
;
const
expectedUrl
=
`/api/v4/projects/
${
projectId
}
/alert_management_alerts/
${
alertIid
}
/metric_images/
${
imageIid
}
`
;
const
expectedData
=
[
imageData
];
const
url
=
'
https://www.example.com
'
;
const
urlText
=
'
Example website
'
;
const
expectedFormData
=
new
FormData
();
expectedFormData
.
append
(
'
url
'
,
url
);
expectedFormData
.
append
(
'
url_text
'
,
urlText
);
mock
.
onPut
(
expectedUrl
).
reply
(
200
,
{
data
:
expectedData
});
return
alertManagementAlertsApi
.
updateAlertMetricImage
({
alertIid
,
id
:
projectId
,
imageId
:
imageIid
,
url
,
urlText
,
})
.
then
(({
data
})
=>
{
expect
(
data
).
toEqual
({
data
:
expectedData
});
expect
(
axios
.
put
).
toHaveBeenCalledWith
(
expectedUrl
,
expectedFormData
);
});
});
});
describe
(
'
deleteAlertMetricImage
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
spyOn
(
axios
,
'
delete
'
);
});
it
(
'
deletes a metric image to the correct URL and returns it in the response data
'
,
()
=>
{
const
imageIid
=
3
;
const
expectedUrl
=
`/api/v4/projects/
${
projectId
}
/alert_management_alerts/
${
alertIid
}
/metric_images/
${
imageIid
}
`
;
const
expectedData
=
[
imageData
];
mock
.
onDelete
(
expectedUrl
).
reply
(
204
,
{
data
:
expectedData
});
return
alertManagementAlertsApi
.
deleteAlertMetricImage
({
alertIid
,
id
:
projectId
,
imageId
:
imageIid
,
})
.
then
(({
data
})
=>
{
expect
(
data
).
toEqual
({
data
:
expectedData
});
expect
(
axios
.
delete
).
toHaveBeenCalledWith
(
expectedUrl
);
});
});
});
});
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