Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-10-10 16:35:28 +02:00
parent bc8b624ead
commit 34fcc96004
9 changed files with 33 additions and 57 deletions
+18 -22
View File
@@ -92,7 +92,7 @@ export class MockAnalyticsApi implements AnalyticsApi {
// @public
export namespace mockApis {
export function analytics(): jest.Mocked<AnalyticsApi>;
export function analytics(): AnalyticsApi;
export namespace analytics {
const // (undocumented)
factory: () => ApiFactory<AnalyticsApi, AnalyticsApi, {}>;
@@ -112,9 +112,7 @@ export namespace mockApis {
) => ApiFactory<Config, Config, {}>;
const mock: (partialImpl?: Partial<Config> | undefined) => ApiMock<Config>;
}
export function discovery(options?: { baseUrl?: string }): jest.Mocked<{
getBaseUrl(pluginId: string): Promise<string>;
}>;
export function discovery(options?: { baseUrl?: string }): DiscoveryApi;
export namespace discovery {
const // (undocumented)
factory: (
@@ -136,7 +134,7 @@ export namespace mockApis {
email?: string;
displayName?: string;
picture?: string;
}): jest.Mocked<IdentityApi>;
}): IdentityApi;
export namespace identity {
const // (undocumented)
factory: (
@@ -163,7 +161,7 @@ export namespace mockApis {
| ((
request: EvaluatePermissionRequest,
) => AuthorizeResult.ALLOW | AuthorizeResult.DENY);
}): jest.Mocked<PermissionApi>;
}): PermissionApi;
export namespace permission {
const // (undocumented)
factory: (
@@ -184,9 +182,7 @@ export namespace mockApis {
partialImpl?: Partial<PermissionApi> | undefined,
) => ApiMock<PermissionApi>;
}
export function storage(options?: {
data?: JsonObject;
}): jest.Mocked<StorageApi>;
export function storage(options?: { data?: JsonObject }): StorageApi;
export namespace storage {
const // (undocumented)
factory: (
@@ -201,7 +197,7 @@ export namespace mockApis {
partialImpl?: Partial<StorageApi> | undefined,
) => ApiMock<StorageApi>;
}
export function translation(): jest.Mocked<TranslationApi>;
export function translation(): TranslationApi;
export namespace translation {
const // (undocumented)
factory: () => ApiFactory<TranslationApi, TranslationApi, {}>;
@@ -424,16 +420,16 @@ export function wrapInTestApp(
// src/testUtils/apis/StorageApi/MockStorageApi.d.ts:24:5 - (ae-undocumented) Missing documentation for "set".
// src/testUtils/apis/StorageApi/MockStorageApi.d.ts:25:5 - (ae-undocumented) Missing documentation for "remove".
// src/testUtils/apis/StorageApi/MockStorageApi.d.ts:26:5 - (ae-undocumented) Missing documentation for "observe$".
// src/testUtils/apis/mockApis.d.ts:59:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:60:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:128:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:131:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:153:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:161:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:180:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:183:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:200:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:203:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:218:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:219:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:58:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:59:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:125:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:128:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:150:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:158:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:177:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:180:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:197:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:200:15 - (ae-undocumented) Missing documentation for "mock".
// src/testUtils/apis/mockApis.d.ts:215:15 - (ae-undocumented) Missing documentation for "factory".
// src/testUtils/apis/mockApis.d.ts:216:15 - (ae-undocumented) Missing documentation for "mock".
```
@@ -25,7 +25,7 @@ import { createTranslationRef } from '@backstage/core-plugin-api/alpha';
describe('mockApis', () => {
describe('analytics', () => {
it('can create an instance and make assertions on it', () => {
it('can create an instance', () => {
const analytics = mockApis.analytics();
expect(
analytics.captureEvent({
@@ -34,7 +34,6 @@ describe('mockApis', () => {
context: { pluginId: 'c', extension: 'd', routeRef: 'e' },
}),
).toBeUndefined();
expect(analytics.captureEvent).toHaveBeenCalledTimes(1);
});
it('can create a mock and make assertions on it', async () => {
@@ -80,18 +79,16 @@ describe('mockApis', () => {
});
describe('discovery', () => {
it('can create an instance and make assertions on it', async () => {
it('can create an instance', 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 () => {
@@ -108,7 +105,7 @@ describe('mockApis', () => {
});
describe('identity', () => {
it('can create an instance and make assertions on it', async () => {
it('can create an instance', async () => {
const empty = mockApis.identity();
await expect(empty.getBackstageIdentity()).resolves.toEqual({
type: 'user',
@@ -118,10 +115,6 @@ describe('mockApis', () => {
await expect(empty.getCredentials()).resolves.toEqual({});
await expect(empty.getProfileInfo()).resolves.toEqual({});
await expect(empty.signOut()).resolves.toBeUndefined();
expect(empty.getBackstageIdentity).toHaveBeenCalledTimes(1);
expect(empty.getCredentials).toHaveBeenCalledTimes(1);
expect(empty.getProfileInfo).toHaveBeenCalledTimes(1);
expect(empty.signOut).toHaveBeenCalledTimes(1);
const notEmpty = mockApis.identity({
userEntityRef: 'a',
@@ -143,10 +136,6 @@ describe('mockApis', () => {
picture: 'f',
});
await expect(notEmpty.signOut()).resolves.toBeUndefined();
expect(notEmpty.getBackstageIdentity).toHaveBeenCalledTimes(1);
expect(notEmpty.getCredentials).toHaveBeenCalledTimes(1);
expect(notEmpty.getProfileInfo).toHaveBeenCalledTimes(1);
expect(notEmpty.signOut).toHaveBeenCalledTimes(1);
});
it('can create a mock and make assertions on it', async () => {
@@ -194,7 +183,7 @@ describe('mockApis', () => {
});
describe('permission', () => {
it('can create an instance and make assertions on it', async () => {
it('can create an instance', async () => {
// default allow
const permission1 = mockApis.permission();
await expect(
@@ -205,7 +194,6 @@ describe('mockApis', () => {
}),
}),
).resolves.toEqual({ result: AuthorizeResult.ALLOW });
expect(permission1.authorize).toHaveBeenCalledTimes(1);
// static value
const permission2 = mockApis.permission({
@@ -219,7 +207,6 @@ describe('mockApis', () => {
}),
}),
).resolves.toEqual({ result: AuthorizeResult.DENY });
expect(permission2.authorize).toHaveBeenCalledTimes(1);
// callback form
const permission3 = mockApis.permission({
@@ -244,7 +231,6 @@ describe('mockApis', () => {
}),
}),
).resolves.toEqual({ result: AuthorizeResult.DENY });
expect(permission3.authorize).toHaveBeenCalledTimes(2);
});
it('can create a mock and make assertions on it', async () => {
@@ -548,10 +534,9 @@ describe('mockApis', () => {
});
});
it('can create an instance and make assertions on it', () => {
it('can create an instance', () => {
const empty = mockApis.storage();
expect(empty.snapshot('a')).toEqual({ key: 'a', presence: 'absent' });
expect(empty.snapshot).toHaveBeenCalledTimes(1);
const notEmpty = mockApis.storage({ data: { a: 1, b: { c: 2 } } });
expect(notEmpty.snapshot('a')).toEqual({
@@ -564,8 +549,6 @@ describe('mockApis', () => {
presence: 'present',
value: 2,
});
expect(notEmpty.snapshot).toHaveBeenCalledTimes(1); // "inner" (forBucket returned) instances aren't mocked
expect(notEmpty.forBucket).toHaveBeenCalledTimes(1);
});
it('can create a mock and make assertions on it', () => {
@@ -750,7 +733,7 @@ describe('mockApis', () => {
});
});
it('can create an instance and make assertions on it', () => {
it('can create an instance', () => {
const translation = mockApis.translation();
const ref = createTranslationRef({
id: 'test',
@@ -761,7 +744,6 @@ describe('mockApis', () => {
throw new Error('not ready');
}
expect(result.t('a')).toEqual('b');
expect(translation.getTranslation).toHaveBeenCalledTimes(1);
});
it('can create a mock and make assertions on it', () => {