test: fix mongodb destroy
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
"@payloadcms/eslint-config": "workspace:*",
|
"@payloadcms/eslint-config": "workspace:*",
|
||||||
"@types/mongoose-aggregate-paginate-v2": "1.0.9",
|
"@types/mongoose-aggregate-paginate-v2": "1.0.9",
|
||||||
"mongodb": "4.17.1",
|
"mongodb": "4.17.1",
|
||||||
"mongodb-memory-server": "8.13.0",
|
"mongodb-memory-server": "^9",
|
||||||
"payload": "workspace:*"
|
"payload": "workspace:*"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import type { MongooseAdapter } from './index.js'
|
|||||||
|
|
||||||
export const destroy: Destroy = async function destroy(this: MongooseAdapter) {
|
export const destroy: Destroy = async function destroy(this: MongooseAdapter) {
|
||||||
if (this.mongoMemoryServer) {
|
if (this.mongoMemoryServer) {
|
||||||
this.mongoMemoryServer.stop()
|
await this.mongoMemoryServer.stop()
|
||||||
|
} else {
|
||||||
|
await mongoose.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
await mongoose.disconnect()
|
|
||||||
Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))
|
Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { TransactionOptions } from 'mongodb'
|
import type { TransactionOptions } from 'mongodb'
|
||||||
|
import type { MongoMemoryReplSet } from 'mongodb-memory-server'
|
||||||
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'
|
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'
|
||||||
@@ -52,7 +53,7 @@ export interface Args {
|
|||||||
/**
|
/**
|
||||||
* typed as any to avoid dependency
|
* typed as any to avoid dependency
|
||||||
*/
|
*/
|
||||||
mongoMemoryServer?: any
|
mongoMemoryServer?: MongoMemoryReplSet
|
||||||
transactionOptions?: TransactionOptions | false
|
transactionOptions?: TransactionOptions | false
|
||||||
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
||||||
url: false | string
|
url: false | string
|
||||||
@@ -65,7 +66,7 @@ export type MongooseAdapter = BaseDatabaseAdapter &
|
|||||||
}
|
}
|
||||||
connection: Connection
|
connection: Connection
|
||||||
globals: GlobalModel
|
globals: GlobalModel
|
||||||
mongoMemoryServer: any
|
mongoMemoryServer: MongoMemoryReplSet
|
||||||
sessions: Record<number | string, ClientSession>
|
sessions: Record<number | string, ClientSession>
|
||||||
versions: {
|
versions: {
|
||||||
[slug: string]: CollectionModel
|
[slug: string]: CollectionModel
|
||||||
@@ -81,7 +82,7 @@ declare module 'payload' {
|
|||||||
}
|
}
|
||||||
connection: Connection
|
connection: Connection
|
||||||
globals: GlobalModel
|
globals: GlobalModel
|
||||||
mongoMemoryServer: any
|
mongoMemoryServer: MongoMemoryReplSet
|
||||||
sessions: Record<number | string, ClientSession>
|
sessions: Record<number | string, ClientSession>
|
||||||
transactionOptions: TransactionOptions
|
transactionOptions: TransactionOptions
|
||||||
versions: {
|
versions: {
|
||||||
|
|||||||
Reference in New Issue
Block a user