jas0nw01
jas0nw014mo ago

how to mock convex actions?

I'm trying to write tests for a function that uses AWS KMS decryption (fetchSomething). This function relies on internal.kms.decrypt action. I've tried several approaches but all attempts resulted in type errors or failed decryption. What's the correct way to mock an internal action in Convex tests? Example of what I'm trying to test:
export const fetchSomething = action({
args: {...},
handler: async (ctx, args) => {

// ... gets encrypted token ...
const decryptedToken = await ctx.runAction(
internal.kms.decrypt,
{ token: user.token }
)
// ... uses decrypted token ...

}
})
export const fetchSomething = action({
args: {...},
handler: async (ctx, args) => {

// ... gets encrypted token ...
const decryptedToken = await ctx.runAction(
internal.kms.decrypt,
{ token: user.token }
)
// ... uses decrypted token ...

}
})
4 Replies
Convex Bot
Convex Bot4mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
jamwt
jamwt4mo ago
hi! are you using convex-test ?
jas0nw01
jas0nw01OP4mo ago
hi jamie, yes i am! is there a function in convext-test that would help out with mocking the function that calls aws client?
erquhart
erquhart4mo ago
Haven’t tried but I’m wondering if there’s a way to get msw working here

Did you find this page helpful?