We will create a simple temperature conversion code
// Celsius to Fahrenheit conversion
function celsiusToFahrenheit(celsius) {
var fahrenheit = celsius * 9/5 + 32;
return fahrenheit;
}
Now, open up your terminal and paste the following cURL request:
curl --location --request POST 'https://gptest1.p.rapidapi.com/api/v0/unit-test-generation' \
--header 'Content-Type: application/json' \
--header 'X-RapidAPI-Key: YOUR_RAPIDAPI_KEY \
--header 'X-RapidAPI-Host: gptest1.p.rapidapi.com' \
--data-raw '{"code": "function celsiusToFahrenheit(celsius) { var fahrenheit = celsius * 9/5 + 32; return fahrenheit;}"'
TA-DA! There you have your unit test
{
"unit_test": "describe('sum function', () => {\n it('should return the sum of two positive numbers', () => {\n expect(sum(2, 3)).toEqual(5);\n });\n\n it('should return the sum of a positive and a negative number', () => {\n expect(sum(2, -3)).toEqual(-1);\n });\n });"
}