Skip to content

SalhiFayza/playwright-APIs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

APIs_Products_Admin_User โ˜•

๐Ÿ˜œ Nodejs&Expressjs => JavaScript ๐Ÿ’› / MongoDB ๐Ÿ’š / JWT ๐Ÿ”

๐ŸŒตOverview

This project is a backend API built with Node.js and Express. It uses MySQL with Sequelize for database management, and MongoDB with Mongoose for certain data models. Security is handled with bcrypt for password hashing and jsonwebtoken for authentication. File uploads are managed by multer.


๐ŸดFeatures

  • RESTful API endpoints for various resources
  • Data validation using Joi
  • Authentication with JWT tokens
  • Password hashing with bcrypt
  • File upload support
  • MySQL and MongoDB integration
  • Comprehensive API tests with Playwright

๐Ÿ“ Project Structure

alt text

๐Ÿงช Testing

๐Ÿ“ฌ Manual API Testing

All API endpoints are first tested manually using Postman to ensure they behave correctly.

๐ŸŽญ Automated Testing with Playwright

Automated end-to-end API tests are implemented using Playwright. These tests simulate real user interactions and verify API behavior.

๐Ÿฆฉ API Testing with Playwright

This project uses Playwright to automate API testing.

Example test:

test.describe('Admin creates a product', () => {
  test.beforeAll(async ({ request }) => {
    const res = await request.post('/admin/login', {
      data: { email: 'admin@example.com', password: 'secret' },
    });
    token = (await res.json()).token;
  });

  test('Create product with valid data', async ({ request }) => {
    const res = await request.post('/product/add', {
      data: {
        nameProduct: "Coffee",
        Description: "Roasted coffee beans",
        priceProduct: 10,
        image: "https://example.com/coffee.jpg"
      },
      headers: { Authorization: `Bearer ${token}` },
    });
    expect(res.status()).toBe(201);
  });
});

โœ… Authenticates with admin
โœ… Sends authorized request
โœ… Asserts response status and content

Playwright lets you test your APIs quickly in CI without needing a browser.

๐Ÿ’ป How to run locally

  1. Clone the repository
    git clone https://github.com/yourusername/api.git

  2. Install dependencies
    npm install

  3. Create a .env file and add your environment variables (database credentials, JWT secret, etc.)๐Ÿ˜œ๐Ÿ”‘

  4. Start the server
    node server.js

  5. Run tests
    npm test


Author

๐Ÿ€ Salhi Fayza