Merge pull request #27070 from backstage/freben/catalog-expect-too

rewrite some more tests to use actual fake catalog instead of mock
This commit is contained in:
Fredrik Adelöw
2024-10-21 15:44:32 +02:00
committed by GitHub
10 changed files with 144 additions and 179 deletions
@@ -17,11 +17,11 @@
import { TokenManager } from '@backstage/backend-common';
import {
RELATION_MEMBER_OF,
UserEntity,
UserEntityV1alpha1,
} from '@backstage/catalog-model';
import { catalogServiceMock } from '@backstage/plugin-catalog-node/testUtils';
import { CatalogIdentityClient } from './CatalogIdentityClient';
import { mockServices } from '@backstage/backend-test-utils';
describe('CatalogIdentityClient', () => {
const tokenManager: jest.Mocked<TokenManager> = {
@@ -32,14 +32,25 @@ describe('CatalogIdentityClient', () => {
afterEach(() => jest.resetAllMocks());
it('findUser passes through the correct search params', async () => {
const catalogApi = catalogServiceMock.mock({
getEntities: jest
.fn()
.mockResolvedValueOnce({ items: [{} as UserEntity] }),
const catalogApi = catalogServiceMock({
entities: [
{
apiVersion: 'backstage.io/v1beta1',
kind: 'User',
metadata: {
name: 'user',
namespace: 'default',
annotations: { key: 'value' },
},
spec: {},
},
],
});
jest.spyOn(catalogApi, 'getEntities');
tokenManager.getToken.mockResolvedValue({ token: 'my-token' });
const client = new CatalogIdentityClient({
discovery: {} as any,
discovery: mockServices.discovery(),
catalogApi,
tokenManager,
});
@@ -94,9 +105,8 @@ describe('CatalogIdentityClient', () => {
],
},
];
const catalogApi = catalogServiceMock.mock({
getEntities: jest.fn().mockResolvedValueOnce({ items: mockUsers }),
});
const catalogApi = catalogServiceMock({ entities: mockUsers });
jest.spyOn(catalogApi, 'getEntities');
tokenManager.getToken.mockResolvedValue({ token: 'my-token' });
const client = new CatalogIdentityClient({
@@ -26,9 +26,8 @@ describe('CatalogAuthResolverContext', () => {
jest.clearAllMocks();
});
const catalogApi = catalogServiceMock.mock({
getEntities: jest.fn().mockResolvedValue({ items: [] }),
});
const catalogApi = catalogServiceMock();
jest.spyOn(catalogApi, 'getEntities');
it('adds kind to filter when missing', async () => {
const context = CatalogAuthResolverContext.create({