Add attachment_single tests
This commit is contained in:
parent
28d10ec086
commit
e5843929f1
|
@ -6,14 +6,17 @@ import * as setup from "./utilities"
|
||||||
import { context, InternalTable, tenancy } from "@budibase/backend-core"
|
import { context, InternalTable, tenancy } from "@budibase/backend-core"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
|
AttachmentFieldMetadata,
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
Datasource,
|
Datasource,
|
||||||
|
DateFieldMetadata,
|
||||||
DeleteRow,
|
DeleteRow,
|
||||||
FieldSchema,
|
FieldSchema,
|
||||||
FieldType,
|
FieldType,
|
||||||
FieldTypeSubtypes,
|
FieldTypeSubtypes,
|
||||||
FormulaType,
|
FormulaType,
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
|
NumberFieldMetadata,
|
||||||
QuotaUsageType,
|
QuotaUsageType,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
Row,
|
Row,
|
||||||
|
@ -232,9 +235,14 @@ describe.each([
|
||||||
name: "str",
|
name: "str",
|
||||||
constraints: { type: "string", presence: false },
|
constraints: { type: "string", presence: false },
|
||||||
}
|
}
|
||||||
const attachment: FieldSchema = {
|
const singleAttachment: FieldSchema = {
|
||||||
|
type: FieldType.ATTACHMENT_SINGLE,
|
||||||
|
name: "single attachment",
|
||||||
|
constraints: { presence: false },
|
||||||
|
}
|
||||||
|
const attachmentList: AttachmentFieldMetadata = {
|
||||||
type: FieldType.ATTACHMENTS,
|
type: FieldType.ATTACHMENTS,
|
||||||
name: "attachment",
|
name: "attachments",
|
||||||
constraints: { type: "array", presence: false },
|
constraints: { type: "array", presence: false },
|
||||||
}
|
}
|
||||||
const bool: FieldSchema = {
|
const bool: FieldSchema = {
|
||||||
|
@ -242,12 +250,12 @@ describe.each([
|
||||||
name: "boolean",
|
name: "boolean",
|
||||||
constraints: { type: "boolean", presence: false },
|
constraints: { type: "boolean", presence: false },
|
||||||
}
|
}
|
||||||
const number: FieldSchema = {
|
const number: NumberFieldMetadata = {
|
||||||
type: FieldType.NUMBER,
|
type: FieldType.NUMBER,
|
||||||
name: "str",
|
name: "str",
|
||||||
constraints: { type: "number", presence: false },
|
constraints: { type: "number", presence: false },
|
||||||
}
|
}
|
||||||
const datetime: FieldSchema = {
|
const datetime: DateFieldMetadata = {
|
||||||
type: FieldType.DATETIME,
|
type: FieldType.DATETIME,
|
||||||
name: "datetime",
|
name: "datetime",
|
||||||
constraints: {
|
constraints: {
|
||||||
|
@ -297,10 +305,12 @@ describe.each([
|
||||||
boolUndefined: bool,
|
boolUndefined: bool,
|
||||||
boolString: bool,
|
boolString: bool,
|
||||||
boolBool: bool,
|
boolBool: bool,
|
||||||
attachmentNull: attachment,
|
singleAttachmentNull: singleAttachment,
|
||||||
attachmentUndefined: attachment,
|
singleAttachmentUndefined: singleAttachment,
|
||||||
attachmentEmpty: attachment,
|
attachmentListNull: attachmentList,
|
||||||
attachmentEmptyArrayStr: attachment,
|
attachmentListUndefined: attachmentList,
|
||||||
|
attachmentListEmpty: attachmentList,
|
||||||
|
attachmentListEmptyArrayStr: attachmentList,
|
||||||
arrayFieldEmptyArrayStr: arrayField,
|
arrayFieldEmptyArrayStr: arrayField,
|
||||||
arrayFieldArrayStrKnown: arrayField,
|
arrayFieldArrayStrKnown: arrayField,
|
||||||
arrayFieldNull: arrayField,
|
arrayFieldNull: arrayField,
|
||||||
|
@ -336,10 +346,12 @@ describe.each([
|
||||||
boolString: "true",
|
boolString: "true",
|
||||||
boolBool: true,
|
boolBool: true,
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
attachmentNull: null,
|
singleAttachmentNull: null,
|
||||||
attachmentUndefined: undefined,
|
singleAttachmentUndefined: undefined,
|
||||||
attachmentEmpty: "",
|
attachmentListNull: null,
|
||||||
attachmentEmptyArrayStr: "[]",
|
attachmentListUndefined: undefined,
|
||||||
|
attachmentListEmpty: "",
|
||||||
|
attachmentListEmptyArrayStr: "[]",
|
||||||
arrayFieldEmptyArrayStr: "[]",
|
arrayFieldEmptyArrayStr: "[]",
|
||||||
arrayFieldUndefined: undefined,
|
arrayFieldUndefined: undefined,
|
||||||
arrayFieldNull: null,
|
arrayFieldNull: null,
|
||||||
|
@ -368,10 +380,12 @@ describe.each([
|
||||||
expect(row.boolUndefined).toBe(undefined)
|
expect(row.boolUndefined).toBe(undefined)
|
||||||
expect(row.boolString).toBe(true)
|
expect(row.boolString).toBe(true)
|
||||||
expect(row.boolBool).toBe(true)
|
expect(row.boolBool).toBe(true)
|
||||||
expect(row.attachmentNull).toEqual([])
|
expect(row.singleAttachmentNull).toEqual(null)
|
||||||
expect(row.attachmentUndefined).toBe(undefined)
|
expect(row.singleAttachmentUndefined).toBe(undefined)
|
||||||
expect(row.attachmentEmpty).toEqual([])
|
expect(row.attachmentListNull).toEqual([])
|
||||||
expect(row.attachmentEmptyArrayStr).toEqual([])
|
expect(row.attachmentListUndefined).toBe(undefined)
|
||||||
|
expect(row.attachmentListEmpty).toEqual([])
|
||||||
|
expect(row.attachmentListEmptyArrayStr).toEqual([])
|
||||||
expect(row.arrayFieldEmptyArrayStr).toEqual([])
|
expect(row.arrayFieldEmptyArrayStr).toEqual([])
|
||||||
expect(row.arrayFieldNull).toEqual([])
|
expect(row.arrayFieldNull).toEqual([])
|
||||||
expect(row.arrayFieldUndefined).toEqual(undefined)
|
expect(row.arrayFieldUndefined).toEqual(undefined)
|
||||||
|
@ -784,7 +798,39 @@ describe.each([
|
||||||
|
|
||||||
isInternal &&
|
isInternal &&
|
||||||
describe("attachments", () => {
|
describe("attachments", () => {
|
||||||
it("should allow enriching attachment rows", async () => {
|
it("should allow enriching single attachment rows", async () => {
|
||||||
|
const table = await config.api.table.save(
|
||||||
|
defaultTable({
|
||||||
|
schema: {
|
||||||
|
attachment: {
|
||||||
|
type: FieldType.ATTACHMENT_SINGLE,
|
||||||
|
name: "attachment",
|
||||||
|
constraints: { presence: false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
const attachmentId = `${uuid.v4()}.csv`
|
||||||
|
const row = await config.api.row.save(table._id!, {
|
||||||
|
name: "test",
|
||||||
|
description: "test",
|
||||||
|
attachment: {
|
||||||
|
key: `${config.getAppId()}/attachments/${attachmentId}`,
|
||||||
|
},
|
||||||
|
|
||||||
|
tableId: table._id,
|
||||||
|
})
|
||||||
|
await config.withEnv({ SELF_HOSTED: "true" }, async () => {
|
||||||
|
return context.doInAppContext(config.getAppId(), async () => {
|
||||||
|
const enriched = await outputProcessing(table, [row])
|
||||||
|
expect((enriched as Row[])[0].attachment.url).toBe(
|
||||||
|
`/files/signed/prod-budi-app-assets/${config.getProdAppId()}/attachments/${attachmentId}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should allow enriching attachment list rows", async () => {
|
||||||
const table = await config.api.table.save(
|
const table = await config.api.table.save(
|
||||||
defaultTable({
|
defaultTable({
|
||||||
schema: {
|
schema: {
|
||||||
|
|
Loading…
Reference in New Issue