-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): functional test changes (#1359)
* test(core): remove unused JS coverage collection * chore(core): move ui test files around * test(core): update skipped tests * test(core): remove serial ran tests * test(core): add customer account fixture for tests
- Loading branch information
1 parent
27cbfd2
commit f37deb6
Showing
41 changed files
with
306 additions
and
738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { test as base } from '@playwright/test'; | ||
|
||
import { AccountFactory } from './utils/account'; | ||
|
||
interface Fixtures { | ||
/** | ||
* This fixture enables the creation, deletion, and the ability to login and logout of customer accounts. | ||
*/ | ||
account: AccountFactory; | ||
} | ||
|
||
export const test = base.extend<Fixtures>({ | ||
account: [ | ||
async ({ page }, use) => { | ||
const accountFactory = new AccountFactory(page); | ||
|
||
await use(accountFactory); | ||
|
||
await accountFactory.cleanup(); | ||
}, | ||
{ scope: 'test' }, | ||
], | ||
}); | ||
|
||
export { expect, type Page } from '@playwright/test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { type Page } from '@playwright/test'; | ||
|
||
export class Account { | ||
constructor( | ||
private readonly page: Page, | ||
readonly firstName: string, | ||
readonly lastName: string, | ||
readonly email: string, | ||
readonly password: string, | ||
readonly id: number, | ||
) {} | ||
|
||
async login() { | ||
await this.page.goto('/login/'); | ||
await this.page.getByLabel('Email').fill(this.email); | ||
await this.page.getByLabel('Password').fill(this.password); | ||
await this.page.getByRole('button', { name: 'Log in' }).click(); | ||
await this.page.waitForURL('/account/'); | ||
} | ||
|
||
async logout() { | ||
await this.page.getByRole('button', { name: 'Account' }).click(); | ||
await this.page.getByRole('menuitem', { name: 'Log out' }).click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { faker, fi } from '@faker-js/faker'; | ||
import { z } from 'zod'; | ||
|
||
const Customer = z.object({ | ||
id: z.number(), | ||
}); | ||
|
||
const CreateCustomersResponse = z.object({ | ||
data: z.array(Customer), | ||
}); | ||
|
||
export async function createAccount() { | ||
const firstName = faker.person.firstName(); | ||
const lastName = faker.person.lastName(); | ||
const email = faker.internet.email({ firstName, lastName }); | ||
// Prefix is added to ensure that the password requirements are met | ||
const password = faker.internet.password({ pattern: /[a-zA-Z0-9]/, prefix: '1At', length: 10 }); | ||
const address1 = faker.location.streetAddress(); | ||
const city = faker.location.city(); | ||
const state = faker.location.state(); | ||
const postal_code = faker.location.zipCode('#####'); | ||
|
||
if (!process.env.BIGCOMMERCE_ACCESS_TOKEN) { | ||
throw new Error('BIGCOMMERCE_ACCESS_TOKEN is not set'); | ||
} | ||
|
||
if (!process.env.BIGCOMMERCE_STORE_HASH) { | ||
throw new Error('BIGCOMMERCE_STORE_HASH is not set'); | ||
} | ||
|
||
const response = await fetch( | ||
`https://api.bigcommerce.com/stores/${process.env.BIGCOMMERCE_STORE_HASH}/v3/customers`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Auth-Token': process.env.BIGCOMMERCE_ACCESS_TOKEN, | ||
}, | ||
body: JSON.stringify([ | ||
{ | ||
first_name: firstName, | ||
last_name: lastName, | ||
email, | ||
authentication: { | ||
new_password: password, | ||
}, | ||
addresses: [ | ||
{ | ||
first_name: firstName, | ||
last_name: lastName, | ||
address1, | ||
city, | ||
state_or_province: state, | ||
country_code: 'US', | ||
postal_code, | ||
}, | ||
], | ||
}, | ||
]), | ||
}, | ||
); | ||
|
||
const data: unknown = await response.json(); | ||
const parsedResponse = CreateCustomersResponse.parse(data); | ||
const customer = Customer.parse(parsedResponse.data[0]); | ||
|
||
return { | ||
firstName, | ||
lastName, | ||
email, | ||
password, | ||
id: customer.id, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export async function deleteAccount(customerId: number) { | ||
if (!process.env.BIGCOMMERCE_ACCESS_TOKEN) { | ||
throw new Error('BIGCOMMERCE_ACCESS_TOKEN is not set'); | ||
} | ||
|
||
if (!process.env.BIGCOMMERCE_STORE_HASH) { | ||
throw new Error('BIGCOMMERCE_STORE_HASH is not set'); | ||
} | ||
|
||
try { | ||
await fetch( | ||
`https://api.bigcommerce.com/stores/${process.env.BIGCOMMERCE_STORE_HASH}/v3/customers?id:in=${customerId}`, | ||
{ | ||
method: 'DELETE', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Auth-Token': process.env.BIGCOMMERCE_ACCESS_TOKEN, | ||
}, | ||
}, | ||
); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { type Page } from '@playwright/test'; | ||
|
||
import { Account } from './account'; | ||
import { createAccount } from './create'; | ||
import { deleteAccount } from './delete'; | ||
|
||
export class AccountFactory { | ||
autoCleanup = false; | ||
private accounts: Account[] = []; | ||
|
||
constructor(private readonly page: Page) {} | ||
|
||
async create() { | ||
const customer = await createAccount(); | ||
|
||
const account = new Account( | ||
this.page, | ||
customer.firstName, | ||
customer.lastName, | ||
customer.email, | ||
customer.password, | ||
customer.id, | ||
); | ||
|
||
this.accounts.push(account); | ||
|
||
return account; | ||
} | ||
|
||
async cleanup() { | ||
await Promise.all(this.accounts.map(async (account) => await deleteAccount(account.id))); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.