diff --git a/front/lib/resources/space_resource.ts b/front/lib/resources/space_resource.ts index 0a21994724b8..5efb5453d2c0 100644 --- a/front/lib/resources/space_resource.ts +++ b/front/lib/resources/space_resource.ts @@ -568,7 +568,7 @@ export class SpaceResource extends BaseResource { workspaceId: this.workspaceId, roles: [ { role: "admin", permissions: ["admin", "read", "write"] }, - //{ role: "builder", permissions: ["read", "write"] }, + { role: "builder", permissions: ["read", "write"] }, ], groups: this.groups.map((group) => ({ id: group.id, diff --git a/front/package-lock.json b/front/package-lock.json index 60b266043cb1..4680e050af3c 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -154,7 +154,7 @@ }, "../sdks/js": { "name": "@dust-tt/client", - "version": "1.0.23", + "version": "1.0.24", "license": "ISC", "dependencies": { "axios": "^1.7.9", diff --git a/front/pages/api/v1/w/[wId]/spaces/index.test.ts b/front/pages/api/v1/w/[wId]/spaces/index.test.ts index 2e60d59b04e0..f588166ade1b 100644 --- a/front/pages/api/v1/w/[wId]/spaces/index.test.ts +++ b/front/pages/api/v1/w/[wId]/spaces/index.test.ts @@ -1,11 +1,15 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { createMocks } from "node-mocks-http"; -import { describe, expect, expectTypeOf, it } from "vitest"; +import { describe, expect, it } from "vitest"; import { groupFactory } from "@app/tests/utils/GroupFactory"; +import { groupSpaceFactory } from "@app/tests/utils/GroupSpaceFactory"; import { keyFactory } from "@app/tests/utils/KeyFactory"; import { spaceFactory } from "@app/tests/utils/SpaceFactory"; -import { withinTransaction } from "@app/tests/utils/utils"; +import { + expectArrayOfObjectsWithSpecificLength, + withinTransaction, +} from "@app/tests/utils/utils"; import { workspaceFactory } from "@app/tests/utils/WorkspaceFactory"; import handler from "./index"; @@ -47,19 +51,37 @@ describe( }, }); - await spaceFactory().global(workspace).create(); + const globalSpace = await spaceFactory().global(workspace).create(); await spaceFactory().system(workspace).create(); - await spaceFactory().regular(workspace).create(); - await spaceFactory().regular(workspace).create(); + const regularSpace1 = await spaceFactory().regular(workspace).create(); + const regularSpace2 = await spaceFactory().regular(workspace).create(); await spaceFactory().regular(workspace).create(); + await groupSpaceFactory().associate(regularSpace1, globalGroup); + await groupSpaceFactory().associate(regularSpace2, globalGroup); + await handler(req, res); expect(res._getStatusCode()).toBe(200); - console.log(res._getData()); - expect(JSON.parse(res._getData())).toEqual({ - spaces: expect([expect.any(Object)]).toHaveLength(5), - }); + + const response = JSON.parse(res._getData()); + + expectArrayOfObjectsWithSpecificLength(response["spaces"], 3); + + expect(response["spaces"]).toEqual([ + expect.objectContaining({ + name: globalSpace.name, + kind: "global", + }), + expect.objectContaining({ + name: regularSpace1.name, + kind: "regular", + }), + expect.objectContaining({ + name: regularSpace2.name, + kind: "regular", + }), + ]); }); }) ); diff --git a/front/tests/utils/GroupSpaceFactory.ts b/front/tests/utils/GroupSpaceFactory.ts new file mode 100644 index 000000000000..28a9b9e4c6db --- /dev/null +++ b/front/tests/utils/GroupSpaceFactory.ts @@ -0,0 +1,27 @@ +import type { InferCreationAttributes } from "sequelize"; + +import { GroupSpaceModel } from "@app/lib/resources/storage/models/group_spaces"; +import type { GroupModel } from "@app/lib/resources/storage/models/groups"; +import type { SpaceModel } from "@app/lib/resources/storage/models/spaces"; + +import { Factory } from "./factories"; + +class GroupSpaceFactory extends Factory< + GroupSpaceModel, + InferCreationAttributes +> { + async make(params: InferCreationAttributes) { + return GroupSpaceModel.create(params); + } + + associate(space: SpaceModel, group: GroupModel) { + return this.params({ + groupId: group.id, + vaultId: space.id, + }).create(); + } +} + +export const groupSpaceFactory = () => { + return new GroupSpaceFactory(); +}; diff --git a/front/tests/utils/utils.ts b/front/tests/utils/utils.ts index fe23b62e0646..fbebc58b30bc 100644 --- a/front/tests/utils/utils.ts +++ b/front/tests/utils/utils.ts @@ -13,6 +13,17 @@ type NextHandler = ( res: NextApiResponse ) => Promise | void; +export const expectArrayOfObjectsWithSpecificLength = ( + value: any, + length: number +) => { + expect(Array.isArray(value)).toBe(true); + expect(value).toHaveLength(length); + expect( + value.every((item: unknown) => typeof item === "object" && item !== null) + ).toBe(true); +}; + // Wrapper to make sure that each test suite has a clean database export const withinTransaction = (testSuite) => { return async () => {