implement discovery too
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -115,6 +115,25 @@ export namespace mockApis {
|
||||
const mock: (partialImpl?: Partial<Config> | undefined) => ApiMock<Config>;
|
||||
}
|
||||
// (undocumented)
|
||||
export function discovery(options?: { baseUrl?: string }): jest.Mocked<{
|
||||
getBaseUrl(pluginId: string): Promise<string>;
|
||||
}>;
|
||||
// (undocumented)
|
||||
export namespace discovery {
|
||||
const // (undocumented)
|
||||
factory: (
|
||||
options?:
|
||||
| {
|
||||
baseUrl?: string | undefined;
|
||||
}
|
||||
| undefined,
|
||||
) => ApiFactory<DiscoveryApi, DiscoveryApi, {}>;
|
||||
const // (undocumented)
|
||||
mock: (
|
||||
partialImpl?: Partial<DiscoveryApi> | undefined,
|
||||
) => ApiMock<DiscoveryApi>;
|
||||
}
|
||||
// (undocumented)
|
||||
export function identity(options?: {
|
||||
userEntityRef?: string;
|
||||
ownershipEntityRefs?: string[];
|
||||
@@ -421,20 +440,24 @@ export function wrapInTestApp(
|
||||
// src/testUtils/apis/mockApis.d.ts:48:5 - (ae-undocumented) Missing documentation for "analytics".
|
||||
// src/testUtils/apis/mockApis.d.ts:49:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:50:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:101:5 - (ae-undocumented) Missing documentation for "identity".
|
||||
// src/testUtils/apis/mockApis.d.ts:109:5 - (ae-undocumented) Missing documentation for "identity".
|
||||
// src/testUtils/apis/mockApis.d.ts:110:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:118:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:120:5 - (ae-undocumented) Missing documentation for "permission".
|
||||
// src/testUtils/apis/mockApis.d.ts:123:5 - (ae-undocumented) Missing documentation for "permission".
|
||||
// src/testUtils/apis/mockApis.d.ts:124:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:127:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:129:5 - (ae-undocumented) Missing documentation for "storage".
|
||||
// src/testUtils/apis/mockApis.d.ts:132:5 - (ae-undocumented) Missing documentation for "storage".
|
||||
// src/testUtils/apis/mockApis.d.ts:133:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:136:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:138:5 - (ae-undocumented) Missing documentation for "translation".
|
||||
// src/testUtils/apis/mockApis.d.ts:139:5 - (ae-undocumented) Missing documentation for "translation".
|
||||
// src/testUtils/apis/mockApis.d.ts:140:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:141:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:101:5 - (ae-undocumented) Missing documentation for "discovery".
|
||||
// src/testUtils/apis/mockApis.d.ts:106:5 - (ae-undocumented) Missing documentation for "discovery".
|
||||
// src/testUtils/apis/mockApis.d.ts:107:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:110:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:112:5 - (ae-undocumented) Missing documentation for "identity".
|
||||
// src/testUtils/apis/mockApis.d.ts:120:5 - (ae-undocumented) Missing documentation for "identity".
|
||||
// src/testUtils/apis/mockApis.d.ts:121:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:129:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:131:5 - (ae-undocumented) Missing documentation for "permission".
|
||||
// src/testUtils/apis/mockApis.d.ts:134:5 - (ae-undocumented) Missing documentation for "permission".
|
||||
// src/testUtils/apis/mockApis.d.ts:135:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:138:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:140:5 - (ae-undocumented) Missing documentation for "storage".
|
||||
// src/testUtils/apis/mockApis.d.ts:143:5 - (ae-undocumented) Missing documentation for "storage".
|
||||
// src/testUtils/apis/mockApis.d.ts:144:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:147:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
// src/testUtils/apis/mockApis.d.ts:149:5 - (ae-undocumented) Missing documentation for "translation".
|
||||
// src/testUtils/apis/mockApis.d.ts:150:5 - (ae-undocumented) Missing documentation for "translation".
|
||||
// src/testUtils/apis/mockApis.d.ts:151:15 - (ae-undocumented) Missing documentation for "factory".
|
||||
// src/testUtils/apis/mockApis.d.ts:152:15 - (ae-undocumented) Missing documentation for "mock".
|
||||
```
|
||||
|
||||
@@ -79,6 +79,34 @@ describe('mockApis', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('discovery', () => {
|
||||
it('can create an instance and make assertions on it', async () => {
|
||||
const empty = mockApis.discovery();
|
||||
await expect(empty.getBaseUrl('catalog')).resolves.toBe(
|
||||
'http://example.com/api/catalog',
|
||||
);
|
||||
expect(empty.getBaseUrl).toHaveBeenCalledTimes(1);
|
||||
|
||||
const notEmpty = mockApis.discovery({ baseUrl: 'https://other.net' });
|
||||
await expect(notEmpty.getBaseUrl('catalog')).resolves.toBe(
|
||||
'https://other.net/api/catalog',
|
||||
);
|
||||
expect(notEmpty.getBaseUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('can create a mock and make assertions on it', async () => {
|
||||
const empty = mockApis.discovery.mock();
|
||||
expect(empty.getBaseUrl('catalog')).toBeUndefined();
|
||||
expect(empty.getBaseUrl).toHaveBeenCalledTimes(1);
|
||||
|
||||
const notEmpty = mockApis.discovery.mock({
|
||||
getBaseUrl: async () => 'replaced',
|
||||
});
|
||||
await expect(notEmpty.getBaseUrl('catalog')).resolves.toBe('replaced');
|
||||
expect(notEmpty.getBaseUrl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('identity', () => {
|
||||
it('can create an instance and make assertions on it', async () => {
|
||||
const empty = mockApis.identity();
|
||||
|
||||
@@ -20,14 +20,20 @@ import {
|
||||
ApiFactory,
|
||||
ApiRef,
|
||||
ConfigApi,
|
||||
DiscoveryApi,
|
||||
IdentityApi,
|
||||
StorageApi,
|
||||
analyticsApiRef,
|
||||
configApiRef,
|
||||
createApiFactory,
|
||||
discoveryApiRef,
|
||||
identityApiRef,
|
||||
storageApiRef,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import {
|
||||
TranslationApi,
|
||||
translationApiRef,
|
||||
} from '@backstage/core-plugin-api/alpha';
|
||||
import {
|
||||
AuthorizeResult,
|
||||
EvaluatePermissionRequest,
|
||||
@@ -40,10 +46,6 @@ import { JsonObject } from '@backstage/types';
|
||||
import { ApiMock } from './ApiMock';
|
||||
import { MockPermissionApi } from './PermissionApi';
|
||||
import { MockStorageApi } from './StorageApi';
|
||||
import {
|
||||
TranslationApi,
|
||||
translationApiRef,
|
||||
} from '@backstage/core-plugin-api/alpha';
|
||||
import { MockTranslationApi } from './TranslationApi';
|
||||
|
||||
/** @internal */
|
||||
@@ -200,6 +202,26 @@ export namespace mockApis {
|
||||
}));
|
||||
}
|
||||
|
||||
const discoveryMockSkeleton = (): jest.Mocked<DiscoveryApi> => ({
|
||||
getBaseUrl: jest.fn(),
|
||||
});
|
||||
export function discovery(options?: { baseUrl?: string }) {
|
||||
const baseUrl = options?.baseUrl ?? 'http://example.com';
|
||||
return simpleInstance(
|
||||
discoveryApiRef,
|
||||
{
|
||||
async getBaseUrl(pluginId: string) {
|
||||
return `${baseUrl}/api/${pluginId}`;
|
||||
},
|
||||
},
|
||||
discoveryMockSkeleton,
|
||||
);
|
||||
}
|
||||
export namespace discovery {
|
||||
export const factory = simpleFactory(discoveryApiRef, discovery);
|
||||
export const mock = simpleMock(discoveryApiRef, discoveryMockSkeleton);
|
||||
}
|
||||
|
||||
const identityMockSkeleton = (): jest.Mocked<IdentityApi> => ({
|
||||
getBackstageIdentity: jest.fn(),
|
||||
getCredentials: jest.fn(),
|
||||
|
||||
Reference in New Issue
Block a user