winsoroaks
winsoroaks8mo ago

is there a way to mock the ctx.db.system?

hi team! one of my mutation checks for the image size and store them in my table.
const metadata = await ctx.db.system.get(s.storageId as Id<"_storage">)
if (!metadata) throw new ConvexError("not found")
size += metadata.size
const metadata = await ctx.db.system.get(s.storageId as Id<"_storage">)
if (!metadata) throw new ConvexError("not found")
size += metadata.size
is there a way to handle this from the convex-test package? thanks!
5 Replies
winsoroaks
winsoroaksOP8mo ago
also the query does
ctx.storage.getUrl(
image.uploadedImageId as Id<"_storage">
)
ctx.storage.getUrl(
image.uploadedImageId as Id<"_storage">
)
can i somehow also mock the ctx.storage? or what's the best way to handle it? or maybe i should do
if (process.env.IS_TEST) return "fake"
if (process.env.IS_TEST) return "fake"
in the functions?
Michal Srb
Michal Srb8mo ago
GitHub
convex-test/convex/storage.test.ts at main · get-convex/convex-test
Testing harness for pure-JS Convex tests. Contribute to get-convex/convex-test development by creating an account on GitHub.
winsoroaks
winsoroaksOP8mo ago
got it. thanks! weird i copied and pasted
const storageId = await t.run(async (ctx) => {
const bytes = new Uint8Array([0b00001100, 0b00000000]).buffer;
return await ctx.storage.store(new Blob([bytes]));
});
const storageId = await t.run(async (ctx) => {
const bytes = new Uint8Array([0b00001100, 0b00000000]).buffer;
return await ctx.storage.store(new Blob([bytes]));
});
and im getting blob.arrayBuffer is not a function
Michal Srb
Michal Srb8mo ago
What's your Node.js version?
node -v
node -v
winsoroaks
winsoroaksOP8mo ago
node -v
v20.9.0
node -v
v20.9.0
lemme try upgrading nvm fixed, i just had to do
environment: "edge-runtime",
environment: "edge-runtime",
in my config sorry bout that. thanks!

Did you find this page helpful?