Merge branch '21621-io-panel-json-tab-copy' into main. Closes #21621
[arvados.git] / services / workbench2 / src / store / resources / resources.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { getResourceWithEditableStatus } from "./resources";
6 import { ResourceKind } from "models/resource";
7
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',
16 };
17
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_resource_uuid,
24                 createdAt: 'string',
25                 modifiedByClientUuid: 'string',
26                 modifiedByUserUuid: 'string',
27                 modifiedAt: 'string',
28                 href: 'string',
29                 kind: ResourceKind.PROJECT,
30                 canWrite: true,
31                 etag: 'string',
32             },
33             [groupFixtures.editable_collection_resource_uuid]: {
34                 uuid: groupFixtures.editable_collection_resource_uuid,
35                 ownerUuid: groupFixtures.editable_project_resource_uuid,
36                 createdAt: 'string',
37                 modifiedByClientUuid: 'string',
38                 modifiedByUserUuid: 'string',
39                 modifiedAt: 'string',
40                 href: 'string',
41                 kind: ResourceKind.COLLECTION,
42                 etag: 'string',
43             },
44             [groupFixtures.not_editable_project_resource_uuid]: {
45                 uuid: groupFixtures.not_editable_project_resource_uuid,
46                 ownerUuid: groupFixtures.unknown_user_resource_uuid,
47                 createdAt: 'string',
48                 modifiedByClientUuid: 'string',
49                 modifiedByUserUuid: 'string',
50                 modifiedAt: 'string',
51                 href: 'string',
52                 kind: ResourceKind.PROJECT,
53                 canWrite: false,
54                 etag: 'string',
55             },
56             [groupFixtures.not_editable_collection_resource_uuid]: {
57                 uuid: groupFixtures.not_editable_collection_resource_uuid,
58                 ownerUuid: groupFixtures.not_editable_project_resource_uuid,
59                 createdAt: 'string',
60                 modifiedByClientUuid: 'string',
61                 modifiedByUserUuid: 'string',
62                 modifiedAt: 'string',
63                 href: 'string',
64                 kind: ResourceKind.COLLECTION,
65                 etag: 'string',
66             },
67             [groupFixtures.user_resource_uuid]: {
68                 uuid: groupFixtures.user_resource_uuid,
69                 ownerUuid: groupFixtures.user_resource_uuid,
70                 createdAt: 'string',
71                 modifiedByClientUuid: 'string',
72                 modifiedByUserUuid: 'string',
73                 modifiedAt: 'string',
74                 href: 'string',
75                 kind: ResourceKind.USER,
76                 etag: 'string',
77                 canWrite: true
78             }
79         };
80
81         it('should return editable user resource (resource UUID is equal to user UUID)', () => {
82             // given
83             const id = groupFixtures.user_resource_uuid;
84             const userUuid = groupFixtures.user_resource_uuid;
85
86             // when
87             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
88
89             // then
90             expect(result!.isEditable).toBeTruthy();
91         });
92
93         it('should return editable project resource', () => {
94             // given
95             const id = groupFixtures.editable_project_resource_uuid;
96             const userUuid = groupFixtures.user_uuid;
97
98             // when
99             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
100
101             // then
102             expect(result!.isEditable).toBeTruthy();
103         });
104
105         it('should return editable collection resource', () => {
106             // given
107             const id = groupFixtures.editable_collection_resource_uuid;
108             const userUuid = groupFixtures.user_uuid;
109
110             // when
111             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
112
113             // then
114             expect(result!.isEditable).toBeTruthy();
115         });
116
117         it('should return not editable project resource', () => {
118             // given
119             const id = groupFixtures.not_editable_project_resource_uuid;
120             const userUuid = groupFixtures.user_uuid;
121
122             // when
123             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
124
125             // then
126             expect(result!.isEditable).toBeFalsy();
127         });
128
129         it('should return not editable collection resource', () => {
130             // given
131             const id = groupFixtures.not_editable_collection_resource_uuid;
132             const userUuid = groupFixtures.user_uuid;
133
134             // when
135             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
136
137             // then
138             expect(result!.isEditable).toBeFalsy();
139         });
140     });
141 });