diff --git a/TEST_PLAN.md b/TEST_PLAN.md new file mode 100644 index 0000000..39720d6 --- /dev/null +++ b/TEST_PLAN.md @@ -0,0 +1,34 @@ +# Test Plan for Swagger Petstore API + +## Introduction +This document describes the test plan for automated testing of the PetStore API. The goal of testing is to verify +the correctness of the main endpoints and their compliance with the documentation. +The tests will be implemented using Playwright. + +## Test Approach +The testing approach for the PetStore API focuses on verifying that the API aligns with its documented specifications and consistently performs as expected under different conditions. + +## Test Types +Functional Testing: Verify that each API endpoint works as expected, including correct CRUD operations (Create, Read, Update, Delete). +Boundary Testing: Test edge cases to ensure the API handles inputs at the extremes (e.g., large data sets, maximum and minimum field values). +Error Handling: Test both positive and negative scenarios, in case the server is designed to handle negative scenarios. + +## Risk & Mitigation +- **API Instability** +**Risk**: The Pet Store API may experience downtime or unexpected behavior during testing, leading to test failures or delays. +**Mitigation**: Monitor the API's status and schedule tests during off-peak hours. + +- **Incomplete Test Data** +**Risk**: Insufficient test data may result in incomplete test coverage. Without proper data, some scenarios, especially edge cases, may be missed. +**Mitigation**: Develop a well-rounded dataset that includes both positive and negative test cases. This should cover normal use cases and edge conditions. + +## Entry Criteria +- API documentation is available and up-to-date. +- Test environment is set up and accessible. +- Test data is prepared and covers key scenarios. +- Playwright is configured. +- API is stable for testing. + +## Exit Criteria +- All planned test cases have been executed. +- Test results have been reviewed. \ No newline at end of file diff --git a/tests/storeTests.spec.ts b/tests/storeTests.spec.ts new file mode 100644 index 0000000..3f2ff59 --- /dev/null +++ b/tests/storeTests.spec.ts @@ -0,0 +1,100 @@ +import {test, expect, request} from '@playwright/test'; +const backendURL: string = 'https://petstore.swagger.io/v2/store' + +test.describe ('Testing access to orders in the pet store', () => { + test('Return pet inventory by status', async () => { + const context = await request.newContext(); + const response = await context.get(`${backendURL}/inventory`) + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log(responseBody); + }); + + test('Place an order for a pet', async () => { + const context = await request.newContext(); + const response = await context.post(`${backendURL}/order`, { + data: { + "id": 1, + "petId": 0, + "quantity": 0, + "shipDate": "2025-01-01T17:00:00.000Z", + "status": "placed", + "complete": true + }, + }); + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log(responseBody); + }); +}); + +test.describe('Find purchase order by ID', async () => { + const orderId = 2; + test.beforeAll(async () => { + const context = await request.newContext(); + const response = await context.post(`${backendURL}/order`, { + data: { + "id": orderId, + "petId": 0, + "quantity": 0, + "shipDate": "2025-06-01T17:12:00.000Z", + "status": "placed", + "complete": true + }, + }); + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log(responseBody); + }); + + test('Find order', async () => { + const context = await request.newContext(); + const response = await context.get(`${backendURL}/order/${orderId}`); + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log(responseBody); + }); +}); + +test.describe('Delete order by ID', () => { + const orderId = 3; + test.beforeAll(async () => { + const context = await request.newContext(); + const response = await context.post(`${backendURL}/order`, { + data: { + "id": orderId, + "petId": 0, + "quantity": 0, + "shipDate": "2025-06-01T17:12:00.000Z", + "status": "placed", + "complete": true + }, + }); + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log(responseBody); + }); + + test('Delete order', async () => { + const context = await request.newContext(); + const response = await context.delete(`${backendURL}/order/${orderId}`); + expect(response.status()).toBe(200); + + const responseBody = await response.json(); + console.log(responseBody); + }); + + test.afterAll(async () => { + const context = await request.newContext(); + const response = await context.delete(`${backendURL}/order/${orderId}`); + expect(response.status()).toBe(404); + + const responseBody = await response.json(); + console.log(responseBody); + }); +}); \ No newline at end of file