From ea6af512694bbc167377237ba44d28f989b28cc5 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 4 May 2021 16:28:39 +0200 Subject: [PATCH] chore: cleanups Co-authored-by: Ben Lambert Signed-off-by: Johan Haals --- .../src/next/DefaultLocationStore.test.ts | 11 ++---- .../src/next/DefaultLocationStore.ts | 34 +++++++++---------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/plugins/catalog-backend/src/next/DefaultLocationStore.test.ts b/plugins/catalog-backend/src/next/DefaultLocationStore.test.ts index 5a9da22287..88806d0ace 100644 --- a/plugins/catalog-backend/src/next/DefaultLocationStore.test.ts +++ b/plugins/catalog-backend/src/next/DefaultLocationStore.test.ts @@ -14,24 +14,17 @@ * limitations under the License. */ import { v4 as uuid } from 'uuid'; -import { BackgroundContext, Context, TransactionValue } from './Context'; import { DatabaseManager } from './database/DatabaseManager'; import { DefaultLocationStore } from './DefaultLocationStore'; const createLocationStore = async () => { const knex = await DatabaseManager.createTestDatabaseConnection(); - const db = await DatabaseManager.createDatabase(knex); + await DatabaseManager.createDatabase(knex); const connection = { applyMutation: jest.fn() }; const store = new DefaultLocationStore(knex); await store.connect(connection); - const withContext = async (handler: (ctx: Context) => Promise) => { - return await db.transaction(async tx => { - const ctx = TransactionValue.in(new BackgroundContext(), tx as any); - return await handler(ctx); - }); - }; - return { store, connection, db, withContext }; + return { store, connection }; }; describe('DefaultLocationStore', () => { diff --git a/plugins/catalog-backend/src/next/DefaultLocationStore.ts b/plugins/catalog-backend/src/next/DefaultLocationStore.ts index 116ccb2c8e..fe1eb30467 100644 --- a/plugins/catalog-backend/src/next/DefaultLocationStore.ts +++ b/plugins/catalog-backend/src/next/DefaultLocationStore.ts @@ -76,22 +76,7 @@ export class DefaultLocationStore implements LocationStore, EntityProvider { } async listLocations(): Promise { - return await this.locations(this.db); - } - - private async locations(dbOrTx: Knex | Knex.Transaction) { - const locations = await dbOrTx('locations').select(); - return ( - locations - // TODO(blam): We should create a mutation to remove this location for everyone - // eventually when it's all done and dusted - .filter(({ type }) => type !== 'bootstrap') - .map(item => ({ - id: item.id, - target: item.target, - type: item.type, - })) - ); + return await this.locations(); } async getLocation(id: string): Promise { @@ -141,7 +126,7 @@ export class DefaultLocationStore implements LocationStore, EntityProvider { async connect(connection: EntityProviderConnection): Promise { this._connection = connection; - const locations = await this.locations(this.db); + const locations = await this.locations(); const entities = locations.map(location => { return locationSpecToLocationEntity(location); @@ -152,4 +137,19 @@ export class DefaultLocationStore implements LocationStore, EntityProvider { entities, }); } + + private async locations(dbOrTx: Knex.Transaction | Knex = this.db) { + const locations = await dbOrTx('locations').select(); + return ( + locations + // TODO(blam): We should create a mutation to remove this location for everyone + // eventually when it's all done and dusted + .filter(({ type }) => type !== 'bootstrap') + .map(item => ({ + id: item.id, + target: item.target, + type: item.type, + })) + ); + } }