mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-06-04 06:27:38 -04:00
* Added Database checks to the onboarding flow * Added compatibility page setup Added more compatibility questions * Finished up the onboarding flow suite Added compatibility question tests and verifications Updated tests to cover Keywords and Headline changes recently made Updated tests to cover all of the big5 personality traits * . * Fix: Merge conflict * . * Fix: Added fix for None discriptive error issue #36 Updated signUp.spec.ts to use new fixture Updated Account information variable names Deleted "deleteUserFixture.ts" as it was incorporated into the "base.ts" file * Linting and Prettier * Minor cleaning * Added Google account to the Onboarding flow * Added account cleanup for google accounts * Started work on Sign-in tests Updated seedDatabase.ts to throw an error if the user already exists, to also add display names and usernames so they seedUser func acts like a normal basic user Some organising of the google auth code * Linting and Prettier * Added checks to the deleteUser func to check if the accout exists Added account deletion checks * Linting and Prettier * Formatting update, fixed homePage locator for signin * . * . * . * Coderabbitai fix's * Fix * Improve test utilities and stabilize onboarding flow tests * Changes requested * Changed POM/Fixture structure to use an app class to instantiate the page objects * Apply suggestion from @MartinBraquet * Delete .vscode/settings.json * Apply suggestion from @MartinBraquet * Apply suggestion from @MartinBraquet * Apply suggestion from @MartinBraquet * Linting and Prettier * Updated People page * Fix app.ts * Updated peoplePage.ts: continued adding functions to use filters Updated filters.tsx: added data testid * Coderabbitai fix's * . * Updated People page Added data test attributes to search.tsx and profile-grid.tsx * Lint and Prettier * . * Continued work on filter tests Added testid attributes to people page so the info from the results can be accessed * Added more filter tests * Added tests for hiding profiles * Added a context manager to test with multiple accounts interacting with each other Added an option to verify the users email when creating an account * Added Tests for sending/recieving messages Added tests for staring/favoriting profiles Added testIds where necessary Added messagesPage.ts Updated peoplePage.ts * Linting and Prettier * Coderabbit suggestions * CodeRabbit suggestion #2 * Fix #1 * Minor fixes * TC fix --------- Co-authored-by: MartinBraquet <martin.braquet@gmail.com>
173 lines
6.0 KiB
TypeScript
173 lines
6.0 KiB
TypeScript
import {faker} from '@faker-js/faker'
|
|
import {debug} from 'common/logger'
|
|
import {PrivateUser} from 'common/user'
|
|
import {getDefaultNotificationPreferences} from 'common/user-notification-preferences'
|
|
import {cleanUsername} from 'common/util/clean-username'
|
|
import {randomString} from 'common/util/random'
|
|
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
|
import {insert} from 'shared/supabase/utils'
|
|
import {getUser} from 'shared/utils'
|
|
|
|
import UserAccountInformationForSeeding from '../backend/utils/userInformation'
|
|
import {firebaseSignUp, verifyEmail} from './firebaseUtils'
|
|
|
|
export const TEST_USER_EMAIL = 'user@compass.test'
|
|
export const TEST_USER_PASSWORD = 'pass'
|
|
export const TEST_USER_DISPLAY_NAME = 'Test User'
|
|
export const TEST_USER_USERNAME = 'TestUser'
|
|
|
|
/**
|
|
* Function used to populate the database with profiles.
|
|
*
|
|
* @param userInfo - Class object containing information to create a user account generated by `fakerjs`.
|
|
* @param profileType - Optional param used to signify how much information is used in the account generation.
|
|
*/
|
|
export async function seedDbUser(
|
|
userInfo: UserAccountInformationForSeeding,
|
|
profileType?: string,
|
|
): Promise<boolean> {
|
|
const pg = createSupabaseDirectClient()
|
|
const userId = userInfo.user_id
|
|
const deviceToken = randomString()
|
|
const bio = {
|
|
type: 'doc',
|
|
content: [
|
|
{
|
|
type: 'paragraph',
|
|
content: [
|
|
{
|
|
text: userInfo.bio,
|
|
type: 'text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
const relationshipStyle = userInfo.randomElement(userInfo.pref_relation_styles)
|
|
let romanticStyle: string | null = null
|
|
if (relationshipStyle === 'relationship') {
|
|
romanticStyle = userInfo.randomElement(userInfo.pref_romantic_styles)
|
|
}
|
|
|
|
const numberOfLanguages = faker.number.int({min: 1, max: 3})
|
|
const languagesKnown = []
|
|
|
|
for (let i = 0; i < numberOfLanguages; i++) {
|
|
languagesKnown.push(userInfo.randomElement(userInfo.languages))
|
|
}
|
|
|
|
const keywords = faker.number.int({min: 1, max: 4})
|
|
const profileKeywords = []
|
|
for (let i = 0; i < keywords; i++) {
|
|
profileKeywords.push(userInfo.keywords)
|
|
}
|
|
|
|
const basicProfile = {
|
|
user_id: userId,
|
|
bio_length: userInfo.bio.length,
|
|
bio: bio,
|
|
age: userInfo.age,
|
|
gender: userInfo.randomElement(userInfo.gender),
|
|
orientation: userInfo.orientation,
|
|
headline: userInfo.headline,
|
|
keywords: profileKeywords,
|
|
ethnicity: [userInfo.randomElement(userInfo.ethnicity)],
|
|
height_in_inches: userInfo.height_in_inches,
|
|
pref_gender: [userInfo.randomElement(userInfo.pref_gender)],
|
|
pref_relation_styles: [relationshipStyle],
|
|
relationship_status: [userInfo.randomElement(userInfo.relationship_status)],
|
|
pref_romantic_styles: romanticStyle ? [romanticStyle] : [],
|
|
pref_age_min: userInfo.pref_age.min,
|
|
pref_age_max: userInfo.pref_age.max,
|
|
born_in_location: userInfo.born_in_location,
|
|
company: userInfo.company,
|
|
occupation_title: userInfo.occupation_title,
|
|
religion: [userInfo.randomElement(userInfo.religion)],
|
|
has_kids: userInfo.has_kids,
|
|
wants_kids_strength: userInfo.wants_kids_strength,
|
|
is_smoker: userInfo.is_smoker,
|
|
// visibility: 'public',
|
|
}
|
|
|
|
const mediumProfile = {
|
|
...basicProfile,
|
|
drinks_per_month: userInfo.drinks_per_month,
|
|
diet: [userInfo.randomElement(userInfo.diet)],
|
|
education_level: userInfo.randomElement(userInfo.education_level),
|
|
languages: languagesKnown,
|
|
orientation_details: 'Some orientation details',
|
|
}
|
|
|
|
const fullProfile = {
|
|
...mediumProfile,
|
|
cannabis: userInfo.randomElement(userInfo.cannabis),
|
|
psychedelics: userInfo.randomElement(userInfo.psychedelics),
|
|
cannabis_intention: [userInfo.randomElement(userInfo.cannabis_intention)],
|
|
psychedelics_intention: [userInfo.randomElement(userInfo.psychedelics_intention)],
|
|
cannabis_pref: [userInfo.randomElement(userInfo.cannabis_pref)],
|
|
psychedelics_pref: [userInfo.randomElement(userInfo.psychedelics_pref)],
|
|
political_beliefs: [userInfo.randomElement(userInfo.political_beliefs)],
|
|
mbti: userInfo.randomElement(userInfo.mbti),
|
|
big5_openness: userInfo.big5_openness,
|
|
big5_conscientiousness: userInfo.big5_conscientiousness,
|
|
big5_extraversion: userInfo.big5_extraversion,
|
|
big5_agreeableness: userInfo.big5_agreeableness,
|
|
big5_neuroticism: userInfo.big5_neuroticism,
|
|
gender_details: 'Some gender details',
|
|
}
|
|
|
|
const profileData =
|
|
profileType === 'basic' ? basicProfile : profileType === 'medium' ? mediumProfile : fullProfile
|
|
|
|
const privateUser: PrivateUser = {
|
|
id: userId,
|
|
email: userInfo.email,
|
|
initialIpAddress: userInfo.ip,
|
|
initialDeviceToken: deviceToken,
|
|
notificationPreferences: getDefaultNotificationPreferences(),
|
|
blockedUserIds: [],
|
|
blockedByUserIds: [],
|
|
}
|
|
|
|
return pg.tx(async (tx: any) => {
|
|
const preexistingUser = await getUser(userId, tx)
|
|
if (preexistingUser) return false
|
|
|
|
await insert(tx, 'users', {
|
|
id: userId,
|
|
name: userInfo.name,
|
|
username: cleanUsername(userInfo.userName),
|
|
data: {},
|
|
})
|
|
|
|
await insert(tx, 'private_users', {
|
|
id: userId,
|
|
data: privateUser,
|
|
})
|
|
|
|
await insert(tx, 'profiles', profileData)
|
|
return true
|
|
})
|
|
}
|
|
|
|
export async function seedUser(
|
|
email?: string | undefined,
|
|
password?: string | undefined,
|
|
profileType?: string | undefined,
|
|
displayName?: string | undefined,
|
|
userName?: string | undefined,
|
|
verifyUserEmail?: boolean,
|
|
) {
|
|
const userInfo = new UserAccountInformationForSeeding()
|
|
if (email) userInfo.email = email
|
|
if (password) userInfo.password = password
|
|
if (displayName) userInfo.name = displayName
|
|
if (userName) userInfo.userName = userName
|
|
const firebaseId = await firebaseSignUp(userInfo.email, userInfo.password)
|
|
if (firebaseId) userInfo.user_id = firebaseId
|
|
// Fall back to the pre-generated faker id when Firebase is unreachable
|
|
const created = await seedDbUser(userInfo, profileType ?? 'full')
|
|
if (created) debug('User created in Supabase:', userInfo.email)
|
|
if (verifyUserEmail) await verifyEmail(userInfo.email, userInfo.password)
|
|
}
|