1
0
Fork 0
mirror of synced 2024-08-15 18:11:40 +12:00

Namespacing

This commit is contained in:
Adria Navarro 2023-07-18 10:30:15 +02:00
parent f7452aa7fa
commit 5731b26079
2 changed files with 25 additions and 22 deletions

View file

@ -41,7 +41,7 @@ describe("/v2/views", () => {
beforeAll(async () => { beforeAll(async () => {
await config.createTable(priceTable()) await config.createTable(priceTable())
for (let id = 0; id < 10; id++) { 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 newTable = await config.createTable(priceTable())
const newViews = [] const newViews = []
for (let id = 0; id < 5; id++) { 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 const res = await request
@ -100,7 +100,7 @@ describe("/v2/views", () => {
let view: ViewV2 let view: ViewV2
beforeAll(async () => { beforeAll(async () => {
view = await config.createViewV2() view = await config.api.viewV2.create()
}) })
it("can fetch the expected view", async () => { it("can fetch the expected view", async () => {
@ -151,18 +151,18 @@ describe("/v2/views", () => {
beforeAll(async () => { beforeAll(async () => {
await config.createTable(priceTable()) await config.createTable(priceTable())
view = await config.createViewV2() view = await config.api.viewV2.create()
}) })
it("can delete an existing view", async () => { 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 await request
.delete(`/api/v2/views/${view._id}`) .delete(`/api/v2/views/${view._id}`)
.set(config.defaultHeaders()) .set(config.defaultHeaders())
.expect(204) .expect(204)
await config.getViewV2(view._id!).expect(404) await config.api.viewV2.get(view._id!).expect(404)
}) })
}) })
}) })

View file

@ -635,22 +635,25 @@ class TestConfiguration {
return this._req(view, null, controllers.view.v1.save) return this._req(view, null, controllers.view.v1.save)
} }
async createViewV2(config?: Partial<ViewV2>) { api = {
if (!this.table) { viewV2: {
throw "Test requires table to be configured." create: async (config?: Partial<ViewV2>) => {
} if (!this.table) {
const view = { throw "Test requires table to be configured."
tableId: this.table._id, }
name: generator.guid(), const view = {
...config, tableId: this.table._id,
} name: generator.guid(),
return this._req(view, null, controllers.view.v2.save) ...config,
} }
return this._req(view, null, controllers.view.v2.save)
getViewV2(viewId: string): supertest.Test { },
return this.request!.get(`/api/v2/views/${viewId}`) get: (viewId: string): supertest.Test => {
.set(this.defaultHeaders()) return this.request!.get(`/api/v2/views/${viewId}`)
.expect("Content-Type", /json/) .set(this.defaultHeaders())
.expect("Content-Type", /json/)
},
},
} }
// AUTOMATION // AUTOMATION