From 1c6106bafbd89234282452bcdf87399a56f0ab1a Mon Sep 17 00:00:00 2001 From: Leon van Ginneken Date: Tue, 16 Aug 2022 15:35:03 +0200 Subject: [PATCH] test: add tests Signed-off-by: Leon van Ginneken --- .../builtin/github/githubRepoCreate.test.ts | 38 ++++++++++ .../actions/builtin/publish/github.test.ts | 71 +++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts index 0e7e907917..f7fd624865 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubRepoCreate.test.ts @@ -129,6 +129,25 @@ describe('github:repo:create', () => { allow_rebase_merge: true, visibility: 'public', }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + visibility: 'public', + }); }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { @@ -171,6 +190,25 @@ describe('github:repo:create', () => { allow_merge_commit: true, allow_rebase_merge: true, }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + }); }); it('should add access for the team when it starts with the owner', async () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index a526e73019..eec413e2f0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -134,6 +134,25 @@ describe('publish:github', () => { allow_rebase_merge: true, visibility: 'public', }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect(mockOctokit.rest.repos.createInOrg).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + org: 'owner', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + visibility: 'public', + }); }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { @@ -176,6 +195,25 @@ describe('publish:github', () => { allow_merge_commit: true, allow_rebase_merge: true, }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + homepage: 'https://example.com', + }, + }); + expect( + mockOctokit.rest.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + description: 'description', + name: 'repo', + private: false, + delete_branch_on_merge: false, + allow_squash_merge: true, + allow_merge_commit: true, + allow_rebase_merge: true, + }); }); it('should call initRepoAndPush with the correct values', async () => { @@ -812,4 +850,37 @@ describe('publish:github', () => { expect(enableBranchProtectionOnDefaultRepoBranch).not.toHaveBeenCalled(); }); + + it('should add homepage when provided', async () => { + mockOctokit.rest.users.getByUsername.mockResolvedValue({ + data: { type: 'User' }, + }); + + mockOctokit.rest.repos.createForAuthenticatedUser.mockResolvedValue({ + data: { + clone_url: 'https://github.com/clone/url.git', + html_url: 'https://github.com/html/url', + }, + }); + + mockOctokit.rest.repos.replaceAllTopics.mockResolvedValue({ + data: { + names: ['node.js'], + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + topics: ['node.js'], + }, + }); + + expect(mockOctokit.rest.repos.replaceAllTopics).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + names: ['node.js'], + }); + }); });