PR comments.
This commit is contained in:
parent
f4379fcb4f
commit
048cf8f188
|
@ -29,6 +29,17 @@ function buildNano(couchInfo: { url: string; cookie: string }) {
|
|||
})
|
||||
}
|
||||
|
||||
export function DatabaseWithConnection(
|
||||
dbName: string,
|
||||
connection: string,
|
||||
opts?: DatabaseOpts
|
||||
) {
|
||||
if (!connection) {
|
||||
throw new Error("Must provide connection details")
|
||||
}
|
||||
return new DatabaseImpl(dbName, opts, connection)
|
||||
}
|
||||
|
||||
export class DatabaseImpl implements Database {
|
||||
public readonly name: string
|
||||
private static nano: Nano.ServerScope
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
QueryType,
|
||||
} from "@budibase/types"
|
||||
import { db as dbCore } from "@budibase/backend-core"
|
||||
import { DatabaseWithConnection } from "@budibase/backend-core/src/db"
|
||||
|
||||
interface CouchDBConfig {
|
||||
url: string
|
||||
|
@ -66,11 +67,7 @@ class CouchDBIntegration implements IntegrationBase {
|
|||
|
||||
constructor(config: CouchDBConfig) {
|
||||
this.config = config
|
||||
this.client = new dbCore.DatabaseImpl(
|
||||
config.database,
|
||||
undefined,
|
||||
config.url
|
||||
)
|
||||
this.client = dbCore.DatabaseWithConnection(config.database, config.url)
|
||||
}
|
||||
|
||||
async query(
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
import { DatabaseWithConnection } from "@budibase/backend-core/src/db"
|
||||
|
||||
jest.mock("@budibase/backend-core", () => {
|
||||
const core = jest.requireActual("@budibase/backend-core")
|
||||
return {
|
||||
...core,
|
||||
db: {
|
||||
...core.db,
|
||||
DatabaseImpl: function () {
|
||||
this.post = jest.fn()
|
||||
this.allDocs = jest.fn().mockReturnValue({ rows: [] })
|
||||
this.put = jest.fn()
|
||||
this.get = jest.fn().mockReturnValue({ _rev: "a" })
|
||||
this.remove = jest.fn()
|
||||
DatabaseWithConnection: function () {
|
||||
return {
|
||||
post: jest.fn(),
|
||||
allDocs: jest.fn().mockReturnValue({ rows: [] }),
|
||||
put: jest.fn(),
|
||||
get: jest.fn().mockReturnValue({ _rev: "a" }),
|
||||
remove: jest.fn(),
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -20,7 +24,9 @@ import { default as CouchDBIntegration } from "../couchdb"
|
|||
class TestConfiguration {
|
||||
integration: any
|
||||
|
||||
constructor(config: any = {}) {
|
||||
constructor(
|
||||
config: any = { url: "http://somewhere", database: "something" }
|
||||
) {
|
||||
this.integration = new CouchDBIntegration.integration(config)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue