PR comments.
This commit is contained in:
parent
f4379fcb4f
commit
048cf8f188
3 changed files with 26 additions and 12 deletions
|
@ -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 {
|
export class DatabaseImpl implements Database {
|
||||||
public readonly name: string
|
public readonly name: string
|
||||||
private static nano: Nano.ServerScope
|
private static nano: Nano.ServerScope
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
QueryType,
|
QueryType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { db as dbCore } from "@budibase/backend-core"
|
import { db as dbCore } from "@budibase/backend-core"
|
||||||
|
import { DatabaseWithConnection } from "@budibase/backend-core/src/db"
|
||||||
|
|
||||||
interface CouchDBConfig {
|
interface CouchDBConfig {
|
||||||
url: string
|
url: string
|
||||||
|
@ -66,11 +67,7 @@ class CouchDBIntegration implements IntegrationBase {
|
||||||
|
|
||||||
constructor(config: CouchDBConfig) {
|
constructor(config: CouchDBConfig) {
|
||||||
this.config = config
|
this.config = config
|
||||||
this.client = new dbCore.DatabaseImpl(
|
this.client = dbCore.DatabaseWithConnection(config.database, config.url)
|
||||||
config.database,
|
|
||||||
undefined,
|
|
||||||
config.url
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async query(
|
async query(
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
|
import { DatabaseWithConnection } from "@budibase/backend-core/src/db"
|
||||||
|
|
||||||
jest.mock("@budibase/backend-core", () => {
|
jest.mock("@budibase/backend-core", () => {
|
||||||
const core = jest.requireActual("@budibase/backend-core")
|
const core = jest.requireActual("@budibase/backend-core")
|
||||||
return {
|
return {
|
||||||
...core,
|
...core,
|
||||||
db: {
|
db: {
|
||||||
...core.db,
|
...core.db,
|
||||||
DatabaseImpl: function () {
|
DatabaseWithConnection: function () {
|
||||||
this.post = jest.fn()
|
return {
|
||||||
this.allDocs = jest.fn().mockReturnValue({ rows: [] })
|
post: jest.fn(),
|
||||||
this.put = jest.fn()
|
allDocs: jest.fn().mockReturnValue({ rows: [] }),
|
||||||
this.get = jest.fn().mockReturnValue({ _rev: "a" })
|
put: jest.fn(),
|
||||||
this.remove = jest.fn()
|
get: jest.fn().mockReturnValue({ _rev: "a" }),
|
||||||
|
remove: jest.fn(),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -20,7 +24,9 @@ import { default as CouchDBIntegration } from "../couchdb"
|
||||||
class TestConfiguration {
|
class TestConfiguration {
|
||||||
integration: any
|
integration: any
|
||||||
|
|
||||||
constructor(config: any = {}) {
|
constructor(
|
||||||
|
config: any = { url: "http://somewhere", database: "something" }
|
||||||
|
) {
|
||||||
this.integration = new CouchDBIntegration.integration(config)
|
this.integration = new CouchDBIntegration.integration(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue