Skip to content

Commit

Permalink
fix(mikro-orm): re-enable tests (#5316)
Browse files Browse the repository at this point in the history
  • Loading branch information
boredland committed Sep 21, 2022
1 parent 44f2a47 commit 902bf92
Show file tree
Hide file tree
Showing 10 changed files with 1,599 additions and 178 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"build:app": "turbo run build --filter=next-auth-app --include-dependencies",
"build": "turbo run build --filter=next-auth --filter=@next-auth/* --no-deps",
"lint": "turbo run lint --filter=!next-auth-docs --parallel",
"test": "turbo run test --concurrency=1 --filter=!@next-auth/pouchdb-adapter --filter=!@next-auth/mikro-orm-adapter --filter=!@next-auth/upstash-redis-adapter --filter=!next-auth-* --filter=[HEAD^1]",
"test": "turbo run test --concurrency=1 --filter=!@next-auth/pouchdb-adapter --filter=!@next-auth/upstash-redis-adapter --filter=!next-auth-* --filter=[HEAD^1]",
"clean": "turbo run clean --no-cache",
"dev:app": "turbo run dev --parallel --continue --filter=next-auth-app...",
"dev:docs": "turbo run dev --filter=next-auth-docs",
Expand Down
16 changes: 8 additions & 8 deletions packages/adapter-mikro-orm/package.json
Expand Up @@ -32,22 +32,22 @@
"dist"
],
"peerDependencies": {
"@mikro-orm/core": "^5.0.2",
"@mikro-orm/core": "^5",
"next-auth": "^4"
},
"devDependencies": {
"@mikro-orm/core": "^5.0.2",
"@mikro-orm/sqlite": "^5.0.2",
"@mikro-orm/core": "^5",
"@mikro-orm/sqlite": "^5",
"@next-auth/adapter-test": "workspace:*",
"@next-auth/tsconfig": "workspace:*",
"@types/uuid": "^8.3.3",
"jest": "^27.4.3",
"@types/uuid": ">=8",
"jest": "^29",
"next-auth": "workspace:*"
},
"dependencies": {
"uuid": "^9"
},
"jest": {
"preset": "@next-auth/adapter-test/jest"
},
"dependencies": {
"uuid": "^8.3.2"
}
}
61 changes: 32 additions & 29 deletions packages/adapter-mikro-orm/src/entities.ts
Expand Up @@ -9,6 +9,7 @@ import {
OneToMany,
Collection,
ManyToOne,
types,
} from "@mikro-orm/core"

import type { DefaultAccount } from "next-auth"
Expand All @@ -29,55 +30,56 @@ export class User implements RemoveIndex<AdapterUser> {
@PrimaryKey()
id: string = randomUUID()

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
name?: string

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
@Unique()
email?: string

@Property({ type: "Date", nullable: true })
@Property({ type: types.datetime, nullable: true })
emailVerified: Date | null = null

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
image?: string

@OneToMany({
entity: () => Session,
mappedBy: (session) => session.user,
entity: 'Session',
mappedBy: (session: Session) => session.user,
hidden: true,
orphanRemoval: true,
})
sessions = new Collection<Session>(this)
sessions = new Collection<Session, object>(this)

@OneToMany({
entity: () => Account,
mappedBy: (account) => account.user,
entity: 'Account',
mappedBy: (account: Account) => account.user,
hidden: true,
orphanRemoval: true,
})
accounts = new Collection<Account>(this)
accounts = new Collection<Account, object>(this)
}

@Entity()
export class Session implements AdapterSession {
@PrimaryKey()
@Property({ type: types.string })
id: string = randomUUID()

@ManyToOne({
entity: () => User,
entity: 'User',
hidden: true,
onDelete: "cascade",
})
user!: User

@Property({ persist: false })
@Property({ type: types.string, persist: false })
userId!: string

@Property()
@Property({ type: 'Date' })
expires!: Date

@Property()
@Property({ type: types.string })
@Unique()
sessionToken!: string
}
Expand All @@ -86,59 +88,60 @@ export class Session implements AdapterSession {
@Unique({ properties: ["provider", "providerAccountId"] })
export class Account implements RemoveIndex<DefaultAccount> {
@PrimaryKey()
@Property({ type: types.string })
id: string = randomUUID()

@ManyToOne({
entity: () => User,
entity: 'User',
hidden: true,
onDelete: "cascade",
})
user!: User

@Property({ persist: false })
@Property({ type: types.string, persist: false })
userId!: string

@Enum()
@Property({ type: types.string })
type!: ProviderType

@Property()
@Property({ type: types.string })
provider!: string

@Property()
@Property({ type: types.string })
providerAccountId!: string

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
refresh_token?: string

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
access_token?: string

@Property({ nullable: true })
@Property({ type: types.integer, nullable: true })
expires_at?: number

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
token_type?: string

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
scope?: string

@Property({ nullable: true })
@Property({ type: types.text, nullable: true })
id_token?: string

@Property({ nullable: true })
@Property({ type: types.string, nullable: true })
session_state?: string
}

@Entity()
@Unique({ properties: ["token", "identifier"] })
export class VerificationToken implements AdapterVerificationToken {
@PrimaryKey()
@Property()
@Property({ type: types.string })
token!: string

@Property()
@Property({ type: 'Date' })
expires!: Date

@Property()
@Property({ type: types.string })
identifier!: string
}

0 comments on commit 902bf92

Please sign in to comment.