Get lint passing.
This commit is contained in:
parent
7a63dc9830
commit
1785f3af7e
|
@ -265,6 +265,7 @@ describe("docWritethrough", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// This is not yet supported
|
// This is not yet supported
|
||||||
|
// eslint-disable-next-line jest/no-disabled-tests
|
||||||
it.skip("patches will execute in order", async () => {
|
it.skip("patches will execute in order", async () => {
|
||||||
let incrementalValue = 0
|
let incrementalValue = 0
|
||||||
const keyToOverride = generator.word()
|
const keyToOverride = generator.word()
|
||||||
|
|
|
@ -11,7 +11,6 @@ export const buildMatcherRegex = (
|
||||||
return patterns.map(pattern => {
|
return patterns.map(pattern => {
|
||||||
let route = pattern.route
|
let route = pattern.route
|
||||||
const method = pattern.method
|
const method = pattern.method
|
||||||
const strict = pattern.strict ? pattern.strict : false
|
|
||||||
|
|
||||||
// if there is a param in the route
|
// if there is a param in the route
|
||||||
// use a wildcard pattern
|
// use a wildcard pattern
|
||||||
|
@ -24,24 +23,17 @@ export const buildMatcherRegex = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { regex: new RegExp(route), method, strict, route }
|
return { regex: new RegExp(route), method, route }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const matches = (ctx: BBContext, options: RegexMatcher[]) => {
|
export const matches = (ctx: BBContext, options: RegexMatcher[]) => {
|
||||||
return options.find(({ regex, method, strict, route }) => {
|
return options.find(({ regex, method, route }) => {
|
||||||
let urlMatch
|
const urlMatch = regex.test(ctx.request.url)
|
||||||
if (strict) {
|
|
||||||
urlMatch = ctx.request.url === route
|
|
||||||
} else {
|
|
||||||
urlMatch = regex.test(ctx.request.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
const methodMatch =
|
const methodMatch =
|
||||||
method === "ALL"
|
method === "ALL"
|
||||||
? true
|
? true
|
||||||
: ctx.request.method.toLowerCase() === method.toLowerCase()
|
: ctx.request.method.toLowerCase() === method.toLowerCase()
|
||||||
|
|
||||||
return urlMatch && methodMatch
|
return urlMatch && methodMatch
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,23 +34,6 @@ describe("matchers", () => {
|
||||||
expect(!!matchers.matches(ctx, built)).toBe(true)
|
expect(!!matchers.matches(ctx, built)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("doesn't wildcard path with strict", () => {
|
|
||||||
const pattern = [
|
|
||||||
{
|
|
||||||
route: "/api/tests",
|
|
||||||
method: "POST",
|
|
||||||
strict: true,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
const ctx = structures.koa.newContext()
|
|
||||||
ctx.request.url = "/api/tests/id/something/else"
|
|
||||||
ctx.request.method = "POST"
|
|
||||||
|
|
||||||
const built = matchers.buildMatcherRegex(pattern)
|
|
||||||
|
|
||||||
expect(!!matchers.matches(ctx, built)).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("matches with param", () => {
|
it("matches with param", () => {
|
||||||
const pattern = [
|
const pattern = [
|
||||||
{
|
{
|
||||||
|
@ -67,23 +50,6 @@ describe("matchers", () => {
|
||||||
expect(!!matchers.matches(ctx, built)).toBe(true)
|
expect(!!matchers.matches(ctx, built)).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Support the below behaviour
|
|
||||||
// Strict does not work when a param is present
|
|
||||||
// it("matches with param with strict", () => {
|
|
||||||
// const pattern = [{
|
|
||||||
// route: "/api/tests/:testId",
|
|
||||||
// method: "GET",
|
|
||||||
// strict: true
|
|
||||||
// }]
|
|
||||||
// const ctx = structures.koa.newContext()
|
|
||||||
// ctx.request.url = "/api/tests/id"
|
|
||||||
// ctx.request.method = "GET"
|
|
||||||
//
|
|
||||||
// const built = matchers.buildMatcherRegex(pattern)
|
|
||||||
//
|
|
||||||
// expect(!!matchers.matches(ctx, built)).toBe(true)
|
|
||||||
// })
|
|
||||||
|
|
||||||
it("doesn't match by path", () => {
|
it("doesn't match by path", () => {
|
||||||
const pattern = [
|
const pattern = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -245,7 +245,10 @@ describe("/queries", () => {
|
||||||
expect(responseBody.rows.length).toEqual(1)
|
expect(responseBody.rows.length).toEqual(1)
|
||||||
expect(events.query.previewed).toHaveBeenCalledTimes(1)
|
expect(events.query.previewed).toHaveBeenCalledTimes(1)
|
||||||
delete datasource.config
|
delete datasource.config
|
||||||
expect(events.query.previewed).toHaveBeenCalledWith(datasource, queryPreview)
|
expect(events.query.previewed).toHaveBeenCalledWith(
|
||||||
|
datasource,
|
||||||
|
queryPreview
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
|
|
@ -135,9 +135,9 @@ describe("migrations", () => {
|
||||||
expect(events.backfill.tenantSucceeded).toHaveBeenCalledTimes(1)
|
expect(events.backfill.tenantSucceeded).toHaveBeenCalledTimes(1)
|
||||||
|
|
||||||
// to make sure caching is working as expected
|
// to make sure caching is working as expected
|
||||||
expect(events.processors.analyticsProcessor.processEvent).toHaveBeenCalledTimes(
|
expect(
|
||||||
19
|
events.processors.analyticsProcessor.processEvent
|
||||||
)
|
).toHaveBeenCalledTimes(19)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -110,9 +110,7 @@ describe("bbReferenceProcessor", () => {
|
||||||
config.doInTenant(() =>
|
config.doInTenant(() =>
|
||||||
processInputBBReferences(userIdCsv, FieldSubtype.USER)
|
processInputBBReferences(userIdCsv, FieldSubtype.USER)
|
||||||
)
|
)
|
||||||
).rejects.toThrow(
|
).rejects.toThrow(new InvalidBBRefError(wrongId, FieldSubtype.USER))
|
||||||
new InvalidBBRefError(wrongId, FieldSubtype.USER)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validate valid user object", async () => {
|
it("validate valid user object", async () => {
|
||||||
|
|
|
@ -62,7 +62,9 @@ describe("rowProcessor - inputProcessing", () => {
|
||||||
|
|
||||||
const { row } = await inputProcessing(userId, table, newRow)
|
const { row } = await inputProcessing(userId, table, newRow)
|
||||||
|
|
||||||
expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledTimes(1)
|
expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledTimes(
|
||||||
|
1
|
||||||
|
)
|
||||||
expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledWith(
|
expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledWith(
|
||||||
"123",
|
"123",
|
||||||
"user"
|
"user"
|
||||||
|
@ -150,7 +152,9 @@ describe("rowProcessor - inputProcessing", () => {
|
||||||
|
|
||||||
const { row } = await inputProcessing(userId, table, newRow)
|
const { row } = await inputProcessing(userId, table, newRow)
|
||||||
|
|
||||||
expect(bbReferenceProcessor.processInputBBReferences).not.toHaveBeenCalled()
|
expect(
|
||||||
|
bbReferenceProcessor.processInputBBReferences
|
||||||
|
).not.toHaveBeenCalled()
|
||||||
expect(row).toEqual(newRow)
|
expect(row).toEqual(newRow)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -64,7 +64,9 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
|
|
||||||
expect(result).toEqual({ name: "Jack", user })
|
expect(result).toEqual({ name: "Jack", user })
|
||||||
|
|
||||||
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledTimes(1)
|
expect(
|
||||||
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
|
).toHaveBeenCalledTimes(1)
|
||||||
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith(
|
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith(
|
||||||
"123",
|
"123",
|
||||||
FieldSubtype.USER
|
FieldSubtype.USER
|
||||||
|
@ -150,7 +152,9 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
|
|
||||||
expect(result).toEqual({ name: "Jack" })
|
expect(result).toEqual({ name: "Jack" })
|
||||||
|
|
||||||
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledTimes(1)
|
expect(
|
||||||
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
|
).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("does not fetch bb references when not in the schema", async () => {
|
it("does not fetch bb references when not in the schema", async () => {
|
||||||
|
@ -189,6 +193,8 @@ describe("rowProcessor - outputProcessing", () => {
|
||||||
|
|
||||||
expect(result).toEqual({ name: "Jack", user: "123" })
|
expect(result).toEqual({ name: "Jack", user: "123" })
|
||||||
|
|
||||||
expect(bbReferenceProcessor.processOutputBBReferences).not.toHaveBeenCalled()
|
expect(
|
||||||
|
bbReferenceProcessor.processOutputBBReferences
|
||||||
|
).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,15 +8,10 @@ export interface EndpointMatcher {
|
||||||
* ALL is also accepted to cover all verbs.
|
* ALL is also accepted to cover all verbs.
|
||||||
*/
|
*/
|
||||||
method: string
|
method: string
|
||||||
/**
|
|
||||||
* The route must match exactly - not just begins with
|
|
||||||
*/
|
|
||||||
strict?: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RegexMatcher {
|
export interface RegexMatcher {
|
||||||
regex: RegExp
|
regex: RegExp
|
||||||
method: string
|
method: string
|
||||||
strict: boolean
|
|
||||||
route: string
|
route: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,9 @@ describe("configs", () => {
|
||||||
expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
||||||
expect(events.auth.SSODeactivated).not.toHaveBeenCalled()
|
expect(events.auth.SSODeactivated).not.toHaveBeenCalled()
|
||||||
expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1)
|
expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1)
|
||||||
expect(events.auth.SSOActivated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
expect(events.auth.SSOActivated).toHaveBeenCalledWith(
|
||||||
|
ConfigType.GOOGLE
|
||||||
|
)
|
||||||
await config.deleteConfig(ConfigType.GOOGLE)
|
await config.deleteConfig(ConfigType.GOOGLE)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -88,7 +90,9 @@ describe("configs", () => {
|
||||||
expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
||||||
expect(events.auth.SSOActivated).not.toHaveBeenCalled()
|
expect(events.auth.SSOActivated).not.toHaveBeenCalled()
|
||||||
expect(events.auth.SSODeactivated).toHaveBeenCalledTimes(1)
|
expect(events.auth.SSODeactivated).toHaveBeenCalledTimes(1)
|
||||||
expect(events.auth.SSODeactivated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
expect(events.auth.SSODeactivated).toHaveBeenCalledWith(
|
||||||
|
ConfigType.GOOGLE
|
||||||
|
)
|
||||||
await config.deleteConfig(ConfigType.GOOGLE)
|
await config.deleteConfig(ConfigType.GOOGLE)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -104,7 +108,9 @@ describe("configs", () => {
|
||||||
expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
||||||
expect(events.auth.SSODeactivated).not.toHaveBeenCalled()
|
expect(events.auth.SSODeactivated).not.toHaveBeenCalled()
|
||||||
expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1)
|
expect(events.auth.SSOActivated).toHaveBeenCalledTimes(1)
|
||||||
expect(events.auth.SSOActivated).toHaveBeenCalledWith(ConfigType.GOOGLE)
|
expect(events.auth.SSOActivated).toHaveBeenCalledWith(
|
||||||
|
ConfigType.GOOGLE
|
||||||
|
)
|
||||||
await config.deleteConfig(ConfigType.GOOGLE)
|
await config.deleteConfig(ConfigType.GOOGLE)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -154,7 +160,9 @@ describe("configs", () => {
|
||||||
expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.OIDC)
|
expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.OIDC)
|
||||||
expect(events.auth.SSOActivated).not.toHaveBeenCalled()
|
expect(events.auth.SSOActivated).not.toHaveBeenCalled()
|
||||||
expect(events.auth.SSODeactivated).toHaveBeenCalledTimes(1)
|
expect(events.auth.SSODeactivated).toHaveBeenCalledTimes(1)
|
||||||
expect(events.auth.SSODeactivated).toHaveBeenCalledWith(ConfigType.OIDC)
|
expect(events.auth.SSODeactivated).toHaveBeenCalledWith(
|
||||||
|
ConfigType.OIDC
|
||||||
|
)
|
||||||
await config.deleteConfig(ConfigType.OIDC)
|
await config.deleteConfig(ConfigType.OIDC)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,9 @@ describe("/api/global/license", () => {
|
||||||
licenseKey: "licenseKey",
|
licenseKey: "licenseKey",
|
||||||
})
|
})
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(licensing.keys.activateLicenseKey).toHaveBeenCalledWith("licenseKey")
|
expect(licensing.keys.activateLicenseKey).toHaveBeenCalledWith(
|
||||||
|
"licenseKey"
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -74,9 +76,9 @@ describe("/api/global/license", () => {
|
||||||
const res = await config.api.license.activateOfflineLicense({
|
const res = await config.api.license.activateOfflineLicense({
|
||||||
offlineLicenseToken: "offlineLicenseToken",
|
offlineLicenseToken: "offlineLicenseToken",
|
||||||
})
|
})
|
||||||
expect(licensing.offline.activateOfflineLicenseToken).toHaveBeenCalledWith(
|
expect(
|
||||||
"offlineLicenseToken"
|
licensing.offline.activateOfflineLicenseToken
|
||||||
)
|
).toHaveBeenCalledWith("offlineLicenseToken")
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -102,7 +104,9 @@ describe("/api/global/license", () => {
|
||||||
it("returns 204", async () => {
|
it("returns 204", async () => {
|
||||||
const res = await config.api.license.deleteOfflineLicense()
|
const res = await config.api.license.deleteOfflineLicense()
|
||||||
expect(res.status).toBe(204)
|
expect(res.status).toBe(204)
|
||||||
expect(licensing.offline.deleteOfflineLicenseToken).toHaveBeenCalledTimes(1)
|
expect(licensing.offline.deleteOfflineLicenseToken).toHaveBeenCalledTimes(
|
||||||
|
1
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue