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
04c56cb7
Commit
04c56cb7
authored
Nov 12, 2019
by
Nicolò Maria Mezzopera
Committed by
Fatih Acet
Nov 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project package api call to api.js
- paths and function in api.js - unit tests
parent
fd926738
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
ee/app/assets/javascripts/api.js
ee/app/assets/javascripts/api.js
+23
-0
ee/spec/frontend/api_spec.js
ee/spec/frontend/api_spec.js
+59
-0
No files found.
ee/app/assets/javascripts/api.js
View file @
04c56cb7
...
...
@@ -15,6 +15,8 @@ export default {
'
/:project_full_path/environments/:environment_id/pods/:pod_name/containers/logs.json
'
,
podLogsPathWithPodContainer
:
'
/:project_full_path/environments/:environment_id/pods/:pod_name/containers/:container_name/logs.json
'
,
projectPackagesPath
:
'
/api/:version/projects/:id/packages
'
,
projectPackagePath
:
'
/api/:version/projects/:id/packages/:package_id
'
,
userSubscription
(
namespaceId
)
{
const
url
=
Api
.
buildUrl
(
this
.
subscriptionPath
).
replace
(
'
:id
'
,
encodeURIComponent
(
namespaceId
));
...
...
@@ -96,4 +98,25 @@ export default {
}
return
axios
.
get
(
url
);
},
projectPackages
(
id
)
{
const
url
=
Api
.
buildUrl
(
this
.
projectPackagesPath
).
replace
(
'
:id
'
,
id
);
return
axios
.
get
(
url
);
},
buildProjectPackageUrl
(
projectId
,
packageId
)
{
return
Api
.
buildUrl
(
this
.
projectPackagePath
)
.
replace
(
'
:id
'
,
projectId
)
.
replace
(
'
:package_id
'
,
packageId
);
},
projectPackage
(
projectId
,
packageId
)
{
const
url
=
this
.
buildProjectPackageUrl
(
projectId
,
packageId
);
return
axios
.
get
(
url
);
},
deleteProjectPackage
(
projectId
,
packageId
)
{
const
url
=
this
.
buildProjectPackageUrl
(
projectId
,
packageId
);
return
axios
.
delete
(
url
);
},
};
ee/spec/frontend/api_spec.js
View file @
04c56cb7
...
...
@@ -212,4 +212,63 @@ describe('Api', () => {
.
catch
(
done
.
fail
);
});
});
describe
(
'
packages
'
,
()
=>
{
const
projectId
=
'
project_a
'
;
const
packageId
=
'
package_b
'
;
describe
(
'
projectPackages
'
,
()
=>
{
it
(
'
fetch all project packages
'
,
()
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/projects/
${
projectId
}
/packages`
;
const
apiResponse
=
[{
id
:
1
,
name
:
'
foo
'
}];
jest
.
spyOn
(
axios
,
'
get
'
);
mock
.
onGet
(
expectedUrl
).
replyOnce
(
200
,
apiResponse
);
return
Api
.
projectPackages
(
projectId
).
then
(({
data
})
=>
{
expect
(
data
).
toEqual
(
apiResponse
);
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
expectedUrl
);
});
});
});
describe
(
'
buildProjectPackageUrl
'
,
()
=>
{
it
(
'
returns the right url
'
,
()
=>
{
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/projects/
${
projectId
}
/packages/
${
packageId
}
`
;
const
url
=
Api
.
buildProjectPackageUrl
(
projectId
,
packageId
);
expect
(
url
).
toEqual
(
expectedUrl
);
});
});
describe
(
'
projectPackage
'
,
()
=>
{
it
(
'
fetch package details
'
,
()
=>
{
const
expectedUrl
=
`foo`
;
const
apiResponse
=
{
id
:
1
,
name
:
'
foo
'
};
jest
.
spyOn
(
Api
,
'
buildProjectPackageUrl
'
).
mockReturnValue
(
expectedUrl
);
jest
.
spyOn
(
axios
,
'
get
'
);
mock
.
onGet
(
expectedUrl
).
replyOnce
(
200
,
apiResponse
);
return
Api
.
projectPackage
(
projectId
,
packageId
).
then
(({
data
})
=>
{
expect
(
data
).
toEqual
(
apiResponse
);
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
expectedUrl
);
});
});
});
describe
(
'
deleteProjectPackage
'
,
()
=>
{
it
(
'
delete a package
'
,
()
=>
{
const
expectedUrl
=
`foo`
;
const
apiResponse
=
true
;
jest
.
spyOn
(
Api
,
'
buildProjectPackageUrl
'
).
mockReturnValue
(
expectedUrl
);
jest
.
spyOn
(
axios
,
'
delete
'
);
mock
.
onDelete
(
expectedUrl
).
replyOnce
(
200
,
apiResponse
);
return
Api
.
deleteProjectPackage
(
projectId
,
packageId
).
then
(({
data
})
=>
{
expect
(
data
).
toEqual
(
apiResponse
);
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