11import { test , expect , request } from "@playwright/test" ;
22import * as fs from "fs" ;
33import * as path from "path" ;
4+ import pets from "../test-data/pets.Data.json"
45
56const backendURL : string = "https://petstore.swagger.io/v2/pet" ;
67
@@ -37,22 +38,7 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
3738 test ( "Add a new pet to the store" , async ( ) => {
3839 const context = await request . newContext ( ) ;
3940 const response = await context . post ( `${ backendURL } ` , {
40- data : {
41- id : 2 ,
42- category : {
43- id : 0 ,
44- name : "string" ,
45- } ,
46- name : "doggie" ,
47- photoUrls : [ "string" ] ,
48- tags : [
49- {
50- id : 0 ,
51- name : "string" ,
52- } ,
53- ] ,
54- status : "available" ,
55- } ,
41+ data :pets . pet2 ,
5642 } ) ;
5743 expect ( response . status ( ) ) . toBe ( 200 ) ;
5844 const responseBody = await response . json ( ) ;
@@ -62,22 +48,7 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
6248 test ( "Update an existing pet" , async ( ) => {
6349 const context = await request . newContext ( ) ;
6450 const response = await context . post ( `${ backendURL } ` , {
65- data : {
66- id : 2 ,
67- category : {
68- id : 0 ,
69- name : "string" ,
70- } ,
71- name : "kitty" ,
72- photoUrls : [ "string" ] ,
73- tags : [
74- {
75- id : 0 ,
76- name : "string" ,
77- } ,
78- ] ,
79- status : "available" ,
80- } ,
51+ data : pets . pet2update
8152 } ) ;
8253 expect ( response . status ( ) ) . toBe ( 200 ) ;
8354 const responseBody = await response . json ( ) ;
@@ -87,55 +58,51 @@ test.describe("Testing uploading image for pet and pets creation/updating", () =
8758
8859test . describe ( "Find pet by status: available, pending, sold" , ( ) => {
8960 test ( 'Should return pets with status "pending"' , async ( { request } ) => {
90- const status = "pending" ;
9161 const response = await request . get ( `${ backendURL } /findByStatus` , {
92- params : { status } ,
62+ params : pets . pet2 . status [ 1 ] ,
9363 } ) ;
9464
9565 expect ( response . status ( ) ) . toBe ( 200 ) ;
9666
9767 const responseBody = await response . json ( ) ;
9868 expect ( Array . isArray ( responseBody ) ) . toBeTruthy ( ) ;
9969 responseBody . forEach ( ( pet ) => {
100- expect ( pet . status ) . toBe ( "pending" ) ;
70+ expect ( pet . status ) . toBe ( pets . pet2 . status [ 1 ] ) ;
10171 } ) ;
10272 } ) ;
10373} ) ;
10474
10575test ( 'Should return pets with status "available"' , async ( { request } ) => {
106- const status = "available" ;
10776 const response = await request . get ( `${ backendURL } /findByStatus` , {
108- params : { status } ,
77+ params : pets . pet2 . status [ 0 ] ,
10978 } ) ;
11079
11180 expect ( response . status ( ) ) . toBe ( 200 ) ;
11281
11382 const responseBody = await response . json ( ) ;
11483 expect ( Array . isArray ( responseBody ) ) . toBeTruthy ( ) ;
11584 responseBody . forEach ( ( pet ) => {
116- expect ( pet . status ) . toBe ( "available" ) ;
85+ expect ( pet . status ) . toBe ( pets . pet2 . status [ 0 ] ) ;
11786 } ) ;
11887} ) ;
11988
12089test ( 'Should return pets with status "sold"' , async ( { request } ) => {
121- const status = "sold" ;
12290 const response = await request . get ( `${ backendURL } /findByStatus` , {
123- params : { status } ,
91+ params : pets . pet2 . status [ 2 ] ,
12492 } ) ;
12593
12694 expect ( response . status ( ) ) . toBe ( 200 ) ;
12795 const responseBody = await response . json ( ) ;
12896 expect ( Array . isArray ( responseBody ) ) . toBeTruthy ( ) ;
12997 responseBody . forEach ( ( pet ) => {
130- expect ( pet . status ) . toBe ( "sold" ) ;
98+ expect ( pet . status ) . toBe ( pets . pet2 . status [ 2 ] ) ;
13199 } ) ;
132100} ) ;
133101
134102test . describe ( "Find pet by ID, update pet in the store" , async ( ) => {
135103 test ( "Find pet" , async ( ) => {
136- const petId = 4 ;
137104 const context = await request . newContext ( ) ;
138- const response = await context . get ( `${ backendURL } /${ petId } ` ) ;
105+ const response = await context . get ( `${ backendURL } /${ pets . pet4 . id } ` ) ;
139106 expect ( response . status ( ) ) . toBe ( 200 ) ;
140107
141108 const responseBody = await response . json ( ) ;
@@ -144,44 +111,25 @@ test.describe("Find pet by ID, update pet in the store", async () => {
144111} ) ;
145112
146113test ( "Update pet information" , async ( ) => {
147- const petId = 2 ;
148- const updatedName = "Updated Pet Name" ;
149- const updatedStatus = "sold" ;
150114 const context = await request . newContext ( ) ;
151- const response = await context . post ( `${ backendURL } /${ petId } ` , {
115+ const response = await context . post ( `${ backendURL } /${ pets . pet2update . id } ` , {
152116 form : {
153- name : updatedName ,
154- status : updatedStatus ,
117+ name : pets . pet2update . name ,
118+ status : pets . pet2update . status [ 2 ]
155119 } ,
156120 } ) ;
157121 expect ( response . status ( ) ) . toBe ( 200 ) ;
158122
159123 const responseBody = await response . json ( ) ;
160124 console . log ( responseBody ) ;
161- expect ( responseBody . message ) . toBe ( petId . toString ( ) ) ;
125+ expect ( responseBody . message ) . toBe ( pets . pet2update . id . toString ( ) ) ;
162126} ) ;
163127
164128test . describe ( "Delete pet by ID" , async ( ) => {
165- const petId = 6 ;
166129 test . beforeAll ( async ( ) => {
167130 const context = await request . newContext ( ) ;
168131 const response = await context . post ( `${ backendURL } ` , {
169- data : {
170- id : petId ,
171- category : {
172- id : 0 ,
173- name : "string" ,
174- } ,
175- name : "doggie" ,
176- photoUrls : [ "string" ] ,
177- tags : [
178- {
179- id : 0 ,
180- name : "string" ,
181- } ,
182- ] ,
183- status : "available" ,
184- } ,
132+ data : pets . pet6
185133 } ) ;
186134 expect ( response . status ( ) ) . toBe ( 200 ) ;
187135 const responseBody = await response . json ( ) ;
@@ -191,7 +139,7 @@ test.describe("Delete pet by ID", async () => {
191139 test ( "Delete pet" , async ( ) => {
192140 const context = await request . newContext ( ) ;
193141 const apiKey = "your_actual_api_key" ;
194- const response = await context . delete ( `${ backendURL } /${ petId } ` , {
142+ const response = await context . delete ( `${ backendURL } /${ pets . pet6 . id } ` , {
195143 headers : {
196144 api_key : apiKey ,
197145 } ,
@@ -203,10 +151,9 @@ test.describe("Delete pet by ID", async () => {
203151 } ) ;
204152
205153 test . afterAll ( async ( ) => {
206- const petId = 6 ;
207154 const context = await request . newContext ( ) ;
208- const response = await context . delete ( `${ backendURL } /${ petId } ` ) ;
155+ const response = await context . delete ( `${ backendURL } /${ pets . pet6 . id } ` ) ;
209156
210- expect ( response . status ( ) ) . toBe ( 404 ) ;
157+ expect ( response . status ( ) ) . toBe ( 404 ) ;
211158 } ) ;
212- } ) ;
159+ } ) ;
0 commit comments