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