|
| 1 | +/* |
| 2 | + * Copyright 2020 Spotify AB |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { getVoidLogger } from '@backstage/backend-common'; |
| 18 | +import { GithubPreparer } from './github'; |
| 19 | +import { checkoutGitRepository } from './helpers'; |
| 20 | + |
| 21 | +jest.mock('./helpers', () => ({ |
| 22 | + ...jest.requireActual<{}>('./helpers'), |
| 23 | + checkoutGitRepository: jest.fn(() => '/tmp/backstage-repo/org/name/branch'), |
| 24 | +})); |
| 25 | + |
| 26 | +const createMockEntity = (annotations = {}) => { |
| 27 | + return { |
| 28 | + apiVersion: 'version', |
| 29 | + kind: 'TestKind', |
| 30 | + metadata: { |
| 31 | + name: 'test-component-name', |
| 32 | + annotations: { |
| 33 | + ...annotations, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }; |
| 37 | +}; |
| 38 | + |
| 39 | +const logger = getVoidLogger(); |
| 40 | + |
| 41 | +describe('github preparer', () => { |
| 42 | + it('should prepare temp docs path from github repo', async () => { |
| 43 | + const preparer = new GithubPreparer(logger); |
| 44 | + |
| 45 | + const mockEntity = createMockEntity({ |
| 46 | + 'backstage.io/techdocs-ref': |
| 47 | + 'github:https://github.com/spotify/backstage/blob/master/plugins/techdocs-backend/examples/documented-component', |
| 48 | + }); |
| 49 | + |
| 50 | + const tempDocsPath = await preparer.prepare(mockEntity); |
| 51 | + expect(checkoutGitRepository).toHaveBeenCalledTimes(1); |
| 52 | + expect(tempDocsPath).toEqual( |
| 53 | + '/tmp/backstage-repo/org/name/branch/plugins/techdocs-backend/examples/documented-component', |
| 54 | + ); |
| 55 | + }); |
| 56 | +}); |
0 commit comments