summaryrefslogtreecommitdiff
path: root/spec/frontend/api_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/api_spec.js')
-rw-r--r--spec/frontend/api_spec.js68
1 files changed, 54 insertions, 14 deletions
diff --git a/spec/frontend/api_spec.js b/spec/frontend/api_spec.js
index 139128e6d4a..f708d8c7728 100644
--- a/spec/frontend/api_spec.js
+++ b/spec/frontend/api_spec.js
@@ -116,6 +116,24 @@ describe('Api', () => {
});
});
});
+
+ describe('deleteProjectPackageFile', () => {
+ const packageFileId = 'package_file_id';
+
+ it('delete a package', () => {
+ const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages/${packageId}/package_files/${packageFileId}`;
+
+ jest.spyOn(axios, 'delete');
+ mock.onDelete(expectedUrl).replyOnce(httpStatus.OK, true);
+
+ return Api.deleteProjectPackageFile(projectId, packageId, packageFileId).then(
+ ({ data }) => {
+ expect(data).toEqual(true);
+ expect(axios.delete).toHaveBeenCalledWith(expectedUrl);
+ },
+ );
+ });
+ });
});
describe('container registry', () => {
@@ -1503,33 +1521,55 @@ describe('Api', () => {
'Content-Type': 'application/json',
};
- describe('when usage data increment unique users is called with feature flag disabled', () => {
+ describe('when user is set', () => {
beforeEach(() => {
- gon.features = { ...gon.features, usageDataApi: false };
+ window.gon.current_user_id = 1;
});
- it('returns null', () => {
- jest.spyOn(axios, 'post');
- mock.onPost(expectedUrl).replyOnce(httpStatus.OK, true);
+ describe('when usage data increment unique users is called with feature flag disabled', () => {
+ beforeEach(() => {
+ gon.features = { ...gon.features, usageDataApi: false };
+ });
- expect(axios.post).toHaveBeenCalledTimes(0);
- expect(Api.trackRedisHllUserEvent(event)).toEqual(null);
+ it('returns null and does not call the endpoint', () => {
+ jest.spyOn(axios, 'post');
+
+ const result = Api.trackRedisHllUserEvent(event);
+
+ expect(result).toEqual(null);
+ expect(axios.post).toHaveBeenCalledTimes(0);
+ });
+ });
+
+ describe('when usage data increment unique users is called', () => {
+ beforeEach(() => {
+ gon.features = { ...gon.features, usageDataApi: true };
+ });
+
+ it('resolves the Promise', () => {
+ jest.spyOn(axios, 'post');
+ mock.onPost(expectedUrl, { event }).replyOnce(httpStatus.OK, true);
+
+ return Api.trackRedisHllUserEvent(event).then(({ data }) => {
+ expect(data).toEqual(true);
+ expect(axios.post).toHaveBeenCalledWith(expectedUrl, postData, { headers });
+ });
+ });
});
});
- describe('when usage data increment unique users is called', () => {
+ describe('when user is not set and feature flag enabled', () => {
beforeEach(() => {
gon.features = { ...gon.features, usageDataApi: true };
});
- it('resolves the Promise', () => {
+ it('returns null and does not call the endpoint', () => {
jest.spyOn(axios, 'post');
- mock.onPost(expectedUrl, { event }).replyOnce(httpStatus.OK, true);
- return Api.trackRedisHllUserEvent(event).then(({ data }) => {
- expect(data).toEqual(true);
- expect(axios.post).toHaveBeenCalledWith(expectedUrl, postData, { headers });
- });
+ const result = Api.trackRedisHllUserEvent(event);
+
+ expect(result).toEqual(null);
+ expect(axios.post).toHaveBeenCalledTimes(0);
});
});
});