forked from jsnbuchanan/crowd-funder-for-time-pwa
refactor: extract test user data and improve "New offers" test flow
- Extract test user data (seed phrases, DIDs, usernames) from importUser into separate getTestUserData function
- Refactor importUser to use getTestUserData internally, maintaining backward compatibility
- Update "New offers for another user" test to use new getTestUserData function
- Replace hardcoded seed phrase with programmatic retrieval using getTestUserData('00')
- Add proper TypeScript type annotations to array functions in testUtils
- Improve test maintainability by centralizing test user data management
This allows tests to access user data without executing import flow, providing more flexibility for test scenarios.
This commit is contained in:
@@ -1,24 +1,30 @@
|
||||
import { expect, Page } from '@playwright/test';
|
||||
|
||||
// Import the seed and switch to the user based on the ID.
|
||||
// Get test user data based on the ID.
|
||||
// '01' -> user 111
|
||||
// otherwise -> user 000
|
||||
// (... which is a weird convention but I haven't taken the time to change it)
|
||||
export async function importUser(page: Page, id?: string): Promise<string> {
|
||||
let seedPhrase, userName, did;
|
||||
|
||||
// Set seed phrase and DID based on user ID
|
||||
export function getTestUserData(id?: string): { seedPhrase: string, userName: string, did: string } {
|
||||
switch(id) {
|
||||
case '01':
|
||||
seedPhrase = 'island fever beef wine urban aim vacant quit afford total poem flame service calm better adult neither color gaze forum month sister imitate excite';
|
||||
userName = 'User One';
|
||||
did = 'did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39';
|
||||
break;
|
||||
return {
|
||||
seedPhrase: 'island fever beef wine urban aim vacant quit afford total poem flame service calm better adult neither color gaze forum month sister imitate excite',
|
||||
userName: 'User One',
|
||||
did: 'did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39'
|
||||
};
|
||||
default: // to user 00
|
||||
seedPhrase = 'rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage';
|
||||
userName = 'User Zero';
|
||||
did = 'did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F';
|
||||
return {
|
||||
seedPhrase: 'rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage',
|
||||
userName: 'User Zero',
|
||||
did: 'did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Import the seed and switch to the user based on the ID.
|
||||
export async function importUser(page: Page, id?: string): Promise<string> {
|
||||
const userData = getTestUserData(id);
|
||||
const { seedPhrase, userName, did } = userData;
|
||||
|
||||
// Import ID
|
||||
await page.goto('./start');
|
||||
@@ -109,7 +115,7 @@ export async function generateRandomString(length: number): Promise<string> {
|
||||
|
||||
// Function to create an array of unique strings
|
||||
export async function createUniqueStringsArray(count: number): Promise<string[]> {
|
||||
const stringsArray = [];
|
||||
const stringsArray: string[] = [];
|
||||
const stringLength = 16;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
@@ -122,7 +128,7 @@ export async function createUniqueStringsArray(count: number): Promise<string[]>
|
||||
|
||||
// Function to create an array of two-digit non-zero numbers
|
||||
export async function createRandomNumbersArray(count: number): Promise<number[]> {
|
||||
const numbersArray = [];
|
||||
const numbersArray: number[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
let randomNumber = Math.floor(Math.random() * 99) + 1;
|
||||
|
||||
Reference in New Issue
Block a user