parent
d1ca256f5a
commit
4b4b26a09a
@ -1,54 +0,0 @@
|
||||
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
|
||||
},
|
||||
},
|
||||
})
|
@ -1,51 +0,0 @@
|
||||
import { runBasicTests } from "@next-auth/adapter-test"
|
||||
import { defaultCollections, format, MongoDBAdapter, _id } from "../src"
|
||||
import { MongoClient } from "mongodb"
|
||||
|
||||
const name = "test"
|
||||
const client = new MongoClient(`mongodb://localhost:27017/${name}`)
|
||||
const clientPromise = client.connect()
|
||||
|
||||
runBasicTests({
|
||||
adapter: MongoDBAdapter(clientPromise),
|
||||
db: {
|
||||
async disconnect() {
|
||||
await client.db().dropDatabase()
|
||||
await client.close()
|
||||
},
|
||||
async user(id) {
|
||||
const user = await client
|
||||
.db()
|
||||
.collection(defaultCollections.Users)
|
||||
.findOne({ _id: _id(id) })
|
||||
|
||||
if (!user) return null
|
||||
return format.from(user)
|
||||
},
|
||||
async account(provider_providerAccountId) {
|
||||
const account = await client
|
||||
.db()
|
||||
.collection(defaultCollections.Accounts)
|
||||
.findOne(provider_providerAccountId)
|
||||
if (!account) return null
|
||||
return format.from(account)
|
||||
},
|
||||
async session(sessionToken) {
|
||||
const session = await client
|
||||
.db()
|
||||
.collection(defaultCollections.Sessions)
|
||||
.findOne({ sessionToken })
|
||||
if (!session) return null
|
||||
return format.from(session)
|
||||
},
|
||||
async verificationToken(identifier_token) {
|
||||
const token = await client
|
||||
.db()
|
||||
.collection(defaultCollections.VerificationTokens)
|
||||
.findOne(identifier_token)
|
||||
if (!token) return null
|
||||
const { _id, ...rest } = token
|
||||
return rest
|
||||
},
|
||||
},
|
||||
})
|
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CONTAINER_NAME=next-auth-mongodb-test
|
||||
|
||||
JEST_WATCH=false
|
||||
|
||||
# Is the watch flag passed to the script?
|
||||
while getopts w flag
|
||||
do
|
||||
case "${flag}" in
|
||||
w) JEST_WATCH=true;;
|
||||
*) continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Start db
|
||||
docker run -d --rm -p 27017:27017 --name ${CONTAINER_NAME} mongo
|
||||
|
||||
echo "Waiting 3 sec for db to start..."
|
||||
sleep 3
|
||||
|
||||
if $JEST_WATCH; then
|
||||
# Run jest in watch mode
|
||||
npx jest tests --watch
|
||||
# Only stop the container after jest has been quit
|
||||
docker stop "${CONTAINER_NAME}"
|
||||
else
|
||||
# Always stop container, but exit with 1 when tests are failing
|
||||
if npx jest;then
|
||||
docker stop ${CONTAINER_NAME}
|
||||
else
|
||||
docker stop ${CONTAINER_NAME} && exit 1
|
||||
fi
|
||||
fi
|
Loading…
Reference in new issue