21910: Remove modified_by_client_uuid references from workbench.
[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                 modifiedByUserUuid: 'string',
26                 modifiedAt: 'string',
27                 href: 'string',
28                 kind: ResourceKind.PROJECT,
29                 canWrite: true,
30                 etag: 'string',
31             },
32             [groupFixtures.editable_collection_resource_uuid]: {
33                 uuid: groupFixtures.editable_collection_resource_uuid,
34                 ownerUuid: groupFixtures.editable_project_resource_uuid,
35                 createdAt: 'string',
36                 modifiedByUserUuid: 'string',
37                 modifiedAt: 'string',
38                 href: 'string',
39                 kind: ResourceKind.COLLECTION,
40                 etag: 'string',
41             },
42             [groupFixtures.not_editable_project_resource_uuid]: {
43                 uuid: groupFixtures.not_editable_project_resource_uuid,
44                 ownerUuid: groupFixtures.unknown_user_resource_uuid,
45                 createdAt: 'string',
46                 modifiedByUserUuid: 'string',
47                 modifiedAt: 'string',
48                 href: 'string',
49                 kind: ResourceKind.PROJECT,
50                 canWrite: false,
51                 etag: 'string',
52             },
53             [groupFixtures.not_editable_collection_resource_uuid]: {
54                 uuid: groupFixtures.not_editable_collection_resource_uuid,
55                 ownerUuid: groupFixtures.not_editable_project_resource_uuid,
56                 createdAt: 'string',
57                 modifiedByUserUuid: 'string',
58                 modifiedAt: 'string',
59                 href: 'string',
60                 kind: ResourceKind.COLLECTION,
61                 etag: 'string',
62             },
63             [groupFixtures.user_resource_uuid]: {
64                 uuid: groupFixtures.user_resource_uuid,
65                 ownerUuid: groupFixtures.user_resource_uuid,
66                 createdAt: 'string',
67                 modifiedByUserUuid: 'string',
68                 modifiedAt: 'string',
69                 href: 'string',
70                 kind: ResourceKind.USER,
71                 etag: 'string',
72                 canWrite: true
73             }
74         };
75
76         it('should return editable user resource (resource UUID is equal to user UUID)', () => {
77             // given
78             const id = groupFixtures.user_resource_uuid;
79             const userUuid = groupFixtures.user_resource_uuid;
80
81             // when
82             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
83
84             // then
85             expect(result!.isEditable).toBeTruthy();
86         });
87
88         it('should return editable project resource', () => {
89             // given
90             const id = groupFixtures.editable_project_resource_uuid;
91             const userUuid = groupFixtures.user_uuid;
92
93             // when
94             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
95
96             // then
97             expect(result!.isEditable).toBeTruthy();
98         });
99
100         it('should return editable collection resource', () => {
101             // given
102             const id = groupFixtures.editable_collection_resource_uuid;
103             const userUuid = groupFixtures.user_uuid;
104
105             // when
106             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
107
108             // then
109             expect(result!.isEditable).toBeTruthy();
110         });
111
112         it('should return not editable project resource', () => {
113             // given
114             const id = groupFixtures.not_editable_project_resource_uuid;
115             const userUuid = groupFixtures.user_uuid;
116
117             // when
118             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
119
120             // then
121             expect(result!.isEditable).toBeFalsy();
122         });
123
124         it('should return not editable collection resource', () => {
125             // given
126             const id = groupFixtures.not_editable_collection_resource_uuid;
127             const userUuid = groupFixtures.user_uuid;
128
129             // when
130             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
131
132             // then
133             expect(result!.isEditable).toBeFalsy();
134         });
135     });
136 });