Fix tests refs #19295
[arvados.git] / 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_uuid,
24                 createdAt: 'string',
25                 modifiedByClientUuid: 'string',
26                 modifiedByUserUuid: 'string',
27                 modifiedAt: 'string',
28                 href: 'string',
29                 kind: ResourceKind.PROJECT,
30                 writableBy: [groupFixtures.user_uuid],
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                 writableBy: [groupFixtures.unknown_user_resource_uuid],
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             }
78         };
79
80         it('should return editable user resource (resource UUID is equal to user UUID)', () => {
81             // given
82             const id = groupFixtures.user_resource_uuid;
83             const userUuid = groupFixtures.user_resource_uuid;
84
85             // when
86             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
87
88             // then
89             expect(result!.isEditable).toBeTruthy();
90         });
91
92         it('should return editable project resource', () => {
93             // given
94             const id = groupFixtures.editable_project_resource_uuid;
95             const userUuid = groupFixtures.user_uuid;
96
97             // when
98             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
99
100             // then
101             expect(result!.isEditable).toBeTruthy();
102         });
103
104         it('should return editable collection resource', () => {
105             // given
106             const id = groupFixtures.editable_collection_resource_uuid;
107             const userUuid = groupFixtures.user_uuid;
108
109             // when
110             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
111
112             // then
113             expect(result!.isEditable).toBeTruthy();
114         });
115
116         it('should return not editable project resource', () => {
117             // given
118             const id = groupFixtures.not_editable_project_resource_uuid;
119             const userUuid = groupFixtures.user_uuid;
120
121             // when
122             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
123
124             // then
125             expect(result!.isEditable).toBeFalsy();
126         });
127
128         it('should return not editable collection resource', () => {
129             // given
130             const id = groupFixtures.not_editable_collection_resource_uuid;
131             const userUuid = groupFixtures.user_uuid;
132
133             // when
134             const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
135
136             // then
137             expect(result!.isEditable).toBeFalsy();
138         });
139     });
140 });