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 modifiedByClientUuid: 'string',
26 modifiedByUserUuid: 'string',
29 kind: ResourceKind.PROJECT,
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,
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,
81 it('should return editable user resource (resource UUID is equal to user UUID)', () => {
83 const id = groupFixtures.user_resource_uuid;
84 const userUuid = groupFixtures.user_resource_uuid;
87 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
90 expect(result!.isEditable).toBeTruthy();
93 it('should return editable project resource', () => {
95 const id = groupFixtures.editable_project_resource_uuid;
96 const userUuid = groupFixtures.user_uuid;
99 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
102 expect(result!.isEditable).toBeTruthy();
105 it('should return editable collection resource', () => {
107 const id = groupFixtures.editable_collection_resource_uuid;
108 const userUuid = groupFixtures.user_uuid;
111 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
114 expect(result!.isEditable).toBeTruthy();
117 it('should return not editable project resource', () => {
119 const id = groupFixtures.not_editable_project_resource_uuid;
120 const userUuid = groupFixtures.user_uuid;
123 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
126 expect(result!.isEditable).toBeFalsy();
129 it('should return not editable collection resource', () => {
131 const id = groupFixtures.not_editable_collection_resource_uuid;
132 const userUuid = groupFixtures.user_uuid;
135 const result = getResourceWithEditableStatus(id, userUuid)(resourcesState);
138 expect(result!.isEditable).toBeFalsy();