I am working on a normal express backed API project which is using firebase functions for some performing offline data processing. In many cases the API raises event to pub-sub which is later picked up by cloud function. A typical example is all the aggregations(total sales for day/month) are all pushed to cloud function.
I am looking at having an integration test suite using firebase emulators where I can test from the API layer till cloud functions getting triggered and its updates to data store. Having integration test suite on emulator provides me good advantage on speed and cost along with quick local validation.
I am calling my regular test script with firebase emulator
firebase emulators:exec "npm run test"
On running the tests I can all the pubsub functions initialised.
Subsequently I can see that message is also pushed to topic.
However I don't see corresponding subscription firebase functions executing. My firebase function skeleton is like
export const addIncentiveData = functions
.region("asia-south1")
.pubsub.topic("on_wf_data_added")
.onPublish(async (message, context) => {
const FUNCTION_NAME = `addIncentiveData`;
console.log(`[${FUNCTION_NAME}] Entering `)
const FUNCTION_NAME = `addIncentiveData`;
logger.info(`[${FUNCTION_NAME}] : The function was triggered at ${context.timestamp}`);
logger.debug(`[${FUNCTION_NAME}] : The message is ${JSON.stringify(message)}`);
const payLoad = JSON.parse(Buffer.from(message.data, "base64").toString());
logger.debug(`[${FUNCTION_NAME}] : The payload is ${JSON.stringify(payLoad)}`);
//some processing
logger.info(`[${FUNCTION_NAME}] : Completed processing`);
return;
});

