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_resource_uuid,
25 modifiedByUserUuid: 'string',
28 kind: ResourceKind.PROJECT,
32 [groupFixtures.editable_collection_resource_uuid]: {
33 uuid: groupFixtures.editable_collection_resource_uuid,
34 ownerUuid: groupFixtures.editable_project_resource_uuid,
36 modifiedByUserUuid: 'string',
39 kind: ResourceKind.COLLECTION,
42 [groupFixtures.not_editable_project_resource_uuid]: {
43 uuid: groupFixtures.not_editable_project_resource_uuid,
44 ownerUuid: groupFixtures.unknown_user_resource_uuid,
46 modifiedByUserUuid: 'string',
49 kind: ResourceKind.PROJECT,
53 [groupFixtures.not_editable_collection_resource_uuid]: {
54 uuid: groupFixtures.not_editable_collection_resource_uuid,
55 ownerUuid: groupFixtures.not_editable_project_resource_uuid,
57 modifiedByUserUuid: 'string',
60 kind: ResourceKind.COLLECTION,
63 [groupFixtures.user_resource_uuid]: {
64 uuid: groupFixtures.user_resource_uuid,
65 ownerUuid: groupFixtures.user_resource_uuid,
67 modifiedByUserUuid: 'string',
70 kind: ResourceKind.USER,
76 it('should return editable user resource (resource UUID is equal to user UUID)', () => {
78 const id = groupFixtures.user_resource_uuid;
79 const userUuid = groupFixtures.user_resource_uuid;
82 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
85 expect(result!.isEditable).toBeTruthy();
88 it('should return editable project resource', () => {
90 const id = groupFixtures.editable_project_resource_uuid;
91 const userUuid = groupFixtures.user_uuid;
94 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
97 expect(result!.isEditable).toBeTruthy();
100 it('should return editable collection resource', () => {
102 const id = groupFixtures.editable_collection_resource_uuid;
103 const userUuid = groupFixtures.user_uuid;
106 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
109 expect(result!.isEditable).toBeTruthy();
112 it('should return not editable project resource', () => {
114 const id = groupFixtures.not_editable_project_resource_uuid;
115 const userUuid = groupFixtures.user_uuid;
118 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
121 expect(result!.isEditable).toBeFalsy();
124 it('should return not editable collection resource', () => {
126 const id = groupFixtures.not_editable_collection_resource_uuid;
127 const userUuid = groupFixtures.user_uuid;
130 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
133 expect(result!.isEditable).toBeFalsy();