Files
archived-next-auth/packages/adapter-mongodb/tests/custom.test.ts
Thang Vu 4f29d39521 chore: move to pnpm (#4420)
* feat: pnpm

* Update publish script

* gitignore the pnpm debug log

* Fix workspace

* Fix dev commands

* feat: pnpm

* Update publish script

* gitignore the pnpm debug log

* Fix workspace

* Fix dev commands

* chore: fix pnpm install in GitHub Action

* fix: update tsconfig path

* pnpm run -> pnpm

* chore: remove cache-node and add back setup-node

* fix: tsconfig dependencies

* chore: fix tsconfig path

* fix: adapter-test dependencies

* fix: setup-node for release-pr

* fix: import adapter-test

* chore: update workspace dependency for next-auth

* fix: test failure

* fix: add jest for adapters

* fix: jest again

* fix: mongo in prisma

* fix: `--no-git-checks` for `release-pr`

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2022-05-03 15:05:55 +02:00

55 lines
1.5 KiB
TypeScript

import { runBasicTests } from "@next-auth/adapter-test"
import { defaultCollections, format, MongoDBAdapter, _id } from "../src"
import { MongoClient } from "mongodb"
const name = "custom-test"
const client = new MongoClient(`mongodb://localhost:27017/${name}`)
const clientPromise = client.connect()
const collections = { ...defaultCollections, Users: "some_userz" }
runBasicTests({
adapter: MongoDBAdapter(clientPromise, {
collections,
}),
db: {
async disconnect() {
await client.db().dropDatabase()
await client.close()
},
async user(id) {
const user = await client
.db()
.collection(collections.Users)
.findOne({ _id: _id(id) })
if (!user) return null
return format.from(user)
},
async account(provider_providerAccountId) {
const account = await client
.db()
.collection(collections.Accounts)
.findOne(provider_providerAccountId)
if (!account) return null
return format.from(account)
},
async session(sessionToken) {
const session = await client
.db()
.collection(collections.Sessions)
.findOne({ sessionToken })
if (!session) return null
return format.from(session)
},
async verificationToken(identifier_token) {
const token = await client
.db()
.collection(collections.VerificationTokens)
.findOne(identifier_token)
if (!token) return null
const { _id, ...rest } = token
return rest
},
},
})