1
0
Fork 0
mirror of synced 2024-07-08 15:56:23 +12:00
budibase/packages/common/test/getNewRecord.spec.js
2020-04-15 15:24:24 +01:00

33 lines
1.1 KiB
JavaScript

import { testSchema } from "./testSchema.mjs"
import { isNonEmptyString } from "../src/common"
import { getNewRecord } from "../src/records/getNewRecord.mjs"
describe("getNewRecord", () => {
it("should get object with generated id and key (full path)", async () => {
const schema = testSchema()
const record = getNewRecord(schema, "Contact")
expect(record._id).toBeDefined()
expect(isNonEmptyString(record._id)).toBeTruthy()
expect(record._rev).not.toBeDefined()
expect(record._modelId).toBe(schema.findModel("Contact").id)
})
it("should create object with all declared fields, using default values", async () => {
const schema = testSchema()
const contact = getNewRecord(schema, "Contact")
expect(contact.Name).toBe(null)
expect(contact.Created).toBe(null)
expect(contact["Is Active"]).toBe(null)
})
it("should create object with all declared fields, and use inital values", async () => {
const schema = testSchema()
schema.findField("Contact", "Name").getInitialValue = "Default Name"
const contact = getNewRecord(schema, "Contact")
expect(contact.Name).toBe("Default Name")
})
})