Add in signature field testing support. Some signature fixes

This commit is contained in:
Dean 2024-04-08 12:18:05 +01:00
parent 7106689ebd
commit 9b276aa3c1
4 changed files with 98 additions and 28 deletions

View File

@ -237,6 +237,11 @@ describe.each([
name: "attachment",
constraints: { type: "array", presence: false },
}
const signature: FieldSchema = {
type: FieldType.SIGNATURE,
name: "signature",
constraints: { type: "array", presence: false },
}
const bool: FieldSchema = {
type: FieldType.BOOLEAN,
name: "boolean",
@ -301,6 +306,10 @@ describe.each([
attachmentUndefined: attachment,
attachmentEmpty: attachment,
attachmentEmptyArrayStr: attachment,
signatureNull: signature,
signatureUndefined: signature,
signatureEmpty: signature,
signatureEmptyArrayStr: signature,
arrayFieldEmptyArrayStr: arrayField,
arrayFieldArrayStrKnown: arrayField,
arrayFieldNull: arrayField,
@ -340,6 +349,10 @@ describe.each([
attachmentUndefined: undefined,
attachmentEmpty: "",
attachmentEmptyArrayStr: "[]",
signatureNull: null,
signatureUndefined: undefined,
signatureEmpty: "",
signatureEmptyArrayStr: "[]",
arrayFieldEmptyArrayStr: "[]",
arrayFieldUndefined: undefined,
arrayFieldNull: null,
@ -372,6 +385,10 @@ describe.each([
expect(row.attachmentUndefined).toBe(undefined)
expect(row.attachmentEmpty).toEqual([])
expect(row.attachmentEmptyArrayStr).toEqual([])
expect(row.signatureNull).toEqual([])
expect(row.signatureUndefined).toBe(undefined)
expect(row.signatureEmpty).toEqual([])
expect(row.signatureEmptyArrayStr).toEqual([])
expect(row.arrayFieldEmptyArrayStr).toEqual([])
expect(row.arrayFieldNull).toEqual([])
expect(row.arrayFieldUndefined).toEqual(undefined)
@ -783,24 +800,21 @@ describe.each([
})
isInternal &&
describe("attachments", () => {
it("should allow enriching attachment rows", async () => {
describe("attachments and signatures", () => {
const coreAttachmentEnrichment = async (
schema: any,
field: string,
attachmentId: string
) => {
const table = await config.api.table.save(
defaultTable({
schema: {
attachment: {
type: FieldType.ATTACHMENT,
name: "attachment",
constraints: { type: "array", presence: false },
},
},
schema,
})
)
const attachmentId = `${uuid.v4()}.csv`
const row = await config.api.row.save(table._id!, {
name: "test",
description: "test",
attachment: [
[field]: [
{
key: `${config.getAppId()}/attachments/${attachmentId}`,
},
@ -810,11 +824,39 @@ describe.each([
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[0].url).toBe(
expect((enriched as Row[])[0]?.[field][0].url).toBe(
`/files/signed/prod-budi-app-assets/${config.getProdAppId()}/attachments/${attachmentId}`
)
})
})
}
it("should allow enriching attachment rows", async () => {
coreAttachmentEnrichment(
{
attachment: {
type: FieldType.ATTACHMENT,
name: "attachment",
constraints: { type: "array", presence: false },
},
},
"attachment",
`${uuid.v4()}.csv`
)
})
it("should allow enriching signature rows", async () => {
coreAttachmentEnrichment(
{
signature: {
type: FieldType.SIGNATURE,
name: "signature",
constraints: { type: "array", presence: false },
},
},
"signature",
`${uuid.v4()}.png`
)
})
})

View File

@ -30,7 +30,10 @@ export async function getRowsWithAttachments(appId: string, table: Table) {
const db = dbCore.getDB(appId)
const attachmentCols: string[] = []
for (let [key, column] of Object.entries(table.schema)) {
if (column.type === FieldType.ATTACHMENT) {
if (
column.type === FieldType.ATTACHMENT ||
column.type === FieldType.SIGNATURE
) {
attachmentCols.push(key)
}
}

View File

@ -23,27 +23,18 @@ describe("should be able to re-write attachment URLs", () => {
await config.init()
})
it("should update URLs on a number of rows over the limit", async () => {
const coreBehaviour = async (tblSchema: any, field: string) => {
const table = await config.api.table.save({
name: "photos",
type: "table",
sourceId: INTERNAL_TABLE_SOURCE_ID,
sourceType: TableSourceType.INTERNAL,
schema: {
photo: {
type: FieldType.ATTACHMENT,
name: "photo",
},
otherCol: {
type: FieldType.STRING,
name: "otherCol",
},
},
schema: tblSchema,
})
for (let i = 0; i < FIND_LIMIT * 4; i++) {
await config.api.row.save(table._id!, {
photo: [attachment],
[field]: [attachment],
otherCol: "string",
})
}
@ -56,8 +47,39 @@ describe("should be able to re-write attachment URLs", () => {
)
for (const row of rows) {
expect(row.otherCol).toBe("string")
expect(row.photo[0].url).toBe("")
expect(row.photo[0].key).toBe(`${db.name}/attachments/a.png`)
expect(row[field][0].url).toBe("")
expect(row[field][0].key).toBe(`${db.name}/attachments/a.png`)
}
}
it("Attachment field, should update URLs on a number of rows over the limit", async () => {
await coreBehaviour(
{
photo: {
type: FieldType.ATTACHMENT,
name: "photo",
},
otherCol: {
type: FieldType.STRING,
name: "otherCol",
},
},
"photo"
)
})
it("Signature field, should update URLs on a number of rows over the limit", async () => {
await coreBehaviour(
{
signature: {
type: FieldType.SIGNATURE,
name: "signature",
},
otherCol: {
type: FieldType.STRING,
name: "otherCol",
},
},
"signature"
)
})
})

View File

@ -95,7 +95,10 @@ export class AttachmentCleanup {
return AttachmentCleanup.coreCleanup(() => {
let files: string[] = []
for (let [key, schema] of Object.entries(table.schema)) {
if (schema.type !== FieldType.ATTACHMENT) {
if (
schema.type !== FieldType.ATTACHMENT &&
schema.type !== FieldType.SIGNATURE
) {
continue
}
const oldKeys =