mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 10:02:27 -04:00
* Fixed Type errors * Organizing testing utilities * Added Database checks to the onboarding flow * Updated Onboarding flow Changed type ChildrenExpectation so that it can be used for database verification * Added compatibility page setup Added more compatibility questions * Fix * . * Fix: Typo * Fix: Faker usernames can no longer generate symbols * Fix: Changed how work area is verified * . * . * Fix: Trying to work in headed mode * Fix: Change back to headless * Fix: Added timeout after workArea selection * . * Clean e2e * Improve E2E setup * Prettier * Log * Fix: should pull test account from unique identifier like email, username or id; not the display name * Source env vars in playwright directly * Clean e2e data * Clean test account id to be the same for email and username * Fix import warning * Add error handling * Add log * Temp remove env load * Update * Add logs and safeguards against using remote supabase during e2e tests * Fix playwright report path in C@ * Remove locale log * Check if userInformationFromDb loading with name instead of username was the issue * Remove login log * Check if initial work area names were the issue * Ignore if no files found * Cache Firebase emulators in CI * Reload env vars in playwright * It did not break tests... * Clean verifyWorkArea * Add caching for node modules in CI * Add caching for node modules in CI (2) * Do not raise if emulator not running during db seed * Do not raise if using firebase emulator * Fix supabase cache in CI * Add Cache Playwright browsers in CI * Fix * Test cache * Turn off unused supabase services to speed things up * Back to good one * Set CI=true * api is required for client connection * Add safeguards for missing supabase env vars * Remove echo * Remove supabase cache --------- Co-authored-by: Martin Braquet <martin.braquet@gmail.com>
108 lines
3.5 KiB
TypeScript
108 lines
3.5 KiB
TypeScript
import axios from 'axios'
|
|
import {createSomeNotifications} from 'backend/api/src/create-notification'
|
|
import {tryCatch} from 'common/util/try-catch'
|
|
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
|
import {insert} from 'shared/supabase/utils'
|
|
|
|
import UserAccountInformation from '../backend/utils/userInformation'
|
|
import {config} from '../web/SPEC_CONFIG'
|
|
import {seedDatabase} from './seedDatabase'
|
|
|
|
async function createAuth(email: string, password: string) {
|
|
const base = 'http://localhost:9099/identitytoolkit.googleapis.com/v1'
|
|
|
|
try {
|
|
const response = await axios.post(`${base}/accounts:signUp?key=fake-api-key`, {
|
|
email: email,
|
|
password: password,
|
|
returnSecureToken: true,
|
|
})
|
|
const userId = response.data.localId
|
|
console.log('User created in Firebase Auth:', email, userId)
|
|
return userId
|
|
} catch (err: any) {
|
|
if (
|
|
err.response?.status === 400 ||
|
|
err.response?.data?.error?.message?.includes('EMAIL_EXISTS')
|
|
) {
|
|
return
|
|
}
|
|
if (err.code === 'ECONNREFUSED') return
|
|
// throw Error('Firebase emulator not running. Start it with:\n yarn test:e2e:services\n')
|
|
console.log(err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
async function seedCompatibilityPrompts(pg: any, userId: string | null = null) {
|
|
// Need some prompts to prevent the onboarding from stopping once it reaches them (just after profile creation)
|
|
const compatibilityPrompts = [
|
|
{
|
|
question: 'What is your favorite color?',
|
|
options: {Blue: 0, Green: 1, Red: 2},
|
|
},
|
|
{
|
|
question: 'What is your favorite animal?',
|
|
options: {Dog: 0, Cat: 1, Bird: 2},
|
|
},
|
|
{
|
|
question: 'What is your preferred time of day?',
|
|
options: {Morning: 0, Afternoon: 1, Night: 2},
|
|
},
|
|
{
|
|
question: 'What type of movies do you enjoy most?',
|
|
options: {Action: 0, Comedy: 1, Drama: 2},
|
|
},
|
|
]
|
|
for (let i = 0; i < compatibilityPrompts.length; i++) {
|
|
const {data, error} = await tryCatch(
|
|
insert(pg, 'compatibility_prompts', {
|
|
creator_id: userId,
|
|
question: compatibilityPrompts[i].question,
|
|
answer_type: 'compatibility_multiple_choice',
|
|
multiple_choice_options: compatibilityPrompts[i].options,
|
|
}),
|
|
)
|
|
console.log('Compatibility prompts created', {data, error})
|
|
}
|
|
}
|
|
|
|
async function seedNotifications() {
|
|
await createSomeNotifications()
|
|
console.log('Notifications created', {})
|
|
}
|
|
|
|
type ProfileType = 'basic' | 'medium' | 'full'
|
|
;(async () => {
|
|
const pg = createSupabaseDirectClient()
|
|
|
|
//Edit the count seedConfig to specify the amount of each profiles to create
|
|
const seedConfig = [
|
|
{count: 8, profileType: 'basic' as ProfileType},
|
|
{count: 8, profileType: 'medium' as ProfileType},
|
|
{count: 8, profileType: 'full' as ProfileType},
|
|
]
|
|
|
|
for (const {count, profileType} of seedConfig) {
|
|
for (let i = 0; i < count; i++) {
|
|
const userInfo = new UserAccountInformation()
|
|
if (i == 0 && profileType === 'full') {
|
|
// Seed the first profile with deterministic data for the e2e tests
|
|
userInfo.name = 'Franklin Buckridge'
|
|
userInfo.email = config.USERS.DEV_1.EMAIL
|
|
userInfo.password = config.USERS.DEV_1.PASSWORD
|
|
}
|
|
userInfo.user_id = await createAuth(userInfo.email, userInfo.password)
|
|
if (userInfo.user_id) {
|
|
console.log('User created in Supabase:', userInfo.email)
|
|
await seedDatabase(pg, userInfo, profileType)
|
|
}
|
|
}
|
|
}
|
|
|
|
await seedCompatibilityPrompts(pg)
|
|
await seedNotifications()
|
|
|
|
process.exit(0)
|
|
})()
|