WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/userTests.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test, expect } from '@playwright/test';
import { loginWithCredsFromEnv, CheckUserInformation, CreateTestUser } from './utilities';
import { validUserName, validPassword } from '../playwright.config';


test.describe('Login and UserInfo tests', () => {
test('Create User', async () => {
const responseStatus = await CreateTestUser({ username: validUserName, password: validPassword })
expect(responseStatus.status()).toBe(200);
});

test('Check Login', async () => {
const responseStatus = await loginWithCredsFromEnv(validUserName, validPassword);
expect(responseStatus.status()).toBe(200);
});

test('Check User', async () => {
const responseStatus = await CheckUserInformation(validUserName)
expect(responseStatus.status()).toBe(200);
});
})
48 changes: 48 additions & 0 deletions tests/utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, expect, request } from '@playwright/test';

export async function CreateTestUser({id = 11225, username = "TestUser", firstName = "Auto", lastName = "Testing", email = "[email protected]", password = "12345678Aa!", phone = "0661112233", userStatus = 0} = {}) {
const context = await request.newContext();
const response = await context.post('https://petstore.swagger.io/v2/user', {
data: {
"id": id,
"username": username,
"firstName": firstName,
"lastName": lastName,
"email": email,
"password": password,
"phone": phone,
"userStatus": userStatus
}
})
const responseBody = await response.json();
console.log('Creation response:', responseBody);
return response
}

export async function loginWithCredsFromEnv(username: string | undefined, password: string | undefined) {
const context = await request.newContext();
if (!username || !password) {
throw new Error('Username or password is undefined');
}
const response = await context.get('https://petstore.swagger.io/v2/user/login', {

params: {
username: username,
password: password,
},
});
const responseBody = await response.json();
console.log('Login response:', responseBody);
return response
}

export async function CheckUserInformation(username: string | undefined) {
const context = await request.newContext();
const response = await context.get(`https://petstore.swagger.io/v2/user/${username}`)
const responseBody = await response.json();
console.log(responseBody)

const userInfo = await response.json();
console.log('User Information:', userInfo);
return response
}