@@ -66,11 +66,13 @@ const mockConfigApi = mockApis.config({
|
||||
});
|
||||
|
||||
const mockCatalogApi = catalogApiMock.mock();
|
||||
jest.spyOn(mockCatalogApi, 'queryEntities');
|
||||
|
||||
const mockIdentityApi = mockApis.identity({
|
||||
userEntityRef: ownershipEntityRefs[0],
|
||||
ownershipEntityRefs,
|
||||
});
|
||||
jest.spyOn(mockIdentityApi, 'getBackstageIdentity');
|
||||
|
||||
const mockStarredEntitiesApi = new MockStarredEntitiesApi();
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ const mockIdentityApi = mockApis.identity({
|
||||
ownershipEntityRefs: ['user:default/spiderman', 'user:group/a-group'],
|
||||
userEntityRef: 'user:default/spiderman',
|
||||
});
|
||||
jest.spyOn(mockIdentityApi, 'getBackstageIdentity');
|
||||
|
||||
jest.mock('@backstage/core-plugin-api', () => {
|
||||
const actual = jest.requireActual('@backstage/core-plugin-api');
|
||||
|
||||
@@ -131,7 +131,7 @@ describe('useAsyncEntity', () => {
|
||||
});
|
||||
|
||||
it('should provide entityRef analytics context', () => {
|
||||
const analyticsSpy = mockApis.analytics();
|
||||
const analyticsSpy = mockApis.analytics.mock();
|
||||
const apis = TestApiRegistry.from([analyticsApiRef, analyticsSpy]);
|
||||
const { result } = renderHook(() => useAnalytics(), {
|
||||
wrapper: ({ children }: React.PropsWithChildren<{}>) => (
|
||||
@@ -154,7 +154,7 @@ describe('useAsyncEntity', () => {
|
||||
});
|
||||
|
||||
it('should omit entityRef analytics context', () => {
|
||||
const analyticsSpy = mockApis.analytics();
|
||||
const analyticsSpy = mockApis.analytics.mock();
|
||||
const apis = TestApiRegistry.from([analyticsApiRef, analyticsSpy]);
|
||||
const { result } = renderHook(() => useAnalytics(), {
|
||||
wrapper: ({ children }: PropsWithChildren<{}>) => (
|
||||
|
||||
@@ -67,6 +67,7 @@ describe('usePermission', () => {
|
||||
const permissionApi = mockApis.permission({
|
||||
authorize: AuthorizeResult.ALLOW,
|
||||
});
|
||||
jest.spyOn(permissionApi, 'authorize');
|
||||
|
||||
const { findByText } = renderComponent(permissionApi);
|
||||
|
||||
@@ -78,6 +79,7 @@ describe('usePermission', () => {
|
||||
const permissionApi = mockApis.permission({
|
||||
authorize: AuthorizeResult.DENY,
|
||||
});
|
||||
jest.spyOn(permissionApi, 'authorize');
|
||||
|
||||
const { findByText } = renderComponent(permissionApi);
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ describe('TechDocsStorageClient', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
identityApi.getCredentials.mockResolvedValue({ token: undefined });
|
||||
});
|
||||
|
||||
it('should return correct base url based on defined storage', async () => {
|
||||
@@ -92,7 +91,6 @@ describe('TechDocsStorageClient', () => {
|
||||
await Promise.resolve();
|
||||
onmessage?.({ id: '', event: 'finish', data: '{"updated": false}' });
|
||||
});
|
||||
identityApi.getCredentials.mockResolvedValue({});
|
||||
await storageApi.syncEntityDocs(mockEntity);
|
||||
|
||||
expect(mockFetchEventSource).toHaveBeenCalledWith(
|
||||
@@ -123,7 +121,6 @@ describe('TechDocsStorageClient', () => {
|
||||
onmessage?.({ id: '', event: 'finish', data: '{"updated": false}' });
|
||||
});
|
||||
|
||||
identityApi.getCredentials.mockResolvedValue({});
|
||||
await expect(storageApi.syncEntityDocs(mockEntity)).resolves.toEqual(
|
||||
'cached',
|
||||
);
|
||||
@@ -143,7 +140,6 @@ describe('TechDocsStorageClient', () => {
|
||||
onmessage?.({ id: '', event: 'finish', data: '{"updated": true}' });
|
||||
});
|
||||
|
||||
identityApi.getCredentials.mockResolvedValue({});
|
||||
await expect(storageApi.syncEntityDocs(mockEntity)).resolves.toEqual(
|
||||
'updated',
|
||||
);
|
||||
@@ -166,7 +162,6 @@ describe('TechDocsStorageClient', () => {
|
||||
onmessage?.({ id: '', event: 'finish', data: '{"updated": false}' });
|
||||
});
|
||||
|
||||
identityApi.getCredentials.mockResolvedValue({});
|
||||
const logHandler = jest.fn();
|
||||
await expect(
|
||||
storageApi.syncEntityDocs(mockEntity, logHandler),
|
||||
@@ -189,7 +184,6 @@ describe('TechDocsStorageClient', () => {
|
||||
});
|
||||
|
||||
// we await later after we emitted the error
|
||||
identityApi.getCredentials.mockResolvedValue({});
|
||||
const promise = storageApi.syncEntityDocs(mockEntity).then();
|
||||
|
||||
await expect(promise).rejects.toThrow(NotFoundError);
|
||||
@@ -204,7 +198,6 @@ describe('TechDocsStorageClient', () => {
|
||||
});
|
||||
|
||||
// we await later after we emitted the error
|
||||
identityApi.getCredentials.mockResolvedValue({});
|
||||
const promise = storageApi.syncEntityDocs(mockEntity).then();
|
||||
|
||||
mockFetchEventSource.mockImplementation(async (_url, options) => {
|
||||
|
||||
Reference in New Issue
Block a user