isolated VM test cases.
This commit is contained in:
parent
c52b6aa0d1
commit
335228e878
|
@ -30,4 +30,57 @@ describe("Test isolated vm directly", () => {
|
||||||
})
|
})
|
||||||
expect(result).toBe("<p>dddd</p>\n")
|
expect(result).toBe("<p>dddd</p>\n")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("handle a mapping case", async () => {
|
||||||
|
const context = {
|
||||||
|
data: {
|
||||||
|
data: {
|
||||||
|
searchProducts: {
|
||||||
|
results: [
|
||||||
|
{ imageLinks: ["_S/"] }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const result = await compare(`
|
||||||
|
const dataUnnested = data.data.searchProducts.results
|
||||||
|
const emptyLink = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRRC3hpq0MXqXssA28Lm5NrzcOYAyr--q3xyg&usqp=CAU"
|
||||||
|
let pImage = emptyLink
|
||||||
|
let sImage = emptyLink
|
||||||
|
let uImage = emptyLink
|
||||||
|
let lImage = emptyLink
|
||||||
|
let b1Image = emptyLink
|
||||||
|
let b2Image = emptyLink
|
||||||
|
|
||||||
|
const dataTransformed = dataUnnested.map(x=> {
|
||||||
|
let imageLinks = x.imageLinks
|
||||||
|
for (let i = 0; i < imageLinks.length; i++){
|
||||||
|
if(imageLinks[i].includes("_P/") || imageLinks[i].includes("_p/")){
|
||||||
|
pImage = imageLinks[i]
|
||||||
|
} else if (imageLinks[i].includes("_S/") || imageLinks[i].includes("_s/")){
|
||||||
|
sImage = imageLinks[i]
|
||||||
|
} else if (imageLinks[i].includes("_U/") || imageLinks[i].includes("_u/")){
|
||||||
|
uImage = imageLinks[i]
|
||||||
|
} else if (imageLinks[i].includes("_L/") || imageLinks[i].includes("_l/")){
|
||||||
|
lImage = imageLinks[i]
|
||||||
|
} else if (imageLinks[i].includes("_B/") || imageLinks[i].includes("_b/")){
|
||||||
|
b1Image = imageLinks[i]
|
||||||
|
} else if (imageLinks[i].includes("_B2/") || imageLinks[i].includes("_b2/")){
|
||||||
|
b2Image = imageLinks[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const arrangedLinks = [pImage, sImage, uImage, lImage, b1Image, b2Image]
|
||||||
|
x.imageLinks = arrangedLinks
|
||||||
|
|
||||||
|
return x
|
||||||
|
})
|
||||||
|
|
||||||
|
return dataTransformed
|
||||||
|
`, context)
|
||||||
|
expect(result).toBeDefined()
|
||||||
|
expect(result.length).toBe(1)
|
||||||
|
expect(result[0].imageLinks.length).toBe(6)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -144,5 +144,26 @@ describe("jsRunner (using isolated-vm)", () => {
|
||||||
expect(result).toBeDefined()
|
expect(result).toBeDefined()
|
||||||
expect(result).toBe(3)
|
expect(result).toBe(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle test case 4", async () => {
|
||||||
|
const context = {
|
||||||
|
"Time Sheets": ["a", "b"]
|
||||||
|
}
|
||||||
|
const result = await processJS(`
|
||||||
|
let hours = 0
|
||||||
|
if (($("[Time Sheets]") != null) == true){
|
||||||
|
for (i = 0; i < $("[Time Sheets]").length; i++){
|
||||||
|
let hoursLogged = "Time Sheets." + i + ".Hours"
|
||||||
|
hours += $(hoursLogged)
|
||||||
|
}
|
||||||
|
return hours
|
||||||
|
}
|
||||||
|
if (($("[Time Sheets]") != null) == false){
|
||||||
|
return hours
|
||||||
|
}
|
||||||
|
`, context)
|
||||||
|
expect(result).toBeDefined()
|
||||||
|
expect(result).toBe("0ab")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue