1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 07:25:19 +02:00

Handle types and tests.

This commit is contained in:
Anthony Shew 2024-01-14 22:52:43 -07:00
parent b7e9365597
commit 55121eba08
6 changed files with 16 additions and 28 deletions

View file

@ -6,7 +6,6 @@ import { PgService } from '@maybe-finance/server/shared'
import { AccountQueryService, UserService } from '@maybe-finance/server/features'
import { resetUser } from './utils/user'
jest.mock('plaid')
jest.mock('auth0')
const prisma = new PrismaClient()

View file

@ -3,12 +3,12 @@ import prisma from '../../lib/prisma'
const EMAIL = 'test@example.com'
export async function resetUser(auth0Id = '__TEST_USER_ID__'): Promise<User> {
export async function resetUser(authId = '__TEST_USER_ID__'): Promise<User> {
const [_, [user]] = await prisma.$transaction([
prisma.$executeRaw`DELETE FROM "user" WHERE auth0_id=${auth0Id}`,
prisma.$executeRaw`DELETE FROM "user" WHERE auth_id=${authId}`,
prisma.$queryRaw<
[User]
>`INSERT INTO "user" (auth0_id, email) VALUES (${auth0Id}, ${EMAIL}) ON CONFLICT DO NOTHING RETURNING *`,
>`INSERT INTO "user" (auth_id, email) VALUES (${authId}, ${EMAIL}) ON CONFLICT DO NOTHING RETURNING *`,
])
return user

View file

@ -82,6 +82,7 @@ app.get('/', (req, res) => {
res.render('pages/index', { error: req.query.error })
})
// TODO: Replace "admin" concept from Auth0 with next-auth
// Only Auth0 users with a role of "admin" can view these pages (i.e. Maybe Employees)
app.use(express.static(__dirname + '/assets'))

View file

@ -302,10 +302,15 @@ async function getCurrentUser(jwt: NonNullable<Request['user']>) {
return {
...user,
roles: jwt[SharedType.Auth0CustomNamespace.Roles] ?? [],
primaryIdentity: jwt[SharedType.Auth0CustomNamespace.PrimaryIdentity] ?? {},
userMetadata: jwt[SharedType.Auth0CustomNamespace.UserMetadata] ?? {},
appMetadata: jwt[SharedType.Auth0CustomNamespace.AppMetadata] ?? {},
// TODO: Replace Auth0 concepts with next-auth
roles: [],
primaryIdentity: {},
userMetadata: {},
appMetadata: {},
// roles: jwt[SharedType.Auth0CustomNamespace.Roles] ?? [],
// primaryIdentity: jwt[SharedType.Auth0CustomNamespace.PrimaryIdentity] ?? {},
// userMetadata: jwt[SharedType.Auth0CustomNamespace.UserMetadata] ?? {},
// appMetadata: jwt[SharedType.Auth0CustomNamespace.AppMetadata] ?? {},
}
}

View file

@ -1,12 +1,9 @@
import type { PrismaClient, User } from '@prisma/client'
export async function resetUser(
prisma: PrismaClient,
auth0Id = 'auth0|workers-integration-test-id'
): Promise<User> {
export async function resetUser(prisma: PrismaClient, authId = 'TODO'): Promise<User> {
// eslint-disable-next-line
const [_, __, ___, user] = await prisma.$transaction([
prisma.$executeRaw`DELETE FROM "user" WHERE auth0_id=${auth0Id};`,
prisma.$executeRaw`DELETE FROM "user" WHERE auth_id=${authId};`,
// Deleting a user does not cascade to securities, so delete all security records
prisma.$executeRaw`DELETE from security;`,
@ -14,7 +11,7 @@ export async function resetUser(
prisma.user.create({
data: {
auth0Id,
authId,
email: 'test@example.com',
finicityCustomerId: 'TEST',
},

14
custom-express.d.ts vendored
View file

@ -13,19 +13,5 @@ declare global {
json(data: any): Send<Response, this>
superjson(data: any): Send<Response, this>
}
// express-jwt already adds a `user` prop to `req` object, we just need to define it
// This is the structure of the Auth0 user object - https://auth0.com/docs/users/user-profiles/user-profile-structure
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/96d20a6a47593b83b0331a0a3f163a39aba523aa/types/express-jwt/index.d.ts#L69
interface User
extends Partial<{
iss: string
sub: string
aud: string[]
iat: number
exp: number
azp: string
scope: string
}> {}
}
}