@@ -26,6 +26,7 @@ describe('cms url methods', () => {
26
26
const learningContextId = 'lEarnIngCOntextId123' ;
27
27
const courseId = 'course-v1:courseId123' ;
28
28
const libraryV1Id = 'library-v1:libaryId123' ;
29
+ const libraryV2Id = 'lib:libaryId123' ;
29
30
const language = 'la' ;
30
31
const handout = '/aSSet@hANdoUt' ;
31
32
const videoId = '123-SOmeVidEOid-213' ;
@@ -41,17 +42,21 @@ describe('cms url methods', () => {
41
42
] ,
42
43
} ,
43
44
} ;
44
- it ( 'returns the library page when given the library' , ( ) => {
45
+ it ( 'returns the library page when given the v1 library' , ( ) => {
45
46
expect ( returnUrl ( { studioEndpointUrl, unitUrl, learningContextId : libraryV1Id } ) )
46
47
. toEqual ( `${ studioEndpointUrl } /library/${ libraryV1Id } ` ) ;
47
48
} ) ;
49
+ it ( 'throws error when given the v2 library' , ( ) => {
50
+ expect ( ( ) => { returnUrl ( { studioEndpointUrl, unitUrl, learningContextId : libraryV2Id } ) ; } )
51
+ . toThrow ( 'Return url not available (or needed) for V2 libraries' ) ;
52
+ } ) ;
48
53
it ( 'returns url with studioEndpointUrl and unitUrl' , ( ) => {
49
54
expect ( returnUrl ( { studioEndpointUrl, unitUrl, learningContextId : courseId } ) )
50
55
. toEqual ( `${ studioEndpointUrl } /container/${ unitUrl . data . ancestors [ 0 ] . id } ` ) ;
51
56
} ) ;
52
- it ( 'returns empty string if no unit url' , ( ) => {
53
- expect ( returnUrl ( { studioEndpointUrl, unitUrl : null , learningContextId : courseId } ) )
54
- . toEqual ( ' ') ;
57
+ it ( 'throws error if no unit url' , ( ) => {
58
+ expect ( ( ) => { returnUrl ( { studioEndpointUrl, unitUrl : null , learningContextId : courseId } ) ; } )
59
+ . toThrow ( 'No unit url for return url ') ;
55
60
} ) ;
56
61
it ( 'returns the library page when given the library' , ( ) => {
57
62
expect ( libraryV1 ( { studioEndpointUrl, learningContextId : libraryV1Id } ) )
@@ -69,20 +74,28 @@ describe('cms url methods', () => {
69
74
} ) ;
70
75
it ( 'returns v2 url with studioEndpointUrl and v2BlockId' , ( ) => {
71
76
expect ( block ( { studioEndpointUrl, blockId : v2BlockId } ) )
72
- . toEqual ( `${ studioEndpointUrl } /api/xblock/v2/xblocks/${ v2BlockId } ` ) ;
77
+ . toEqual ( `${ studioEndpointUrl } /api/xblock/v2/xblocks/${ v2BlockId } /fields/ ` ) ;
73
78
} ) ;
74
79
} ) ;
75
80
describe ( 'blockAncestor' , ( ) => {
76
81
it ( 'returns url with studioEndpointUrl, blockId and ancestor query' , ( ) => {
77
82
expect ( blockAncestor ( { studioEndpointUrl, blockId } ) )
78
83
. toEqual ( `${ block ( { studioEndpointUrl, blockId } ) } ?fields=ancestorInfo` ) ;
79
84
} ) ;
85
+ it ( 'throws error with studioEndpointUrl, v2 blockId and ancestor query' , ( ) => {
86
+ expect ( ( ) => { blockAncestor ( { studioEndpointUrl, blockId : v2BlockId } ) ; } )
87
+ . toThrow ( 'Block ancestor not available (and not needed) for V2 blocks' ) ;
88
+ } ) ;
80
89
} ) ;
81
90
describe ( 'blockStudioView' , ( ) => {
82
- it ( 'returns url with studioEndpointUrl, blockId and studio_view query' , ( ) => {
91
+ it ( 'returns v1 url with studioEndpointUrl, blockId and studio_view query' , ( ) => {
83
92
expect ( blockStudioView ( { studioEndpointUrl, blockId } ) )
84
93
. toEqual ( `${ block ( { studioEndpointUrl, blockId } ) } /studio_view` ) ;
85
94
} ) ;
95
+ it ( 'returns v2 url with studioEndpointUrl, v2 blockId and studio_view query' , ( ) => {
96
+ expect ( blockStudioView ( { studioEndpointUrl, blockId : v2BlockId } ) )
97
+ . toEqual ( `${ studioEndpointUrl } /api/xblock/v2/xblocks/${ v2BlockId } /view/studio_view/` ) ;
98
+ } ) ;
86
99
} ) ;
87
100
88
101
describe ( 'courseAssets' , ( ) => {
0 commit comments