Add basic test

This commit is contained in:
Adria Navarro 2023-01-17 17:22:31 +00:00
parent 6412da730c
commit 89e0610600
6 changed files with 871 additions and 24 deletions

View File

@ -122,6 +122,7 @@
"@babel/core": "7.17.4", "@babel/core": "7.17.4",
"@babel/preset-env": "7.16.11", "@babel/preset-env": "7.16.11",
"@budibase/standard-components": "^0.9.139", "@budibase/standard-components": "^0.9.139",
"@faker-js/faker": "^7.6.0",
"@jest/test-sequencer": "24.9.0", "@jest/test-sequencer": "24.9.0",
"@swc/core": "^1.3.25", "@swc/core": "^1.3.25",
"@swc/jest": "^0.2.24", "@swc/jest": "^0.2.24",

View File

@ -0,0 +1,73 @@
import { faker } from "@faker-js/faker"
import {
generateMakeRequest,
MakeRequestResponse,
} from "../api/routes/public/tests/utils"
import * as setup from "../api/routes/tests/utilities"
import supertest from "supertest"
import { FieldType } from "@budibase/types"
const config = setup.getConfig()
let apiKey, table, app, makeRequest: MakeRequestResponse
beforeAll(async () => {
app = await config.init()
table = await config.updateTable()
apiKey = await config.generateApiKey()
makeRequest = generateMakeRequest(apiKey)
})
afterAll(async () => {
require("../app").default
await config.end()
})
describe("row api", () => {
let request: supertest.SuperTest<supertest.Test>
let server: any
beforeAll(() => {
server = require("../app").default
})
afterAll(() => {
server.close()
})
beforeEach(async () => {
request = supertest(server)
})
describe("create a row", () => {
test("Given than no row exists, adding a new rows persists it", async () => {
const tableName = faker.lorem.word()
let table = await config.createTable({
name: tableName,
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
description: {
name: "description",
type: FieldType.STRING,
},
value: {
name: "value",
type: FieldType.NUMBER,
},
},
})
const newRow = {
name: faker.name.fullName(),
description: faker.lorem.paragraphs(),
value: faker.random.numeric(),
}
const res = await makeRequest("post", `/tables/${table._id}/rows`, newRow)
expect(res.status).toBe(200)
})
})
})

View File

@ -1,13 +1,17 @@
import env from "../environment" import env from "../environment"
import { tmpdir } from "os" import { tmpdir } from "os"
env._set("SELF_HOSTED", "1") if (!env.isDockerisedTest()) {
env._set("NODE_ENV", "jest") env._set("SELF_HOSTED", "1")
env._set("JWT_SECRET", "test-jwtsecret") env._set("NODE_ENV", "jest")
env._set("CLIENT_ID", "test-client-id") env._set("JWT_SECRET", "test-jwtsecret")
env._set("BUDIBASE_DIR", tmpdir("budibase-unittests")) env._set("CLIENT_ID", "test-client-id")
env._set("LOG_LEVEL", "silent") env._set("BUDIBASE_DIR", tmpdir("budibase-unittests"))
env._set("PORT", 0) env._set("LOG_LEVEL", "silent")
env._set("MINIO_URL", "http://localhost") env._set("PORT")
env._set("MINIO_ACCESS_KEY", "test") env._set("MINIO_URL", "http://localhost")
env._set("MINIO_SECRET_KEY", "test") env._set("MINIO_ACCESS_KEY", "test")
env._set("MINIO_SECRET_KEY", "test")
} else {
env._set("DISABLE_AUTO_PROD_APP_SYNC", "TRUE")
}

View File

@ -39,6 +39,7 @@ import newid from "../../db/newid"
import { generateUserMetadataID } from "../../db/utils" import { generateUserMetadataID } from "../../db/utils"
import { startup } from "../../startup" import { startup } from "../../startup"
import supertest from "supertest" import supertest from "supertest"
import { Table } from "@budibase/types"
const GLOBAL_USER_ID = "us_uuid1" const GLOBAL_USER_ID = "us_uuid1"
const EMAIL = "babs@babs.com" const EMAIL = "babs@babs.com"
@ -418,7 +419,7 @@ class TestConfiguration {
return this.table return this.table
} }
async createTable(config?: any) { async createTable(config?: Table) {
if (config != null && config._id) { if (config != null && config._id) {
delete config._id delete config._id
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
import { Document } from "../document" import { Document } from "../document"
import { View } from "./view" import { View } from "./view"
import { RenameColumn } from "../../sdk" import { RenameColumn } from "../../sdk"
import { FieldType } from "./row"
export interface FieldSchema { export interface FieldSchema {
// TODO: replace with field types enum when done type: FieldType
type: string
externalType?: string externalType?: string
fieldName?: string fieldName?: string
name: string name: string