implement discovery too

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-10-09 16:33:39 +02:00
parent d081861694
commit 3afafea87b
12 changed files with 129 additions and 75 deletions
@@ -30,11 +30,7 @@ import {
} from '@backstage/core-plugin-api';
describe('CookieAuthRefreshProvider', () => {
const discoveryApiMock = {
getBaseUrl: jest
.fn()
.mockResolvedValue('http://localhost:7000/api/techdocs'),
};
const discoveryApiMock = mockApis.discovery();
function getExpiresAtInFuture() {
const tenMinutesInMilliseconds = 10 * 60 * 1000;
@@ -118,7 +114,7 @@ describe('CookieAuthRefreshProvider', () => {
await waitFor(() =>
expect(fetchApiMock.fetch).toHaveBeenCalledWith(
'http://localhost:7000/api/techdocs/.backstage/auth/v1/cookie',
'http://example.com/api/techdocs/.backstage/auth/v1/cookie',
{ credentials: 'include' },
),
);
@@ -17,15 +17,11 @@
import React from 'react';
import { renderHook, waitFor } from '@testing-library/react';
import { fetchApiRef, discoveryApiRef } from '@backstage/core-plugin-api';
import { TestApiProvider } from '@backstage/test-utils';
import { TestApiProvider, mockApis } from '@backstage/test-utils';
import { useCookieAuthRefresh } from './useCookieAuthRefresh';
describe('useCookieAuthRefresh', () => {
const discoveryApiMock = {
getBaseUrl: jest
.fn()
.mockResolvedValue('http://localhost:7000/api/techdocs'),
};
const discoveryApiMock = mockApis.discovery();
const now = 1710316886171;
const tenMinutesInMilliseconds = 10 * 60 * 1000;
@@ -269,7 +265,7 @@ describe('useCookieAuthRefresh', () => {
await waitFor(() =>
expect(fetchApiMock.fetch).toHaveBeenCalledWith(
'http://localhost:7000/api/techdocs/.backstage/auth/v1/cookie',
'http://example.com/api/techdocs/.backstage/auth/v1/cookie',
{ credentials: 'include' },
),
);
@@ -14,8 +14,9 @@
* limitations under the License.
*/
import { DiscoveryApi, discoveryApiRef } from '@backstage/core-plugin-api';
import { discoveryApiRef } from '@backstage/core-plugin-api';
import {
mockApis,
renderInTestApp,
TestApiProvider,
textContentMatcher,
@@ -37,9 +38,7 @@ describe('PodExecTerminal', () => {
const podName = 'pod1';
const podNamespace = 'podNamespace';
const mockDiscoveryApi: Partial<DiscoveryApi> = {
getBaseUrl: () => Promise.resolve('http://localhost'),
};
const mockDiscoveryApi = mockApis.discovery();
it('Should render an XTerm web terminal', async () => {
await renderInTestApp(
@@ -62,7 +61,7 @@ describe('PodExecTerminal', () => {
it('Should connect to WebSocket server & render response', async () => {
const server = new WS(
'ws://localhost/proxy/api/v1/namespaces/podNamespace/pods/pod1/exec?container=container2&stdin=true&stdout=true&stderr=true&tty=true&command=%2Fbin%2Fsh',
'ws://example.com/api/kubernetes/proxy/api/v1/namespaces/podNamespace/pods/pod1/exec?container=container2&stdin=true&stdout=true&stderr=true&tty=true&command=%2Fbin%2Fsh',
);
await renderInTestApp(
@@ -17,19 +17,21 @@
import React from 'react';
import { screen } from '@testing-library/react';
import { TestApiProvider, renderInTestApp } from '@backstage/test-utils';
import {
TestApiProvider,
mockApis,
renderInTestApp,
} from '@backstage/test-utils';
import '@testing-library/jest-dom';
import { PodDrawer } from './PodDrawer';
import { DiscoveryApi, discoveryApiRef } from '@backstage/core-plugin-api';
import { discoveryApiRef } from '@backstage/core-plugin-api';
jest.mock('../../../hooks/useIsPodExecTerminalSupported');
describe('PodDrawer', () => {
it('Should show title and container names', async () => {
const mockDiscoveryApi: Partial<DiscoveryApi> = {
getBaseUrl: () => Promise.resolve('http://localhost'),
};
const mockDiscoveryApi = mockApis.discovery();
await renderInTestApp(
<TestApiProvider apis={[[discoveryApiRef, mockDiscoveryApi]]}>
@@ -14,24 +14,21 @@
* limitations under the License.
*/
import { DiscoveryApi } from '@backstage/core-plugin-api';
import { mockApis } from '@backstage/test-utils';
import WS from 'jest-websocket-mock';
import { SignalClient } from './SignalClient';
describe('SignalsClient', () => {
const baseUrlFunction = jest.fn();
const identity = mockApis.identity({ token: '12345' });
const discoveryApi = {
getBaseUrl: baseUrlFunction,
} as unknown as DiscoveryApi;
const discoveryApi = mockApis.discovery({ baseUrl: 'http://localhost:1234' });
let server: WS;
beforeEach(async () => {
jest.clearAllMocks();
baseUrlFunction.mockResolvedValue('http://localhost:1234');
server = new WS('ws://localhost:1234', { jsonProtocol: true });
server = new WS('ws://localhost:1234/api/signals', {
jsonProtocol: true,
});
});
afterEach(() => {
@@ -81,12 +81,6 @@ const techdocsStorageApiMock: jest.Mocked<typeof techdocsStorageApiRef.T> = {
syncEntityDocs: jest.fn(),
};
const discoveryApiMock = {
getBaseUrl: jest
.fn()
.mockResolvedValue('https://localhost:7000/api/techdocs'),
};
const fetchApiMock = {
fetch: jest.fn().mockResolvedValue({
ok: true,
@@ -116,7 +110,7 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => {
<TestApiProvider
apis={[
[fetchApiRef, fetchApiMock],
[discoveryApiRef, discoveryApiMock],
[discoveryApiRef, mockApis.discovery()],
[scmIntegrationsApiRef, {}],
[configApiRef, configApi],
[techdocsApiRef, techdocsApiMock],