lint
This commit is contained in:
parent
4f238d9c10
commit
268dd0ace5
|
@ -322,29 +322,29 @@ class MongoIntegration implements IntegrationBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async aggregate(query: { steps: any[]; extra: { [key: string]: string } }) {
|
async aggregate(query: { steps: any[]; extra: { [key: string]: string } }) {
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const db = this.client.db(this.config.db)
|
const db = this.client.db(this.config.db)
|
||||||
const collection = db.collection(query.extra.collection)
|
const collection = db.collection(query.extra.collection)
|
||||||
let response = {}
|
let response = {}
|
||||||
for await (const doc of collection.aggregate(
|
for await (const doc of collection.aggregate(
|
||||||
query.steps.map(({ key, value }) => {
|
query.steps.map(({ key, value }) => {
|
||||||
let temp: any = {}
|
let temp: any = {}
|
||||||
temp[key] = JSON.parse(value.value)
|
temp[key] = JSON.parse(value.value)
|
||||||
return temp
|
return temp
|
||||||
})
|
})
|
||||||
)) {
|
)) {
|
||||||
response = doc
|
response = doc
|
||||||
}
|
|
||||||
return response
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error writing to mongodb", err)
|
|
||||||
throw err
|
|
||||||
} finally {
|
|
||||||
await this.client.close()
|
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error writing to mongodb", err)
|
||||||
|
throw err
|
||||||
|
} finally {
|
||||||
|
await this.client.close()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -16,9 +16,7 @@ class InternalAPIClient {
|
||||||
|
|
||||||
constructor(appId?: string) {
|
constructor(appId?: string) {
|
||||||
if (!env.BUDIBASE_SERVER_URL) {
|
if (!env.BUDIBASE_SERVER_URL) {
|
||||||
throw new Error(
|
throw new Error("Must set BUDIBASE_SERVER_URL env var")
|
||||||
"Must set BUDIBASE_SERVER_URL env var"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
this.host = `${env.BUDIBASE_SERVER_URL}/api`
|
this.host = `${env.BUDIBASE_SERVER_URL}/api`
|
||||||
this.appId = appId
|
this.appId = appId
|
||||||
|
@ -55,4 +53,4 @@ class InternalAPIClient {
|
||||||
put = this.apiCall("PUT")
|
put = this.apiCall("PUT")
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InternalAPIClient
|
export default InternalAPIClient
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import {
|
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||||
Application,
|
|
||||||
} from "@budibase/server/api/controllers/public/mapping/types"
|
|
||||||
import { App } from "@budibase/types"
|
import { App } from "@budibase/types"
|
||||||
import { Response } from "node-fetch"
|
import { Response } from "node-fetch"
|
||||||
import InternalAPIClient from "./InternalAPIClient"
|
import InternalAPIClient from "./InternalAPIClient"
|
||||||
|
@ -37,9 +35,7 @@ export default class AppApi {
|
||||||
return [response, json]
|
return [response, json]
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(
|
async create(body: any): Promise<[Response, Partial<App>]> {
|
||||||
body: any
|
|
||||||
): Promise<[Response, Partial<App>]> {
|
|
||||||
const response = await this.api.post(`/applications`, { body })
|
const response = await this.api.post(`/applications`, { body })
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
return [response, json]
|
return [response, json]
|
||||||
|
|
|
@ -9,11 +9,11 @@ export default class AuthApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(): Promise<[Response, any]> {
|
async login(): Promise<[Response, any]> {
|
||||||
const response = await this.api.post(`/global/auth/default/login`, {
|
const response = await this.api.post(`/global/auth/default/login`, {
|
||||||
body: {
|
body: {
|
||||||
username: process.env.BB_ADMIN_USER_EMAIL,
|
username: process.env.BB_ADMIN_USER_EMAIL,
|
||||||
password: process.env.BB_ADMIN_USER_PASSWORD
|
password: process.env.BB_ADMIN_USER_PASSWORD,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
const cookie = response.headers.get("set-cookie")
|
const cookie = response.headers.get("set-cookie")
|
||||||
this.api.cookie = cookie as any
|
this.api.cookie = cookie as any
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import generator from "../../generator"
|
import generator from "../../generator"
|
||||||
import {
|
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
|
||||||
Application,
|
|
||||||
} from "@budibase/server/api/controllers/public/mapping/types"
|
|
||||||
|
|
||||||
|
const generate = (
|
||||||
const generate = (overrides: Partial<Application> = {}): Partial<Application> => ({
|
overrides: Partial<Application> = {}
|
||||||
|
): Partial<Application> => ({
|
||||||
name: generator.word(),
|
name: generator.word(),
|
||||||
url: `/${generator.word()}`,
|
url: `/${generator.word()}`,
|
||||||
...overrides,
|
...overrides,
|
||||||
|
|
|
@ -24,14 +24,14 @@ describe("Internal API - /applications endpoints", () => {
|
||||||
useTemplate: "true",
|
useTemplate: "true",
|
||||||
templateName: "Near Miss Register",
|
templateName: "Near Miss Register",
|
||||||
templateKey: "app/near-miss-register",
|
templateKey: "app/near-miss-register",
|
||||||
templateFile: undefined
|
templateFile: undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
it("GET - fetch applications", async () => {
|
it("GET - fetch applications", async () => {
|
||||||
await config.applications.create({
|
await config.applications.create({
|
||||||
...generateApp(),
|
...generateApp(),
|
||||||
useTemplate: false
|
useTemplate: false,
|
||||||
})
|
})
|
||||||
const [response, apps] = await config.applications.fetch()
|
const [response, apps] = await config.applications.fetch()
|
||||||
expect(response).toHaveStatusCode(200)
|
expect(response).toHaveStatusCode(200)
|
||||||
|
@ -57,7 +57,7 @@ describe("Internal API - /applications endpoints", () => {
|
||||||
expect(publish).toEqual({
|
expect(publish).toEqual({
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
appUrl: app.url,
|
appUrl: app.url,
|
||||||
status: "SUCCESS"
|
status: "SUCCESS",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -70,7 +70,8 @@ describe("Internal API - /applications endpoints", () => {
|
||||||
config.applications.api.appId = app.appId
|
config.applications.api.appId = app.appId
|
||||||
|
|
||||||
// check preview renders
|
// check preview renders
|
||||||
const [previewResponse, previewRenders] = await config.applications.canRender()
|
const [previewResponse, previewRenders] =
|
||||||
|
await config.applications.canRender()
|
||||||
expect(previewResponse).toHaveStatusCode(200)
|
expect(previewResponse).toHaveStatusCode(200)
|
||||||
expect(previewRenders).toBe(true)
|
expect(previewRenders).toBe(true)
|
||||||
|
|
||||||
|
@ -79,8 +80,8 @@ describe("Internal API - /applications endpoints", () => {
|
||||||
|
|
||||||
// check published app renders
|
// check published app renders
|
||||||
config.applications.api.appId = db.getProdAppID(app.appId)
|
config.applications.api.appId = db.getProdAppID(app.appId)
|
||||||
const [publishedAppResponse, publishedAppRenders] = await config.applications.canRender()
|
const [publishedAppResponse, publishedAppRenders] =
|
||||||
|
await config.applications.canRender()
|
||||||
expect(publishedAppRenders).toBe(true)
|
expect(publishedAppRenders).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue