1
0
Fork 0
mirror of synced 2024-07-15 11:15:59 +12:00

PR comments.

This commit is contained in:
mike12345567 2023-02-01 13:01:38 +00:00
parent f4379fcb4f
commit 048cf8f188
3 changed files with 26 additions and 12 deletions

View file

@ -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

View file

@ -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(

View file

@ -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)
}
}