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:
parent
b7e9365597
commit
55121eba08
6 changed files with 16 additions and 28 deletions
|
@ -6,7 +6,6 @@ import { PgService } from '@maybe-finance/server/shared'
|
||||||
import { AccountQueryService, UserService } from '@maybe-finance/server/features'
|
import { AccountQueryService, UserService } from '@maybe-finance/server/features'
|
||||||
import { resetUser } from './utils/user'
|
import { resetUser } from './utils/user'
|
||||||
jest.mock('plaid')
|
jest.mock('plaid')
|
||||||
jest.mock('auth0')
|
|
||||||
|
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ import prisma from '../../lib/prisma'
|
||||||
|
|
||||||
const EMAIL = 'test@example.com'
|
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([
|
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<
|
prisma.$queryRaw<
|
||||||
[User]
|
[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
|
return user
|
||||||
|
|
|
@ -82,6 +82,7 @@ app.get('/', (req, res) => {
|
||||||
res.render('pages/index', { error: req.query.error })
|
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)
|
// Only Auth0 users with a role of "admin" can view these pages (i.e. Maybe Employees)
|
||||||
app.use(express.static(__dirname + '/assets'))
|
app.use(express.static(__dirname + '/assets'))
|
||||||
|
|
||||||
|
|
|
@ -302,10 +302,15 @@ async function getCurrentUser(jwt: NonNullable<Request['user']>) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...user,
|
...user,
|
||||||
roles: jwt[SharedType.Auth0CustomNamespace.Roles] ?? [],
|
// TODO: Replace Auth0 concepts with next-auth
|
||||||
primaryIdentity: jwt[SharedType.Auth0CustomNamespace.PrimaryIdentity] ?? {},
|
roles: [],
|
||||||
userMetadata: jwt[SharedType.Auth0CustomNamespace.UserMetadata] ?? {},
|
primaryIdentity: {},
|
||||||
appMetadata: jwt[SharedType.Auth0CustomNamespace.AppMetadata] ?? {},
|
userMetadata: {},
|
||||||
|
appMetadata: {},
|
||||||
|
// roles: jwt[SharedType.Auth0CustomNamespace.Roles] ?? [],
|
||||||
|
// primaryIdentity: jwt[SharedType.Auth0CustomNamespace.PrimaryIdentity] ?? {},
|
||||||
|
// userMetadata: jwt[SharedType.Auth0CustomNamespace.UserMetadata] ?? {},
|
||||||
|
// appMetadata: jwt[SharedType.Auth0CustomNamespace.AppMetadata] ?? {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import type { PrismaClient, User } from '@prisma/client'
|
import type { PrismaClient, User } from '@prisma/client'
|
||||||
|
|
||||||
export async function resetUser(
|
export async function resetUser(prisma: PrismaClient, authId = 'TODO'): Promise<User> {
|
||||||
prisma: PrismaClient,
|
|
||||||
auth0Id = 'auth0|workers-integration-test-id'
|
|
||||||
): Promise<User> {
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const [_, __, ___, user] = await prisma.$transaction([
|
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
|
// Deleting a user does not cascade to securities, so delete all security records
|
||||||
prisma.$executeRaw`DELETE from security;`,
|
prisma.$executeRaw`DELETE from security;`,
|
||||||
|
@ -14,7 +11,7 @@ export async function resetUser(
|
||||||
|
|
||||||
prisma.user.create({
|
prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
auth0Id,
|
authId,
|
||||||
email: 'test@example.com',
|
email: 'test@example.com',
|
||||||
finicityCustomerId: 'TEST',
|
finicityCustomerId: 'TEST',
|
||||||
},
|
},
|
||||||
|
|
14
custom-express.d.ts
vendored
14
custom-express.d.ts
vendored
|
@ -13,19 +13,5 @@ declare global {
|
||||||
json(data: any): Send<Response, this>
|
json(data: any): Send<Response, this>
|
||||||
superjson(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
|
|
||||||
}> {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue