1
1
import * as PortalModule from "@esri/arcgis-rest-portal" ;
2
- import { IHubProject , IResolvedMetric , getProp } from "../../src" ;
2
+ import {
3
+ IHubProject ,
4
+ IResolvedMetric ,
5
+ cloneObject ,
6
+ getProp ,
7
+ mergeObjects ,
8
+ } from "../../src" ;
3
9
import { Catalog } from "../../src/search" ;
4
10
import { ArcGISContextManager } from "../../src/ArcGISContextManager" ;
5
11
import { HubProject } from "../../src/projects/HubProject" ;
@@ -12,6 +18,25 @@ import * as ResolveMetricModule from "../../src/metrics/resolveMetric";
12
18
import { HubItemEntity } from "../../src/core/HubItemEntity" ;
13
19
import * as EnrichEntityModule from "../../src/core/enrichEntity" ;
14
20
21
+ const initContextManager = async ( opts = { } ) => {
22
+ const defaults = {
23
+ authentication : MOCK_AUTH ,
24
+ currentUser : {
25
+ username : "casey" ,
26
+ privileges : [ "portal:user:shareToGroup" ] ,
27
+ } as unknown as PortalModule . IUser ,
28
+ portal : {
29
+ name : "DC R&D Center" ,
30
+ id : "BRXFAKE" ,
31
+ urlKey : "fake-org" ,
32
+ } as unknown as PortalModule . IPortal ,
33
+ portalUrl : "https://myserver.com" ,
34
+ } ;
35
+ return await ArcGISContextManager . create (
36
+ mergeObjects ( opts , defaults , [ "currentUser" ] )
37
+ ) ;
38
+ } ;
39
+
15
40
describe ( "HubProject Class:" , ( ) => {
16
41
let authdCtxMgr : ArcGISContextManager ;
17
42
let unauthdCtxMgr : ArcGISContextManager ;
@@ -20,19 +45,7 @@ describe("HubProject Class:", () => {
20
45
// When we pass in all this information, the context
21
46
// manager will not try to fetch anything, so no need
22
47
// to mock those calls
23
- authdCtxMgr = await ArcGISContextManager . create ( {
24
- authentication : MOCK_AUTH ,
25
- currentUser : {
26
- username : "casey" ,
27
- privileges : [ "portal:user:shareToGroup" ] ,
28
- } as unknown as PortalModule . IUser ,
29
- portal : {
30
- name : "DC R&D Center" ,
31
- id : "BRXFAKE" ,
32
- urlKey : "fake-org" ,
33
- } as unknown as PortalModule . IPortal ,
34
- portalUrl : "https://myserver.com" ,
35
- } ) ;
48
+ authdCtxMgr = await initContextManager ( ) ;
36
49
} ) ;
37
50
38
51
describe ( "static methods:" , ( ) => {
@@ -363,7 +376,7 @@ describe("HubProject Class:", () => {
363
376
364
377
expect ( enrichEntitySpy ) . toHaveBeenCalledTimes ( 1 ) ;
365
378
} ) ;
366
- it ( "toEditor converst entity to correct structure" , async ( ) => {
379
+ it ( "toEditor converts entity to correct structure" , async ( ) => {
367
380
const chk = HubProject . fromJson (
368
381
{
369
382
id : "bc3" ,
@@ -381,6 +394,35 @@ describe("HubProject Class:", () => {
381
394
) ;
382
395
expect ( result . _groups ) . toEqual ( [ ] ) ;
383
396
} ) ;
397
+ describe ( 'auto-populating "shareWith" groups' , ( ) => {
398
+ let projectInstance : any ;
399
+ beforeEach ( async ( ) => {
400
+ const _authdCtxMgr = await initContextManager ( {
401
+ currentUser : {
402
+ groups : [
403
+ { id : "00a" , isViewOnly : false } ,
404
+ { id : "00b" , isViewOnly : true , memberType : "admin" } ,
405
+ { id : "00d" , isViewOnly : false } ,
406
+ ] as PortalModule . IGroup [ ] ,
407
+ } ,
408
+ } ) ;
409
+ projectInstance = HubProject . fromJson ( { } , _authdCtxMgr . context ) ;
410
+ } ) ;
411
+ it ( 'handles auto-populating "shareWith" groups that the current user can share to' , async ( ) => {
412
+ const result = await projectInstance . toEditor ( {
413
+ contentGroupId : "00a" ,
414
+ collaborationGroupId : "00b" ,
415
+ } ) ;
416
+ expect ( result . _groups ) . toEqual ( [ "00a" , "00b" ] ) ;
417
+ } ) ;
418
+ it ( 'does not auto-populate "shareWith" gruops that the current user cannot share to' , async ( ) => {
419
+ const result = await projectInstance . toEditor ( {
420
+ contentGroupId : "00e" ,
421
+ collaborationGroupId : "00f" ,
422
+ } ) ;
423
+ expect ( result . _groups ) . toEqual ( [ ] ) ;
424
+ } ) ;
425
+ } ) ;
384
426
} ) ;
385
427
386
428
describe ( "fromEditor:" , ( ) => {
0 commit comments