From 1785f3af7ebc00b3f2f2140820cbcbcb05d93f36 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 19 Mar 2024 10:55:51 +0000 Subject: [PATCH] Get lint passing. --- .../src/cache/tests/docWritethrough.spec.ts | 1 + .../backend-core/src/middleware/matchers.ts | 14 ++------ .../src/middleware/tests/matchers.spec.ts | 34 ------------------- .../routes/tests/queries/query.seq.spec.ts | 5 ++- .../server/src/migrations/tests/index.spec.ts | 6 ++-- .../tests/bbReferenceProcessor.spec.ts | 4 +-- .../tests/inputProcessing.spec.ts | 8 +++-- .../tests/outputProcessing.spec.ts | 12 +++++-- packages/types/src/sdk/middleware/matchers.ts | 5 --- .../api/routes/global/tests/configs.spec.ts | 16 ++++++--- .../api/routes/global/tests/license.spec.ts | 14 +++++--- 11 files changed, 48 insertions(+), 71 deletions(-) diff --git a/packages/backend-core/src/cache/tests/docWritethrough.spec.ts b/packages/backend-core/src/cache/tests/docWritethrough.spec.ts index 4e26aa05b8..9eb27efcad 100644 --- a/packages/backend-core/src/cache/tests/docWritethrough.spec.ts +++ b/packages/backend-core/src/cache/tests/docWritethrough.spec.ts @@ -265,6 +265,7 @@ describe("docWritethrough", () => { }) // This is not yet supported + // eslint-disable-next-line jest/no-disabled-tests it.skip("patches will execute in order", async () => { let incrementalValue = 0 const keyToOverride = generator.word() diff --git a/packages/backend-core/src/middleware/matchers.ts b/packages/backend-core/src/middleware/matchers.ts index efbdec2dbe..8bede1cc6a 100644 --- a/packages/backend-core/src/middleware/matchers.ts +++ b/packages/backend-core/src/middleware/matchers.ts @@ -11,7 +11,6 @@ export const buildMatcherRegex = ( return patterns.map(pattern => { let route = pattern.route const method = pattern.method - const strict = pattern.strict ? pattern.strict : false // if there is a param in the route // 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[]) => { - return options.find(({ regex, method, strict, route }) => { - let urlMatch - if (strict) { - urlMatch = ctx.request.url === route - } else { - urlMatch = regex.test(ctx.request.url) - } - + return options.find(({ regex, method, route }) => { + const urlMatch = regex.test(ctx.request.url) const methodMatch = method === "ALL" ? true : ctx.request.method.toLowerCase() === method.toLowerCase() - return urlMatch && methodMatch }) } diff --git a/packages/backend-core/src/middleware/tests/matchers.spec.ts b/packages/backend-core/src/middleware/tests/matchers.spec.ts index c39bbb6dd3..1b79db2e68 100644 --- a/packages/backend-core/src/middleware/tests/matchers.spec.ts +++ b/packages/backend-core/src/middleware/tests/matchers.spec.ts @@ -34,23 +34,6 @@ describe("matchers", () => { 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", () => { const pattern = [ { @@ -67,23 +50,6 @@ describe("matchers", () => { 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", () => { const pattern = [ { diff --git a/packages/server/src/api/routes/tests/queries/query.seq.spec.ts b/packages/server/src/api/routes/tests/queries/query.seq.spec.ts index e92adf7419..86df60899c 100644 --- a/packages/server/src/api/routes/tests/queries/query.seq.spec.ts +++ b/packages/server/src/api/routes/tests/queries/query.seq.spec.ts @@ -245,7 +245,10 @@ describe("/queries", () => { expect(responseBody.rows.length).toEqual(1) expect(events.query.previewed).toHaveBeenCalledTimes(1) delete datasource.config - expect(events.query.previewed).toHaveBeenCalledWith(datasource, queryPreview) + expect(events.query.previewed).toHaveBeenCalledWith( + datasource, + queryPreview + ) }) it("should apply authorization to endpoint", async () => { diff --git a/packages/server/src/migrations/tests/index.spec.ts b/packages/server/src/migrations/tests/index.spec.ts index e0203351a4..8eb59b8a0e 100644 --- a/packages/server/src/migrations/tests/index.spec.ts +++ b/packages/server/src/migrations/tests/index.spec.ts @@ -135,9 +135,9 @@ describe("migrations", () => { expect(events.backfill.tenantSucceeded).toHaveBeenCalledTimes(1) // to make sure caching is working as expected - expect(events.processors.analyticsProcessor.processEvent).toHaveBeenCalledTimes( - 19 - ) + expect( + events.processors.analyticsProcessor.processEvent + ).toHaveBeenCalledTimes(19) }) }) }) diff --git a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts index 739d253459..e6ceaae323 100644 --- a/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/bbReferenceProcessor.spec.ts @@ -110,9 +110,7 @@ describe("bbReferenceProcessor", () => { config.doInTenant(() => processInputBBReferences(userIdCsv, FieldSubtype.USER) ) - ).rejects.toThrow( - new InvalidBBRefError(wrongId, FieldSubtype.USER) - ) + ).rejects.toThrow(new InvalidBBRefError(wrongId, FieldSubtype.USER)) }) it("validate valid user object", async () => { diff --git a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts index 7d0c15049e..859a203133 100644 --- a/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/inputProcessing.spec.ts @@ -62,7 +62,9 @@ describe("rowProcessor - inputProcessing", () => { const { row } = await inputProcessing(userId, table, newRow) - expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledTimes(1) + expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledTimes( + 1 + ) expect(bbReferenceProcessor.processInputBBReferences).toHaveBeenCalledWith( "123", "user" @@ -150,7 +152,9 @@ describe("rowProcessor - inputProcessing", () => { const { row } = await inputProcessing(userId, table, newRow) - expect(bbReferenceProcessor.processInputBBReferences).not.toHaveBeenCalled() + expect( + bbReferenceProcessor.processInputBBReferences + ).not.toHaveBeenCalled() expect(row).toEqual(newRow) } ) diff --git a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts index 01814a9a09..a17bd5f393 100644 --- a/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/outputProcessing.spec.ts @@ -64,7 +64,9 @@ describe("rowProcessor - outputProcessing", () => { expect(result).toEqual({ name: "Jack", user }) - expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledTimes(1) + expect( + bbReferenceProcessor.processOutputBBReferences + ).toHaveBeenCalledTimes(1) expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith( "123", FieldSubtype.USER @@ -150,7 +152,9 @@ describe("rowProcessor - outputProcessing", () => { 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 () => { @@ -189,6 +193,8 @@ describe("rowProcessor - outputProcessing", () => { expect(result).toEqual({ name: "Jack", user: "123" }) - expect(bbReferenceProcessor.processOutputBBReferences).not.toHaveBeenCalled() + expect( + bbReferenceProcessor.processOutputBBReferences + ).not.toHaveBeenCalled() }) }) diff --git a/packages/types/src/sdk/middleware/matchers.ts b/packages/types/src/sdk/middleware/matchers.ts index fc4ceb323e..671505eb13 100644 --- a/packages/types/src/sdk/middleware/matchers.ts +++ b/packages/types/src/sdk/middleware/matchers.ts @@ -8,15 +8,10 @@ export interface EndpointMatcher { * ALL is also accepted to cover all verbs. */ method: string - /** - * The route must match exactly - not just begins with - */ - strict?: boolean } export interface RegexMatcher { regex: RegExp method: string - strict: boolean route: string } diff --git a/packages/worker/src/api/routes/global/tests/configs.spec.ts b/packages/worker/src/api/routes/global/tests/configs.spec.ts index 12c0e2ff8b..6e3558ba86 100644 --- a/packages/worker/src/api/routes/global/tests/configs.spec.ts +++ b/packages/worker/src/api/routes/global/tests/configs.spec.ts @@ -61,7 +61,9 @@ describe("configs", () => { expect(events.auth.SSOCreated).toHaveBeenCalledWith(ConfigType.GOOGLE) expect(events.auth.SSODeactivated).not.toHaveBeenCalled() 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) }) @@ -88,7 +90,9 @@ describe("configs", () => { expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE) expect(events.auth.SSOActivated).not.toHaveBeenCalled() 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) }) @@ -104,7 +108,9 @@ describe("configs", () => { expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.GOOGLE) expect(events.auth.SSODeactivated).not.toHaveBeenCalled() 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) }) }) @@ -154,7 +160,9 @@ describe("configs", () => { expect(events.auth.SSOUpdated).toHaveBeenCalledWith(ConfigType.OIDC) expect(events.auth.SSOActivated).not.toHaveBeenCalled() 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) }) diff --git a/packages/worker/src/api/routes/global/tests/license.spec.ts b/packages/worker/src/api/routes/global/tests/license.spec.ts index 7f552fe453..7c8fdb553c 100644 --- a/packages/worker/src/api/routes/global/tests/license.spec.ts +++ b/packages/worker/src/api/routes/global/tests/license.spec.ts @@ -42,7 +42,9 @@ describe("/api/global/license", () => { licenseKey: "licenseKey", }) 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({ offlineLicenseToken: "offlineLicenseToken", }) - expect(licensing.offline.activateOfflineLicenseToken).toHaveBeenCalledWith( - "offlineLicenseToken" - ) + expect( + licensing.offline.activateOfflineLicenseToken + ).toHaveBeenCalledWith("offlineLicenseToken") expect(res.status).toBe(200) }) }) @@ -102,7 +104,9 @@ describe("/api/global/license", () => { it("returns 204", async () => { const res = await config.api.license.deleteOfflineLicense() expect(res.status).toBe(204) - expect(licensing.offline.deleteOfflineLicenseToken).toHaveBeenCalledTimes(1) + expect(licensing.offline.deleteOfflineLicenseToken).toHaveBeenCalledTimes( + 1 + ) }) })