Refactor to fix tests and added an extra empty scenario
This commit is contained in:
parent
a1fdff8df8
commit
5498cc86bd
|
@ -212,6 +212,7 @@ describe("/rows", () => {
|
||||||
attachmentNull: attachment,
|
attachmentNull: attachment,
|
||||||
attachmentUndefined: attachment,
|
attachmentUndefined: attachment,
|
||||||
attachmentEmpty: attachment,
|
attachmentEmpty: attachment,
|
||||||
|
attachmentEmptyArrayStr: attachment
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -239,6 +240,7 @@ describe("/rows", () => {
|
||||||
attachmentNull: null,
|
attachmentNull: null,
|
||||||
attachmentUndefined: undefined,
|
attachmentUndefined: undefined,
|
||||||
attachmentEmpty: "",
|
attachmentEmpty: "",
|
||||||
|
attachmentEmptyArrayStr: "[]",
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = (await config.createRow(row))._id
|
const id = (await config.createRow(row))._id
|
||||||
|
@ -268,6 +270,7 @@ describe("/rows", () => {
|
||||||
expect(saved.attachmentNull).toEqual([])
|
expect(saved.attachmentNull).toEqual([])
|
||||||
expect(saved.attachmentUndefined).toBe(undefined)
|
expect(saved.attachmentUndefined).toBe(undefined)
|
||||||
expect(saved.attachmentEmpty).toEqual([])
|
expect(saved.attachmentEmpty).toEqual([])
|
||||||
|
expect(saved.attachmentEmptyArrayStr).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -67,12 +67,14 @@ export const TYPE_TRANSFORM_MAP: any = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[FieldTypes.ATTACHMENT]: {
|
[FieldTypes.ATTACHMENT]: {
|
||||||
"": [],
|
|
||||||
[null]: [],
|
[null]: [],
|
||||||
[undefined]: undefined,
|
[undefined]: undefined,
|
||||||
parse: attachments => {
|
parse: attachments => {
|
||||||
if (typeof attachments === "string") {
|
if (typeof attachments === "string") {
|
||||||
let result = attachments
|
if (attachments === "") {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
let result
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(attachments)
|
result = JSON.parse(attachments)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -80,6 +82,7 @@ export const TYPE_TRANSFORM_MAP: any = {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
return attachments
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[FieldTypes.BOOLEAN]: {
|
[FieldTypes.BOOLEAN]: {
|
||||||
|
|
Loading…
Reference in New Issue