better generation, and letting tests run in isolation
This commit is contained in:
parent
fdbe429581
commit
e3dbc28dd5
|
@ -15,25 +15,16 @@ export default class RowApi {
|
||||||
this.api = apiClient
|
this.api = apiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
set appId(appId: string) {
|
|
||||||
this.headers = {
|
|
||||||
"x-budibase-app-id": appId,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(body: CreateRowParams): Promise<[Response, Row]> {
|
async create(body: CreateRowParams): Promise<[Response, Row]> {
|
||||||
const response = await this.api.post(`/tables/${this.tableId}/rows`, {
|
const response = await this.api.post(`/tables/${this.tableId}/rows`, {
|
||||||
body,
|
body,
|
||||||
headers: this.headers,
|
|
||||||
})
|
})
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
|
||||||
async read(id: string): Promise<[Response, Row]> {
|
async read(id: string): Promise<[Response, Row]> {
|
||||||
const response = await this.api.get(`/tables/${this.tableId}/rows/${id}`, {
|
const response = await this.api.get(`/tables/${this.tableId}/rows/${id}`)
|
||||||
headers: this.headers,
|
|
||||||
})
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
@ -41,7 +32,7 @@ export default class RowApi {
|
||||||
async search(body: SearchInputParams): Promise<[Response, Row]> {
|
async search(body: SearchInputParams): Promise<[Response, Row]> {
|
||||||
const response = await this.api.post(
|
const response = await this.api.post(
|
||||||
`/tables/${this.tableId}/rows/search`,
|
`/tables/${this.tableId}/rows/search`,
|
||||||
{ body, headers: this.headers }
|
{ body }
|
||||||
)
|
)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
|
@ -50,7 +41,6 @@ export default class RowApi {
|
||||||
async update(id: string, body: Row): Promise<[Response, Row]> {
|
async update(id: string, body: Row): Promise<[Response, Row]> {
|
||||||
const response = await this.api.put(`/tables/${this.tableId}/rows/${id}`, {
|
const response = await this.api.put(`/tables/${this.tableId}/rows/${id}`, {
|
||||||
body,
|
body,
|
||||||
headers: this.headers,
|
|
||||||
})
|
})
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
|
|
|
@ -19,43 +19,28 @@ export default class TableApi {
|
||||||
return this.create(generateTable())
|
return this.create(generateTable())
|
||||||
}
|
}
|
||||||
|
|
||||||
set appId(appId: string) {
|
|
||||||
this.headers = {
|
|
||||||
"x-budibase-app-id": appId,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(body: CreateTableParams): Promise<[Response, Table]> {
|
async create(body: CreateTableParams): Promise<[Response, Table]> {
|
||||||
const response = await this.api.post(`/tables`, {
|
const response = await this.api.post(`/tables`, {
|
||||||
body,
|
body,
|
||||||
headers: this.headers,
|
|
||||||
})
|
})
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
|
||||||
async read(id: string): Promise<[Response, Table]> {
|
async read(id: string): Promise<[Response, Table]> {
|
||||||
const response = await this.api.get(`/tables/${id}`, {
|
const response = await this.api.get(`/tables/${id}`)
|
||||||
headers: this.headers,
|
|
||||||
})
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(body: SearchInputParams): Promise<[Response, Table]> {
|
async search(body: SearchInputParams): Promise<[Response, Table]> {
|
||||||
const response = await this.api.post(`/tables/search`, {
|
const response = await this.api.post(`/tables/search`, { body })
|
||||||
body,
|
|
||||||
headers: this.headers,
|
|
||||||
})
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, body: Table): Promise<[Response, Table]> {
|
async update(id: string, body: Table): Promise<[Response, Table]> {
|
||||||
const response = await this.api.put(`/tables/${id}`, {
|
const response = await this.api.put(`/tables/${id}`, { body })
|
||||||
body,
|
|
||||||
headers: this.headers,
|
|
||||||
})
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json.data]
|
return [response, json.data]
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
User,
|
User,
|
||||||
} from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
} from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
|
import generateUser from "../fixtures/users"
|
||||||
|
|
||||||
export default class UserApi {
|
export default class UserApi {
|
||||||
api: PublicAPIClient
|
api: PublicAPIClient
|
||||||
|
@ -13,7 +14,9 @@ export default class UserApi {
|
||||||
this.api = apiClient
|
this.api = apiClient
|
||||||
}
|
}
|
||||||
|
|
||||||
async seed() {}
|
async seed() {
|
||||||
|
return this.create(generateUser())
|
||||||
|
}
|
||||||
|
|
||||||
async create(body: CreateUserParams): Promise<[Response, User]> {
|
async create(body: CreateUserParams): Promise<[Response, User]> {
|
||||||
const response = await this.api.post(`/users`, { body })
|
const response = await this.api.post(`/users`, { body })
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import generator from "../TestConfiguration/generator"
|
import generator from "../TestConfiguration/generator"
|
||||||
import { CreateApplicationParams } from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
import {
|
||||||
|
Application,
|
||||||
|
CreateApplicationParams,
|
||||||
|
} from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
||||||
|
|
||||||
const generate = (overrides = {}): CreateApplicationParams => ({
|
const generate = (
|
||||||
|
overrides: Partial<Application> = {}
|
||||||
|
): CreateApplicationParams => ({
|
||||||
name: generator.word(),
|
name: generator.word(),
|
||||||
url: `/${generator.word()}`,
|
url: `/${generator.word()}`,
|
||||||
...overrides,
|
...overrides,
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import {
|
import {
|
||||||
CreateRowParams,
|
CreateRowParams,
|
||||||
CreateTableParams,
|
CreateTableParams,
|
||||||
|
Row,
|
||||||
|
Table,
|
||||||
} from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
} from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
||||||
import generator from "../TestConfiguration/generator"
|
import generator from "../TestConfiguration/generator"
|
||||||
|
|
||||||
export const generateTable = (overrides = {}): CreateTableParams => ({
|
export const generateTable = (
|
||||||
|
overrides: Partial<Table> = {}
|
||||||
|
): CreateTableParams => ({
|
||||||
name: generator.word(),
|
name: generator.word(),
|
||||||
primaryDisplay: "sasa",
|
primaryDisplay: "sasa",
|
||||||
schema: {
|
schema: {
|
||||||
|
@ -20,7 +24,7 @@ export const generateTable = (overrides = {}): CreateTableParams => ({
|
||||||
},
|
},
|
||||||
"Created By": {
|
"Created By": {
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
fieldName: "test12-Created By",
|
fieldName: generator.word(),
|
||||||
name: "Created By",
|
name: "Created By",
|
||||||
relationshipType: "many-to-many",
|
relationshipType: "many-to-many",
|
||||||
tableId: "ta_users",
|
tableId: "ta_users",
|
||||||
|
@ -37,7 +41,7 @@ export const generateTable = (overrides = {}): CreateTableParams => ({
|
||||||
},
|
},
|
||||||
"Updated By": {
|
"Updated By": {
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
fieldName: "test12-Updated By",
|
fieldName: generator.word(),
|
||||||
name: "Updated By",
|
name: "Updated By",
|
||||||
relationshipType: "many-to-many",
|
relationshipType: "many-to-many",
|
||||||
tableId: "ta_users",
|
tableId: "ta_users",
|
||||||
|
@ -47,10 +51,10 @@ export const generateTable = (overrides = {}): CreateTableParams => ({
|
||||||
...overrides,
|
...overrides,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const generateRow = (overrides = {}): CreateRowParams => ({
|
export const generateRow = (overrides: Partial<Row> = {}): CreateRowParams => ({
|
||||||
type: "row",
|
type: "row",
|
||||||
tableId: "seed_table",
|
tableId: "seed_table",
|
||||||
sasa: "Mike",
|
sasa: generator.word(),
|
||||||
relationship: ["ro_ta_"],
|
relationship: [generator.string({ length: 32, alpha: true, numeric: true })],
|
||||||
...overrides,
|
...overrides,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { CreateUserParams } from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
import {
|
||||||
|
CreateUserParams,
|
||||||
|
User,
|
||||||
|
} from "../../../../../packages/server/src/api/controllers/public/mapping/types"
|
||||||
import generator from "../TestConfiguration/generator"
|
import generator from "../TestConfiguration/generator"
|
||||||
|
|
||||||
const generate = (overrides = {}): CreateUserParams => ({
|
const generate = (overrides: Partial<User> = {}): CreateUserParams => ({
|
||||||
email: generator.email(),
|
email: generator.email(),
|
||||||
roles: {
|
roles: {
|
||||||
[generator.string({ length: 32, alpha: true, numeric: true })]:
|
[generator.string({ length: 32, alpha: true, numeric: true })]:
|
||||||
|
|
|
@ -9,6 +9,8 @@ describe("Public API - /applications endpoints", () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.beforeAll()
|
await config.beforeAll()
|
||||||
|
const [response, app] = await config.applications.seed()
|
||||||
|
config.context = app
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -17,7 +19,6 @@ describe("Public API - /applications endpoints", () => {
|
||||||
|
|
||||||
it("POST - Create an application", async () => {
|
it("POST - Create an application", async () => {
|
||||||
const [response, app] = await config.applications.create(generateApp())
|
const [response, app] = await config.applications.create(generateApp())
|
||||||
config.context = app
|
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,14 @@ describe("Public API - /rows endpoints", () => {
|
||||||
await config.beforeAll()
|
await config.beforeAll()
|
||||||
const [appResp, app] = await config.applications.seed()
|
const [appResp, app] = await config.applications.seed()
|
||||||
|
|
||||||
config.tables.appId = app._id
|
config.tables.api.appId = app._id
|
||||||
const [tableResp, table] = await config.tables.seed()
|
config.rows.api.appId = app._id
|
||||||
|
|
||||||
config.rows.appId = app._id
|
const [tableResp, table] = await config.tables.seed()
|
||||||
config.rows.tableId = table._id
|
config.rows.tableId = table._id
|
||||||
|
|
||||||
|
const [response, row] = await config.rows.create(generateRow())
|
||||||
|
config.context = row
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -25,7 +28,6 @@ describe("Public API - /rows endpoints", () => {
|
||||||
|
|
||||||
it("POST - Create a row", async () => {
|
it("POST - Create a row", async () => {
|
||||||
const [response, row] = await config.rows.create(generateRow())
|
const [response, row] = await config.rows.create(generateRow())
|
||||||
config.context = row
|
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,11 @@ describe("Public API - /tables endpoints", () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.beforeAll()
|
await config.beforeAll()
|
||||||
const [_, app] = await config.applications.seed()
|
const [appResp, app] = await config.applications.seed()
|
||||||
config.tables.appId = app._id
|
config.tables.api.appId = app._id
|
||||||
|
|
||||||
|
const [tableResp, table] = await config.tables.seed()
|
||||||
|
config.context = table
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -19,7 +22,6 @@ describe("Public API - /tables endpoints", () => {
|
||||||
|
|
||||||
it("POST - Create a table", async () => {
|
it("POST - Create a table", async () => {
|
||||||
const [response, table] = await config.tables.create(generateTable())
|
const [response, table] = await config.tables.create(generateTable())
|
||||||
config.context = table
|
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ describe("Public API - /users endpoints", () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.beforeAll()
|
await config.beforeAll()
|
||||||
|
const [response, user] = await config.users.seed()
|
||||||
|
config.context = user
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -17,7 +19,6 @@ describe("Public API - /users endpoints", () => {
|
||||||
|
|
||||||
it("POST - Create a user", async () => {
|
it("POST - Create a user", async () => {
|
||||||
const [response, user] = await config.users.create(generateUser())
|
const [response, user] = await config.users.create(generateUser())
|
||||||
config.context = user
|
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue