I have a function in my api folder that searches an array of services and returns a single service depending on the slug.
The api function is:
import {services} from '../../../public/data/service.js'
export default async function getSingleService (req, res) {
const serviceId = req.query.serviceID
const result = services.filter((each) => each.url === serviceId )
if(result.length > 0) {
return res.status(200).json(result[0])
} else {
res.status(404).json({message: 'Service not found'})
}
}
How do I got about to write a test for this function. I just started with jest, any help would be nice.