Skip to content

Commit

Permalink
chore: refactor tests a little bit
Browse files Browse the repository at this point in the history
Signed-off-by: blam <[email protected]>
  • Loading branch information
benjdlambert committed Jan 16, 2025
1 parent ad39179 commit 67bf279
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions plugins/catalog-backend/src/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ class TestHarness {
readonly #catalog: EntitiesCatalog;
readonly #engine: CatalogProcessingEngine;
readonly #refresh: RefreshService;
readonly #providers: TestProvider[];
readonly #provider: TestProvider;
readonly #proxyProgressTracker: ProxyProgressTracker;

static async create(options?: {
disableRelationsCompatibility?: boolean;
logger?: LoggerService;
db?: Knex;
permissions?: PermissionEvaluator;
providers?: TestProvider[];
additionalProviders?: EntityProvider[];
processEntity?(
entity: Entity,
location: LocationSpec,
Expand Down Expand Up @@ -302,7 +302,13 @@ class TestHarness {

const refresh = new DefaultRefreshService({ database: catalogDatabase });

const providers = options?.providers ?? [new TestProvider()];
const provider = new TestProvider();
const providers: EntityProvider[] = [provider];

if (options?.additionalProviders) {
providers.push(...options.additionalProviders);
}

await connectEntityProviders(providerDatabase, providers);

return new TestHarness(
Expand All @@ -318,7 +324,7 @@ class TestHarness {
},
},
refresh,
providers,
provider,
proxyProgressTracker,
);
}
Expand All @@ -327,13 +333,13 @@ class TestHarness {
catalog: EntitiesCatalog,
engine: CatalogProcessingEngine,
refresh: RefreshService,
providers: TestProvider[],
provider: TestProvider,
proxyProgressTracker: ProxyProgressTracker,
) {
this.#catalog = catalog;
this.#engine = engine;
this.#refresh = refresh;
this.#providers = providers;
this.#provider = provider;
this.#proxyProgressTracker = proxyProgressTracker;
}

Expand All @@ -354,15 +360,13 @@ class TestHarness {
}

async setInputEntities(entities: (Entity & { locationKey?: string })[]) {
for (const provider of this.#providers) {
await provider.getConnection().applyMutation({
type: 'full',
entities: entities.map(({ locationKey, ...entity }) => ({
entity,
locationKey,
})),
});
}
await this.#provider.getConnection().applyMutation({
type: 'full',
entities: entities.map(({ locationKey, ...entity }) => ({
entity,
locationKey,
})),
});
}

async getOutputEntities(): Promise<Record<string, Entity>> {
Expand Down Expand Up @@ -856,7 +860,7 @@ describe('Catalog Backend Integration', () => {
secondProvider.getProviderName = () => 'second';

const harness = await TestHarness.create({
providers: [firstProvider, secondProvider],
additionalProviders: [firstProvider, secondProvider],
db,
});

Expand Down

0 comments on commit 67bf279

Please sign in to comment.