chore: added tests for ensuring that the token is used properly when passed into the actions
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -119,6 +119,32 @@ describe('publish:azure', () => {
|
||||
).rejects.toThrow(/Unable to create the repository/);
|
||||
});
|
||||
|
||||
it('should not throw if there is a token provided through ctx.input', async () => {
|
||||
mockGitClient.createRepository.mockImplementation(() => ({
|
||||
remoteUrl: 'http://google.com',
|
||||
}));
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'myazurehostnotoken.com?repo=bob&owner=owner&organization=org',
|
||||
token: 'lols',
|
||||
},
|
||||
});
|
||||
|
||||
expect(WebApi).toHaveBeenCalledWith(
|
||||
'https://myazurehostnotoken.com/org',
|
||||
expect.any(Function),
|
||||
);
|
||||
|
||||
expect(mockGitClient.createRepository).toHaveBeenCalledWith(
|
||||
{
|
||||
name: 'bob',
|
||||
},
|
||||
'owner',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if there is no remoteUrl returned', async () => {
|
||||
mockGitClient.createRepository.mockImplementation(() => ({
|
||||
remoteUrl: null,
|
||||
|
||||
@@ -194,6 +194,45 @@ describe('publish:bitbucket', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work if the token is provided through ctx.input', async () => {
|
||||
expect.assertions(2);
|
||||
server.use(
|
||||
rest.post(
|
||||
'https://notoken.bitbucket.com/rest/api/1.0/projects/project/repos',
|
||||
(req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe('Bearer lols');
|
||||
expect(req.body).toEqual({ public: false, name: 'repo' });
|
||||
return res(
|
||||
ctx.status(201),
|
||||
ctx.set('Content-Type', 'application/json'),
|
||||
ctx.json({
|
||||
links: {
|
||||
self: [
|
||||
{
|
||||
href: 'https://bitbucket.mycompany.com/projects/project/repos/repo',
|
||||
},
|
||||
],
|
||||
clone: [
|
||||
{
|
||||
name: 'http',
|
||||
href: 'https://bitbucket.mycompany.com/scm/project/repo',
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'notoken.bitbucket.com?project=project&repo=repo',
|
||||
token: 'lols',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe('LFS for hosted bitbucket', () => {
|
||||
const repoCreationResponse = {
|
||||
links: {
|
||||
|
||||
@@ -96,6 +96,28 @@ describe('publish:gitlab', () => {
|
||||
).rejects.toThrow(/No token available for host/);
|
||||
});
|
||||
|
||||
it('should work when there is a token provided through ctx.input', async () => {
|
||||
mockGitlabClient.Namespaces.show.mockResolvedValue({ id: 1234 });
|
||||
mockGitlabClient.Projects.create.mockResolvedValue({
|
||||
http_url_to_repo: 'http://mockurl.git',
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'hosted.gitlab.com?repo=bob&owner=owner',
|
||||
token: 'token',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockGitlabClient.Namespaces.show).toHaveBeenCalledWith('owner');
|
||||
expect(mockGitlabClient.Projects.create).toHaveBeenCalledWith({
|
||||
namespace_id: 1234,
|
||||
name: 'bob',
|
||||
visibility: 'private',
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the correct Gitlab APIs when the owner is an organization', async () => {
|
||||
mockGitlabClient.Namespaces.show.mockResolvedValue({ id: 1234 });
|
||||
mockGitlabClient.Projects.create.mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user