1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { getResourceWithEditableStatus } from "./resources";
6 import { ResourceKind } from "models/resource";
8 const groupFixtures = {
9 user_uuid: 'zzzzz-tpzed-0123456789ab789',
10 user_resource_uuid: 'zzzzz-tpzed-0123456789abcde',
11 unknown_user_resource_uuid: 'zzzzz-tpzed-0123456789ab987',
12 editable_collection_resource_uuid: 'zzzzz-4zz18-0123456789ab456',
13 not_editable_collection_resource_uuid: 'zzzzz-4zz18-0123456789ab654',
14 editable_project_resource_uuid: 'zzzzz-j7d0g-0123456789ab123',
15 not_editable_project_resource_uuid: 'zzzzz-j7d0g-0123456789ab321',
18 describe('resources', () => {
19 describe('getResourceWithEditableStatus', () => {
20 const resourcesState = {
21 [groupFixtures.editable_project_resource_uuid]: {
22 uuid: groupFixtures.editable_project_resource_uuid,
23 ownerUuid: groupFixtures.user_uuid,
25 modifiedByClientUuid: 'string',
26 modifiedByUserUuid: 'string',
29 kind: ResourceKind.PROJECT,
30 writableBy: [groupFixtures.user_uuid],
33 [groupFixtures.editable_collection_resource_uuid]: {
34 uuid: groupFixtures.editable_collection_resource_uuid,
35 ownerUuid: groupFixtures.editable_project_resource_uuid,
37 modifiedByClientUuid: 'string',
38 modifiedByUserUuid: 'string',
41 kind: ResourceKind.COLLECTION,
44 [groupFixtures.not_editable_project_resource_uuid]: {
45 uuid: groupFixtures.not_editable_project_resource_uuid,
46 ownerUuid: groupFixtures.unknown_user_resource_uuid,
48 modifiedByClientUuid: 'string',
49 modifiedByUserUuid: 'string',
52 kind: ResourceKind.PROJECT,
53 writableBy: [groupFixtures.unknown_user_resource_uuid],
56 [groupFixtures.not_editable_collection_resource_uuid]: {
57 uuid: groupFixtures.not_editable_collection_resource_uuid,
58 ownerUuid: groupFixtures.not_editable_project_resource_uuid,
60 modifiedByClientUuid: 'string',
61 modifiedByUserUuid: 'string',
64 kind: ResourceKind.COLLECTION,
67 [groupFixtures.user_resource_uuid]: {
68 uuid: groupFixtures.user_resource_uuid,
69 ownerUuid: groupFixtures.user_resource_uuid,
71 modifiedByClientUuid: 'string',
72 modifiedByUserUuid: 'string',
75 kind: ResourceKind.USER,
80 it('should return editable user resource (resource UUID is equal to user UUID)', () => {
82 const id = groupFixtures.user_resource_uuid;
83 const userUuid = groupFixtures.user_resource_uuid;
86 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
89 expect(result!.isEditable).toBeTruthy();
92 it('should return editable project resource', () => {
94 const id = groupFixtures.editable_project_resource_uuid;
95 const userUuid = groupFixtures.user_uuid;
98 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
101 expect(result!.isEditable).toBeTruthy();
104 it('should return editable collection resource', () => {
106 const id = groupFixtures.editable_collection_resource_uuid;
107 const userUuid = groupFixtures.user_uuid;
110 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
113 expect(result!.isEditable).toBeTruthy();
116 it('should return not editable project resource', () => {
118 const id = groupFixtures.not_editable_project_resource_uuid;
119 const userUuid = groupFixtures.user_uuid;
122 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
125 expect(result!.isEditable).toBeFalsy();
128 it('should return not editable collection resource', () => {
130 const id = groupFixtures.not_editable_collection_resource_uuid;
131 const userUuid = groupFixtures.user_uuid;
134 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
137 expect(result!.isEditable).toBeFalsy();