b870ed238f
Following https://github.com/twentyhq/twenty/pull/14869 Dynamically clearing the cache, as one entry was forgotten It seems like a permission test deletes a role that's expected to be existing in following tests, as now cache is getting invalidated tests are failing Seems to be related to https://discord.com/channels/1130383047699738754/1423768505911869460 ## Singleton local cache key collision When set for the first time caches local keys looks like `workspaceId:undefined", singleton is shared between several cache instances If the given key is undefined it will read on other entity cache entry.
108 lines
3.9 KiB
TypeScript
108 lines
3.9 KiB
TypeScript
import { deleteOneOperationFactory } from 'test/integration/graphql/utils/delete-one-operation-factory.util';
|
|
import { makeGraphqlAPIRequestWithAcmeMemberRole } from 'test/integration/graphql/utils/make-graphql-api-request-with-acme-member-role.util';
|
|
import { makeGraphqlAPIRequestWithMemberRole } from 'test/integration/graphql/utils/make-graphql-api-request-with-member-role.util';
|
|
import { updateOneOperationFactory } from 'test/integration/graphql/utils/update-one-operation-factory.util';
|
|
|
|
import { ErrorCode } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
|
import { PermissionsExceptionMessage } from 'src/engine/metadata-modules/permissions/permissions.exception';
|
|
import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/data/constants/workspace-member-data-seeds.constant';
|
|
|
|
const WORKSPACE_MEMBER_GQL_FIELDS = `
|
|
id
|
|
name {
|
|
firstName
|
|
}
|
|
`;
|
|
|
|
describe('workspace members permissions', () => {
|
|
it('should allow update when user is updating themself (member role)', async () => {
|
|
const graphqlOperation = updateOneOperationFactory({
|
|
objectMetadataSingularName: 'workspaceMember',
|
|
gqlFields: WORKSPACE_MEMBER_GQL_FIELDS,
|
|
recordId: WORKSPACE_MEMBER_DATA_SEED_IDS.JONY,
|
|
data: {
|
|
name: {
|
|
firstName: 'Jony',
|
|
},
|
|
},
|
|
});
|
|
|
|
const response =
|
|
await makeGraphqlAPIRequestWithMemberRole(graphqlOperation);
|
|
|
|
expect(response.body.errors).not.toBeDefined();
|
|
expect(response.body.data).toStrictEqual({
|
|
updateWorkspaceMember: {
|
|
id: WORKSPACE_MEMBER_DATA_SEED_IDS.JONY,
|
|
name: {
|
|
firstName: 'Jony',
|
|
},
|
|
},
|
|
});
|
|
expect(response.body.errors).toBeUndefined();
|
|
});
|
|
it('should throw when user does not have permission (member role)', async () => {
|
|
const graphqlOperation = updateOneOperationFactory({
|
|
objectMetadataSingularName: 'workspaceMember',
|
|
gqlFields: WORKSPACE_MEMBER_GQL_FIELDS,
|
|
recordId: WORKSPACE_MEMBER_DATA_SEED_IDS.TIM,
|
|
data: {
|
|
name: {
|
|
firstName: 'Not Tim',
|
|
},
|
|
},
|
|
});
|
|
|
|
const response =
|
|
await makeGraphqlAPIRequestWithMemberRole(graphqlOperation);
|
|
|
|
expect(response.body.data).toStrictEqual({ updateWorkspaceMember: null });
|
|
expect(response.body.errors).toBeDefined();
|
|
expect(response.body.errors[0].message).toBe(
|
|
PermissionsExceptionMessage.PERMISSION_DENIED,
|
|
);
|
|
expect(response.body.errors[0].extensions.code).toBe(ErrorCode.FORBIDDEN);
|
|
});
|
|
|
|
it('should throw when user does not have permission (member role)', async () => {
|
|
const graphqlOperation = deleteOneOperationFactory({
|
|
objectMetadataSingularName: 'workspaceMember',
|
|
gqlFields: WORKSPACE_MEMBER_GQL_FIELDS,
|
|
recordId: WORKSPACE_MEMBER_DATA_SEED_IDS.TIM,
|
|
});
|
|
|
|
const response =
|
|
await makeGraphqlAPIRequestWithMemberRole(graphqlOperation);
|
|
|
|
expect(response.body.data).toStrictEqual({ deleteWorkspaceMember: null });
|
|
expect(response.body.errors).toBeDefined();
|
|
expect(response.body.errors[0].message).toBe(
|
|
PermissionsExceptionMessage.PERMISSION_DENIED,
|
|
);
|
|
expect(response.body.errors[0].extensions.code).toBe(ErrorCode.FORBIDDEN);
|
|
});
|
|
|
|
// This test is not idempotent
|
|
it('should allow delete when user is deleting themself (member role)', async () => {
|
|
const deleteOperation = deleteOneOperationFactory({
|
|
objectMetadataSingularName: 'workspaceMember',
|
|
gqlFields: WORKSPACE_MEMBER_GQL_FIELDS,
|
|
recordId: WORKSPACE_MEMBER_DATA_SEED_IDS.JONY,
|
|
});
|
|
|
|
const deleteResponse =
|
|
await makeGraphqlAPIRequestWithAcmeMemberRole(deleteOperation);
|
|
|
|
expect(deleteResponse.body.errors).not.toBeDefined();
|
|
expect(deleteResponse.body.data).toStrictEqual({
|
|
deleteWorkspaceMember: {
|
|
id: WORKSPACE_MEMBER_DATA_SEED_IDS.JONY,
|
|
name: {
|
|
firstName: 'Jony',
|
|
},
|
|
},
|
|
});
|
|
expect(deleteResponse.body.errors).toBeUndefined();
|
|
});
|
|
});
|