From fb1bfbdae8b9593bbb0db30bb01577e23aa4bd85 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 22 Feb 2024 13:55:26 +0100 Subject: [PATCH 1/5] Clean code --- packages/backend-core/src/middleware/joi-validator.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/backend-core/src/middleware/joi-validator.ts b/packages/backend-core/src/middleware/joi-validator.ts index fcc8316886..ac8064a512 100644 --- a/packages/backend-core/src/middleware/joi-validator.ts +++ b/packages/backend-core/src/middleware/joi-validator.ts @@ -1,12 +1,12 @@ -import Joi, { ObjectSchema } from "joi" -import { BBContext } from "@budibase/types" +import Joi from "joi" +import { Ctx } from "@budibase/types" function validate( schema: Joi.ObjectSchema | Joi.ArraySchema, property: string ) { // Return a Koa middleware function - return (ctx: BBContext, next: any) => { + return (ctx: Ctx, next: any) => { if (!schema) { return next() } @@ -30,7 +30,6 @@ function validate( const { error } = schema.validate(params) if (error) { ctx.throw(400, `Invalid ${property} - ${error.message}`) - return } return next() } From 8e77365c1952a353328e87be13f6d63ac66f9c6c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 22 Feb 2024 13:55:38 +0100 Subject: [PATCH 2/5] Allow mocking multiple features --- packages/backend-core/tests/core/utilities/mocks/licenses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-core/tests/core/utilities/mocks/licenses.ts b/packages/backend-core/tests/core/utilities/mocks/licenses.ts index 758fd6bf9a..1cbc282575 100644 --- a/packages/backend-core/tests/core/utilities/mocks/licenses.ts +++ b/packages/backend-core/tests/core/utilities/mocks/licenses.ts @@ -58,7 +58,7 @@ export const useCloudFree = () => { // FEATURES const useFeature = (feature: Feature) => { - const license = cloneDeep(UNLIMITED_LICENSE) + const license = cloneDeep(getCachedLicense() || UNLIMITED_LICENSE) const opts: UseLicenseOpts = { features: [feature], } From ea615f420ce5f2dc466b0a3a512eb25b4ea7071f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 22 Feb 2024 13:55:59 +0100 Subject: [PATCH 3/5] Add extra test --- .../src/api/routes/global/tests/scim.spec.ts | 20 +++++++++++++++++++ packages/worker/src/tests/api/groups.ts | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/worker/src/api/routes/global/tests/scim.spec.ts b/packages/worker/src/api/routes/global/tests/scim.spec.ts index 56b7ca9f40..ae0abadc5d 100644 --- a/packages/worker/src/api/routes/global/tests/scim.spec.ts +++ b/packages/worker/src/api/routes/global/tests/scim.spec.ts @@ -654,6 +654,26 @@ describe("scim", () => { totalResults: groupCount, }) }) + + it("can fetch groups even if internal groups exist", async () => { + mocks.licenses.useGroups() + await config.api.groups.saveGroup(structures.userGroups.userGroup()) + await config.api.groups.saveGroup(structures.userGroups.userGroup()) + + const response = await getScimGroups() + + expect(response).toEqual({ + Resources: expect.arrayContaining(groups), + itemsPerPage: 25, + schemas: ["urn:ietf:params:scim:api:messages:2.0:ListResponse"], + startIndex: 1, + totalResults: groupCount, + }) + + expect((await config.api.groups.fetch()).body.data).toHaveLength( + 25 + 2 // scim groups + internal groups + ) + }) }) }) diff --git a/packages/worker/src/tests/api/groups.ts b/packages/worker/src/tests/api/groups.ts index 91f7c92c7d..0b9081cc92 100644 --- a/packages/worker/src/tests/api/groups.ts +++ b/packages/worker/src/tests/api/groups.ts @@ -53,4 +53,12 @@ export class GroupsAPI extends TestAPI { .expect("Content-Type", /json/) .expect(200) } + + fetch = ({ expect } = { expect: 200 }) => { + return this.request + .get(`/api/global/groups`) + .set(this.config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(expect) + } } From 302c6d9e0b0438b610a13f54ad979c3f2571d3fe Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 22 Feb 2024 14:07:46 +0100 Subject: [PATCH 4/5] Update ref --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index 60e47a8249..bd296586af 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit 60e47a8249fd6291a6bc20fe3fe6776b11938fa1 +Subproject commit bd296586af0dc17081c613e73539bb34820ddf27 From a5f7c3ccf6b80d9bd30b5430172fc8a68c090937 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 22 Feb 2024 15:18:03 +0100 Subject: [PATCH 5/5] Update ref --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index bd296586af..183b35d3ac 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit bd296586af0dc17081c613e73539bb34820ddf27 +Subproject commit 183b35d3acd42433dcb2d32bcd89a36abe13afec