Adding signature and attachment tests to external.

This commit is contained in:
mike12345567 2025-03-12 18:06:38 +00:00
parent 2384b0d73f
commit bca1ccd7e2
2 changed files with 80 additions and 80 deletions

View File

@ -481,6 +481,7 @@
FIELDS.BIGINT, FIELDS.BIGINT,
FIELDS.ATTACHMENT_SINGLE, FIELDS.ATTACHMENT_SINGLE,
FIELDS.ATTACHMENTS, FIELDS.ATTACHMENTS,
FIELDS.SIGNATURE_SINGLE,
] ]
// Filter out multiple users for google sheets // Filter out multiple users for google sheets

View File

@ -2195,95 +2195,94 @@ if (descriptions.length) {
}) })
}) })
isInternal && describe("attachments and signatures", () => {
describe("attachments and signatures", () => { const coreAttachmentEnrichment = async (
const coreAttachmentEnrichment = async ( schema: TableSchema,
schema: TableSchema, field: string,
field: string, attachmentCfg: string | string[]
attachmentCfg: string | string[] ) => {
) => { const testTable = await config.api.table.save(
const testTable = await config.api.table.save( defaultTable({
defaultTable({ schema,
schema,
})
)
const attachmentToStoreKey = (attachmentId: string) => {
return {
key: `${config.getAppId()}/attachments/${attachmentId}`,
}
}
const draftRow = {
name: "test",
description: "test",
[field]:
typeof attachmentCfg === "string"
? attachmentToStoreKey(attachmentCfg)
: attachmentCfg.map(attachmentToStoreKey),
tableId: testTable._id,
}
const row = await config.api.row.save(testTable._id!, draftRow)
await withEnv({ SELF_HOSTED: "true" }, async () => {
return context.doInAppContext(config.getAppId(), async () => {
const enriched: Row[] = await outputProcessing(testTable, [row])
const [targetRow] = enriched
const attachmentEntries = Array.isArray(targetRow[field])
? targetRow[field]
: [targetRow[field]]
for (const entry of attachmentEntries) {
const attachmentId = entry.key.split("/").pop()
expect(entry.url.split("?")[0]).toBe(
`/files/signed/prod-budi-app-assets/${config.getProdAppId()}/attachments/${attachmentId}`
)
}
})
}) })
)
const attachmentToStoreKey = (attachmentId: string) => {
return {
key: `${config.getAppId()}/attachments/${attachmentId}`,
}
} }
const draftRow = {
name: "test",
description: "test",
[field]:
typeof attachmentCfg === "string"
? attachmentToStoreKey(attachmentCfg)
: attachmentCfg.map(attachmentToStoreKey),
tableId: testTable._id,
}
const row = await config.api.row.save(testTable._id!, draftRow)
it("should allow enriching single attachment rows", async () => { await withEnv({ SELF_HOSTED: "true" }, async () => {
await coreAttachmentEnrichment( return context.doInAppContext(config.getAppId(), async () => {
{ const enriched: Row[] = await outputProcessing(testTable, [row])
attachment: { const [targetRow] = enriched
type: FieldType.ATTACHMENT_SINGLE, const attachmentEntries = Array.isArray(targetRow[field])
name: "attachment", ? targetRow[field]
constraints: { presence: false }, : [targetRow[field]]
},
},
"attachment",
`${uuid.v4()}.csv`
)
})
it("should allow enriching attachment list rows", async () => { for (const entry of attachmentEntries) {
await coreAttachmentEnrichment( const attachmentId = entry.key.split("/").pop()
{ expect(entry.url.split("?")[0]).toBe(
attachments: { `/files/signed/prod-budi-app-assets/${config.getProdAppId()}/attachments/${attachmentId}`
type: FieldType.ATTACHMENTS, )
name: "attachments", }
constraints: { type: "array", presence: false }, })
},
},
"attachments",
[`${uuid.v4()}.csv`]
)
}) })
}
it("should allow enriching signature rows", async () => { it("should allow enriching single attachment rows", async () => {
await coreAttachmentEnrichment( await coreAttachmentEnrichment(
{ {
signature: { attachment: {
type: FieldType.SIGNATURE_SINGLE, type: FieldType.ATTACHMENT_SINGLE,
name: "signature", name: "attachment",
constraints: { presence: false }, constraints: { presence: false },
},
}, },
"signature", },
`${uuid.v4()}.png` "attachment",
) `${uuid.v4()}.csv`
}) )
}) })
it("should allow enriching attachment list rows", async () => {
await coreAttachmentEnrichment(
{
attachments: {
type: FieldType.ATTACHMENTS,
name: "attachments",
constraints: { type: "array", presence: false },
},
},
"attachments",
[`${uuid.v4()}.csv`]
)
})
it("should allow enriching signature rows", async () => {
await coreAttachmentEnrichment(
{
signature: {
type: FieldType.SIGNATURE_SINGLE,
name: "signature",
constraints: { presence: false },
},
},
"signature",
`${uuid.v4()}.png`
)
})
})
describe("exportRows", () => { describe("exportRows", () => {
beforeEach(async () => { beforeEach(async () => {
table = await config.api.table.save(defaultTable()) table = await config.api.table.save(defaultTable())