how to write unit test case of this durable function. it is calling through app and df, so it does not have any function. how can i call the trigger and orchestrator? Here is my code
const { app } = require('@azure/functions');
const df = require('durable-functions');
const { autoDeleteBackUpActivity, autoDeleteBackUpDeterminer } = require('../activity/autoDeleteBackUpActivity');
df.app.orchestration('AutoDeleteBackupOrchestrator', function* (context) {
const backupDatabasesToBeRemoved = yield context.df.callActivity('AutoDeleteBackUpDeterminer');
const parallelTasks = [];
for (const backupDatabase of backupDatabasesToBeRemoved) {
parallelTasks.push(
context.df.callActivity(
'AutoDeleteBackUpActivity',
backupDatabase
)
);
}
if (parallelTasks.length > 0) {
yield context.df.Task.all(parallelTasks);
}
});
df.app.activity('AutoDeleteBackUpDeterminer', {
handler: autoDeleteBackUpDeterminer
});
df.app.activity('AutoDeleteBackUpActivity', {
handler: autoDeleteBackUpActivity
});
app.timer('AutoDeleteBackupTimerTrigger', {
schedule: '0 0 2 * * *',
extraInputs: [df.input.durableClient()],
handler: async (myTimer, context) => {
const client = df.getClient(context);
const instanceId = await client.startNew('AutoDeleteBackupOrchestrator');
context.log('[Auto-Delete-Backup]: Started orchestration with ID: ', instanceId);
}
});
is there any testing util is available for v4 javascript durable function? how we can write unit test case of these code.
You can make use of
Jestlibrary to Create Unit Test for Azure Function, Just install thejestpackage fromnpm. Create oneTests folderand atest file with js extensioninside it, Then run thenpx jestcommand to run the test:-Install jest package:-
In your Function project create one folder and add js file:-
__tests__/autoDeleteBackup.test.jsfile:-autoDeleteBackup.test.js:-Now, Run the command below:-
Output:-
Azure Durable Function Javascript v4 Durable Orchestrator Default Function code Test:-
Output:-
Reference:-
Azure function nodejs v4 test mode - Stack Overflow My answer