Test the Function

Before you deploy the function to the remote console and integrate it with Zoho CRM, you can test it locally and check if everything works fine.

You can test and debug a function by launching a node shell from the Catalyst CLI. You can learn about the functions shell in detail from the Working with Functions help page. Let’s test the function by launching the functions shell in the CLI.

Navigate to your project directory in your terminal and execute the following command from the CLI:

copy
$
catalyst functions:shell

This opens the node shell. You can now pass inputs, execute the function, and perform other node shell operations in it.

Note: You can launch the function shell with your IDE's debugger attached to it. This will enable you to debug the function line by line in your IDE. You can do this by executing the command: catalyst functions:shell –debug [port].

Let’s test the countfunction by passing the input values for feature_name and mail_count_threshold. Execute this command in the function shell:

copy
$
countfunction({"feature_name":"CRM","mail_count_threshold":"1"})

This assigns the threshold value as ‘1’ for the feature ‘CRM’. Therefore, when the function is invoked more than once for the feature, the counter will exceed the threshold limit.


The CLI will invoke the function and pass the input values to the default segment in Catalyst Cache. The counter doesn’t exceed the threshold during the first invocation. Therefore, the CLI will just display the output message that we configured for the status code 200.

microservice_test_shell


You can verify if the counter value is added to the cache, by navigating to Cache under Storage in the Cloud Scale section of the Catalyst console.

microservice_cache_name


Click Default to open the default segment in the Segments page. You will be able to see a key-value pair added to the segment, with the key name ‘COUNTER_CRM’ and the value ‘1’ indicating that the function was invoked once.

microservice_cache_info


Now let’s invoke the function a second time to exceed the threshold limit. Execute the countfunction({“feature_name”:“CRM”,“mail_count_threshold”:“1”}) command again.

This will invoke the function again and increment the counter value. Since the threshold limit of 1 has now been exceeded, the email alert will be sent automatically to the defined receiver email address. The CLI will display the message that was pushed to the logs indicating this.

microservice_test_application


You can verify this by checking the receiver email.

microservice_test_email


The value of the counter will also be updated in the cache.

microservice_cache_update

If this setup is working correctly, we can deploy the application to production.

Last Updated 2023-12-15 18:54:08 +0530 +0530

RELATED LINKS

Serve Resources