From 5731b260791e06b66ee1afcdae923b3a94e7f463 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 18 Jul 2023 10:30:15 +0200 Subject: [PATCH] Namespacing --- .../src/api/routes/tests/viewV2.spec.ts | 12 +++---- .../src/tests/utilities/TestConfiguration.ts | 35 ++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 31b843c597..3ae6445393 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -41,7 +41,7 @@ describe("/v2/views", () => { beforeAll(async () => { await config.createTable(priceTable()) for (let id = 0; id < 10; id++) { - views.push(await config.createViewV2()) + views.push(await config.api.viewV2.create()) } }) @@ -62,7 +62,7 @@ describe("/v2/views", () => { const newTable = await config.createTable(priceTable()) const newViews = [] for (let id = 0; id < 5; id++) { - newViews.push(await config.createViewV2({ tableId: newTable._id })) + newViews.push(await config.api.viewV2.create({ tableId: newTable._id })) } const res = await request @@ -100,7 +100,7 @@ describe("/v2/views", () => { let view: ViewV2 beforeAll(async () => { - view = await config.createViewV2() + view = await config.api.viewV2.create() }) it("can fetch the expected view", async () => { @@ -151,18 +151,18 @@ describe("/v2/views", () => { beforeAll(async () => { await config.createTable(priceTable()) - view = await config.createViewV2() + view = await config.api.viewV2.create() }) it("can delete an existing view", async () => { - await config.getViewV2(view._id!).expect(200) + await config.api.viewV2.get(view._id!).expect(200) await request .delete(`/api/v2/views/${view._id}`) .set(config.defaultHeaders()) .expect(204) - await config.getViewV2(view._id!).expect(404) + await config.api.viewV2.get(view._id!).expect(404) }) }) }) diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 0ff3cf2fdf..e4f3cf31d1 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -635,22 +635,25 @@ class TestConfiguration { return this._req(view, null, controllers.view.v1.save) } - async createViewV2(config?: Partial) { - if (!this.table) { - throw "Test requires table to be configured." - } - const view = { - tableId: this.table._id, - name: generator.guid(), - ...config, - } - return this._req(view, null, controllers.view.v2.save) - } - - getViewV2(viewId: string): supertest.Test { - return this.request!.get(`/api/v2/views/${viewId}`) - .set(this.defaultHeaders()) - .expect("Content-Type", /json/) + api = { + viewV2: { + create: async (config?: Partial) => { + if (!this.table) { + throw "Test requires table to be configured." + } + const view = { + tableId: this.table._id, + name: generator.guid(), + ...config, + } + return this._req(view, null, controllers.view.v2.save) + }, + get: (viewId: string): supertest.Test => { + return this.request!.get(`/api/v2/views/${viewId}`) + .set(this.defaultHeaders()) + .expect("Content-Type", /json/) + }, + }, } // AUTOMATION