From 27e7db7709b5df68635152e57c8ea7bfbe8aafe0 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Mon, 14 Aug 2023 10:51:25 -0500 Subject: [PATCH] Fixed failing test Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .../confluenceToMarkdown.examples.test.ts | 66 ++++++++----------- .../confluenceToMarkdown.examples.ts | 2 - 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.test.ts b/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.test.ts index 1a3e249fb0..e5aeadbf00 100644 --- a/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.test.ts +++ b/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.test.ts @@ -1,19 +1,3 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - /* * Copyright 2023 The Backstage Authors * @@ -43,6 +27,7 @@ import { rest } from 'msw'; import { setupServer } from 'msw/node'; import { examples } from './confluenceToMarkdown.examples'; import yaml from 'yaml'; +import { ActionContext } from '@backstage/plugin-scaffolder-node'; jest.mock('fs-extra', () => ({ mkdirSync: jest.fn(), @@ -57,7 +42,7 @@ jest.mock('fs-extra', () => ({ })); describe('confluence:transform:markdown examples', () => { - const baseUrl = `https://nodomain.confluence.com`; + const baseUrl = `https://confluence.example.com`; const worker = setupServer(); setupRequestMockHandlers(worker); @@ -78,30 +63,34 @@ describe('confluence:transform:markdown examples', () => { }), ); + let reader: UrlReader; + let mockContext: ActionContext<{ + confluenceUrls: string[]; + repoUrl: string; + }>; + const logger = getVoidLogger(); jest.spyOn(logger, 'info'); const mockTmpDir = os.tmpdir(); - const mockContext = { - workspacePath: '/tmp', - logger, - logStream: new PassThrough(), - output: jest.fn(), - createTemporaryDirectory: jest.fn().mockResolvedValue(mockTmpDir), - }; - - const reader: UrlReader = { - readUrl: jest.fn(), - readTree: jest.fn().mockResolvedValue({ - dir: jest.fn(), - }), - search: jest.fn(), - }; - mockFs({ [`${mockTmpDir}/src/docs`]: {} }); - beforeEach(() => { - jest.resetAllMocks(); + reader = { + readUrl: jest.fn(), + readTree: jest.fn().mockResolvedValue({ + dir: jest.fn(), + }), + search: jest.fn(), + }; + mockContext = { + input: yaml.parse(examples[0].example).steps[0].input, + workspacePath: '/tmp', + logger, + logStream: new PassThrough(), + output: jest.fn(), + createTemporaryDirectory: jest.fn().mockResolvedValue(mockTmpDir), + }; + mockFs({ [`${mockTmpDir}/src/docs`]: {} }); }); afterEach(() => { jest.clearAllMocks(); @@ -160,13 +149,10 @@ describe('confluence:transform:markdown examples', () => { const action = createConfluenceToMarkdownAction(options); - await action.handler({ - ...mockContext, - input: yaml.parse(examples[0].example).steps[0].input, - }); + await action.handler(mockContext); expect(logger.info).toHaveBeenCalledWith( - `Fetching the mkdocs.yml catalog from https://notreal.github.com/space/backstage/mkdocs.yml`, + `Fetching the mkdocs.yml catalog from https://github.com/organization-name/repo-name/blob/main/mkdocs.yml`, ); expect(logger.info).toHaveBeenCalledTimes(5); expect(createWriteStream).toHaveBeenCalledTimes(1); diff --git a/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.ts b/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.ts index 29249d2dc3..e5d10644a6 100644 --- a/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.ts +++ b/plugins/scaffolder-backend-module-confluence-to-markdown/src/actions/confluence/confluenceToMarkdown.examples.ts @@ -30,8 +30,6 @@ export const examples: TemplateExample[] = [ input: { confluenceUrls: [ 'https://confluence.example.com/display/SPACEKEY/Page+Title', - 'https://confluence.example.com/prefix/display/PREFIXSPACEKEY/Prefix+Page+Title', - 'https://example.atlassian.net/wiki/spaces/CLOUDSPACEKEY/pages/1234567/Cloud+Page+Title', ], repoUrl: 'https://github.com/organization-name/repo-name/blob/main/mkdocs.yml',