Updating the test case to create a git repo
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
This commit is contained in:
@@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PassThrough } from 'stream';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createPublishGiteaAction } from './gitea';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { rest } from 'msw';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
jest.mock('@backstage/plugin-scaffolder-node', () => {
|
||||
@@ -28,9 +29,6 @@ jest.mock('@backstage/plugin-scaffolder-node', () => {
|
||||
initRepoAndPush: jest.fn().mockResolvedValue({
|
||||
commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6',
|
||||
}),
|
||||
commitAndPushRepo: jest.fn().mockResolvedValue({
|
||||
commitHash: '220f19cc36b551763d157f1b5e4a4b446165dbd6',
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -40,6 +38,7 @@ describe('publish:gitea', () => {
|
||||
gitea: [
|
||||
{
|
||||
host: 'gitea.com',
|
||||
baseUrl: 'https://gitea.com',
|
||||
username: 'gitea_user',
|
||||
password: 'gitea_password',
|
||||
},
|
||||
@@ -52,7 +51,7 @@ describe('publish:gitea', () => {
|
||||
const action = createPublishGiteaAction({ integrations, config });
|
||||
const mockContext = {
|
||||
input: {
|
||||
repoUrl: 'gitea.com?repo=repo',
|
||||
repoUrl: 'gitea.com?repo=repo&owner=owner',
|
||||
description,
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
@@ -62,10 +61,6 @@ describe('publish:gitea', () => {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
|
||||
const mockGitClient = {
|
||||
createRepository: jest.fn(),
|
||||
};
|
||||
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
@@ -92,15 +87,36 @@ describe('publish:gitea', () => {
|
||||
});
|
||||
|
||||
it('should throw if there is no repositoryId returned', async () => {
|
||||
mockGitClient.createRepository.mockImplementation(() => ({
|
||||
remoteUrl: 'https://gitea.com',
|
||||
id: null,
|
||||
}));
|
||||
server.use(
|
||||
rest.put('https://gitea.com/api/v1/user/repo', (req, res, ctx) => {
|
||||
expect(req.headers.get('Authorization')).toBe(
|
||||
'Basic Z2l0ZWFfdXNlcjpnaXRlYV9wYXNzd29yZA==',
|
||||
);
|
||||
expect(req.body).toEqual({
|
||||
create_empty_commit: false,
|
||||
owners: ['owner'],
|
||||
description,
|
||||
parent: 'workspace',
|
||||
});
|
||||
return res(
|
||||
ctx.status(201),
|
||||
ctx.set('Content-Type', 'application/json'),
|
||||
ctx.json({}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
...mockContext.input,
|
||||
repoUrl: 'gitea.com?owner=owner&repo=repo',
|
||||
},
|
||||
});
|
||||
|
||||
await action.handler(mockContext);
|
||||
expect(initRepoAndPush).toHaveBeenCalledWith({
|
||||
dir: mockContext.workspacePath,
|
||||
remoteUrl: 'https://gitea.com',
|
||||
remoteUrl: 'https://gitea.com/api/v1/user/repo',
|
||||
defaultBranch: 'main',
|
||||
auth: { username: 'gitea_user', password: 'gitea_password' },
|
||||
logger: mockContext.logger,
|
||||
|
||||
@@ -47,7 +47,6 @@ const createGiteaProject = async (
|
||||
body: JSON.stringify({
|
||||
name: projectName,
|
||||
description,
|
||||
owner,
|
||||
}),
|
||||
headers: {
|
||||
...getGiteaRequestOptions(config).headers,
|
||||
|
||||
Reference in New Issue
Block a user