I have a nextjs server action that uses mssql
for node to connect with the database.
The following is pizza.actions.ts
:
export async function get_pizza_id(pizza_name: string) {
try {
if(!pool.connected) {
await connectDB();
}
const result = await pool.request()
.input('pizza_name', pizza_name)
.query('SELECT pizza_id FROM phut.pizza WHERE pizza_name = @pizza_name');
return result.recordset;
}
catch (error) {
console.error('Error fetching pizza:', error);
throw error;
}
}
After creating this script - I wanted to write a test to ensure that it works - such that whenever I make code changes in the future I can test whether all functionalities are working.
The docs recommend using E2E testing.
While I have some experience using selenium, they recommend playwright. I am looking for recommended way to develop web-app systems that are full-stack and use next.js or similar frameworks.
Note: I understand that there is no specific answer for this - and some stackoverflow users have issues answering such questions. I am hoping the community is stronger and that it can guide me - specially since I truly believe design and testing are fundamental for efficient software development. I am attempting to avoid potential pitfalls by asking this here.
I tried using jest for testing the api links but it wasn't picking up environment variables - and while attempting to solve the issue realized that I might be using the tool wrong
import dotenv from 'dotenv';
dotenv.config({ path: '.env.test.local' });
describe('updatePizza', () => {
it('should update the user details if the pizza exists', async () => {
// Mock the database connection and request methods
const params = {
id: 1,
pizza_name: 'Sid',
pizza_price:23,
};
if(!pool.connected) {
connectDB();
}
const result = await updatePizza(params);
expect(result.rowsAffected).toEqual([1]);
});
mssql
package - but the link provided is for MySQL (/package/mysql
) ...... so which one is it, really?