mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Fix tests libs
This commit is contained in:
@@ -2,7 +2,7 @@ import axios from 'axios'
|
||||
|
||||
import {config} from '../web/SPEC_CONFIG'
|
||||
|
||||
export async function login(email: string, password: string) {
|
||||
export async function firebaseLogin(email: string, password: string) {
|
||||
const login = await axios.post(
|
||||
`${config.FIREBASE_URL.BASE}${config.FIREBASE_URL.SIGN_IN_PASSWORD}`,
|
||||
{
|
||||
@@ -13,17 +13,37 @@ export async function login(email: string, password: string) {
|
||||
)
|
||||
return login
|
||||
}
|
||||
export async function getUserId(email: string, password: string) {
|
||||
try {
|
||||
const loginInfo = await firebaseLogin(email, password)
|
||||
return loginInfo.data.localId
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
export async function signUp(email: string, password: string) {
|
||||
// const base = 'http://localhost:9099/identitytoolkit.googleapis.com/v1';
|
||||
|
||||
await axios.post(`${config.FIREBASE_URL.BASE}${config.FIREBASE_URL.SIGNUP}`, {
|
||||
email,
|
||||
password,
|
||||
returnSecureToken: true,
|
||||
})
|
||||
|
||||
console.log('Auth created for', email)
|
||||
export async function firebaseSignUp(email: string, password: string) {
|
||||
try {
|
||||
const response = await axios.post(`${config.FIREBASE_URL.BASE}${config.FIREBASE_URL.SIGNUP}`, {
|
||||
email,
|
||||
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 await getUserId(email, password)
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteAccount(login: any) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {deleteFromDb} from '../../utils/databaseUtils'
|
||||
import {deleteAccount, login} from '../../utils/firebaseUtils'
|
||||
import {deleteAccount, firebaseLogin} from '../../utils/firebaseUtils'
|
||||
|
||||
export async function deleteUser(email: string, password: string) {
|
||||
try {
|
||||
const loginInfo = await login(email, password)
|
||||
const loginInfo = await firebaseLogin(email, password)
|
||||
await deleteFromDb(loginInfo.data.localId)
|
||||
await deleteAccount(loginInfo)
|
||||
} catch (err: any) {
|
||||
|
||||
Reference in New Issue
Block a user