Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciaqa committed Feb 8, 2024
1 parent 37962ba commit c17f9ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions tests/get-pet.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const { test, expect } = require('@playwright/test');

const data = JSON.parse(JSON.stringify(require("../testdata.json")))
// Importing test data directly
const data = require("../testdata.json")

test.describe('New Todo', () => {
test('should allow consult user by API request', async ({ request }) => {

// Create a new user
await request.post(`/v2/user/createWithArray`, {data})

// Get the details of the user created
const listUser = await request.get(`/v2/user/${data[0].username}`)

// Parse response body to JSON
const body = await listUser.json()
// Assert that the response body matches the test data
expect([body]).toEqual(data)
});
});
Expand Down
14 changes: 8 additions & 6 deletions tests/post-pet.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const { test, expect } = require('@playwright/test');

const data = JSON.parse(JSON.stringify(require("../testdata.json")))
// Importing test data directly
const data = require("../testdata.json")

test.describe('New Todo', () => {

test('should allow create user by API request', async ({ request }) => {
const newUser = await request.post(`/v2/user/createWithArray`, {data})

expect(newUser.status()).toEqual(200)
expect(newUser.statusText()).toEqual("OK")
expect(await newUser.json()).toEqual({"code": 200, "message": "ok", "type": "unknown"})

// Asserting response status
expect(newUser.status()).toBe(200)
// Asserting response status text
expect(newUser.statusText()).toBe('OK')
// Parsing and asserting response JSON
expect(await newUser.json()).toEqual({code: 200, message: 'ok', type: 'unknown'})
});

});
Expand Down

0 comments on commit c17f9ba

Please sign in to comment.