diff --git a/plugins/techdocs/src/api.test.ts b/plugins/techdocs/src/api.test.ts index ebffa2469e..734650d7c8 100644 --- a/plugins/techdocs/src/api.test.ts +++ b/plugins/techdocs/src/api.test.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { useApi, configApiRef, UrlPatternDiscovery } from '@backstage/core'; +import { Config } from '@backstage/config'; +import { UrlPatternDiscovery } from '@backstage/core'; import { TechDocsStorageApi } from './api'; const mockEntity = { @@ -24,21 +25,29 @@ const mockEntity = { describe('TechDocsStorageApi', () => { const mockBaseUrl = 'http://backstage:9191/api/techdocs'; - const configApi = useApi(configApiRef); + const configApi = { + getOptionalString: () => 'http://backstage:9191/api/techdocs', + } as Partial; const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl); - it('should return correct base url based on defined storage', () => { + it('should return correct base url based on defined storage', async () => { + // @ts-ignore Partial not assignable to Config. const storageApi = new TechDocsStorageApi({ configApi, discoveryApi }); - expect(storageApi.getBaseUrl('test.js', mockEntity, '')).toEqual( + await expect( + storageApi.getBaseUrl('test.js', mockEntity, ''), + ).resolves.toEqual( `${mockBaseUrl}/docs/${mockEntity.namespace}/${mockEntity.kind}/${mockEntity.name}/test.js`, ); }); - it('should return base url with correct entity structure', () => { + it('should return base url with correct entity structure', async () => { + // @ts-ignore Partial not assignable to Config. const storageApi = new TechDocsStorageApi({ configApi, discoveryApi }); - expect(storageApi.getBaseUrl('test/', mockEntity, '')).toEqual( + await expect( + storageApi.getBaseUrl('test/', mockEntity, ''), + ).resolves.toEqual( `${mockBaseUrl}/docs/${mockEntity.namespace}/${mockEntity.kind}/${mockEntity.name}/test/`, ); }); diff --git a/plugins/techdocs/src/api.ts b/plugins/techdocs/src/api.ts index 1ca0e40592..a8b1f1e34f 100644 --- a/plugins/techdocs/src/api.ts +++ b/plugins/techdocs/src/api.ts @@ -178,6 +178,7 @@ export class TechDocsStorageApi implements TechDocsStorage { const { kind, namespace, name } = entityId; const apiOrigin = await this.getApiOrigin(); + return new URL( oldBaseUrl, `${apiOrigin}/docs/${namespace}/${kind}/${name}/${path}`,