@@ -149,17 +149,17 @@ describe('file store', () => {
149149 it ( 'getH5PMetadata should check for h5p.json file' , ( ) => {
150150 const zip = new JSZip ( ) ;
151151 return zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
152- await expect ( Promise . resolve ( getH5PMetadata ( h5pBlob ) ) ) . resolves . toThrowError (
152+ await expect ( getH5PMetadata ( h5pBlob ) ) . rejects . toThrow (
153153 'h5p.json not found in the H5P file.'
154154 ) ;
155155 } ) ;
156156 } ) ;
157- it ( 'getH5PMetadata should exract metadata from h5p.json' , async ( ) => {
157+ it ( 'getH5PMetadata should extract metadata from h5p.json' , async ( ) => {
158158 const manifestFile = get_metadata_file ( { title : 'Test file' } ) ;
159159 const zip = new JSZip ( ) ;
160160 zip . file ( 'h5p.json' , manifestFile ) ;
161161 await zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
162- await expect ( Promise . resolve ( getH5PMetadata ( h5pBlob ) ) ) . resolves . toEqual ( {
162+ await expect ( getH5PMetadata ( h5pBlob ) ) . resolves . toEqual ( {
163163 title : 'Test file' ,
164164 } ) ;
165165 } ) ;
@@ -169,7 +169,55 @@ describe('file store', () => {
169169 const zip = new JSZip ( ) ;
170170 zip . file ( 'h5p.json' , manifestFile ) ;
171171 await zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
172- await expect ( Promise . resolve ( getH5PMetadata ( h5pBlob ) ) ) . resolves . toEqual ( {
172+ await expect ( getH5PMetadata ( h5pBlob ) ) . resolves . toEqual ( {
173+ title : 'Test file' ,
174+ } ) ;
175+ } ) ;
176+ } ) ;
177+ it . each ( [
178+ [ 'CC BY' , 1 ] ,
179+ [ 'CC BY-SA' , 2 ] ,
180+ [ 'CC BY-ND' , 3 ] ,
181+ [ 'CC BY-NC' , 4 ] ,
182+ [ 'CC BY-NC-SA' , 5 ] ,
183+ [ 'CC BY-NC-ND' , 6 ] ,
184+ [ 'CC0 1.0' , 8 ] ,
185+ ] ) ( 'getH5PMetadata should parse CC license %s' , async ( licenseName , licenseId ) => {
186+ const manifestFile = get_metadata_file ( { title : 'Test file' , license : licenseName } ) ;
187+ const zip = new JSZip ( ) ;
188+ zip . file ( 'h5p.json' , manifestFile ) ;
189+ await zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
190+ await expect ( getH5PMetadata ( h5pBlob ) ) . resolves . toEqual ( {
191+ title : 'Test file' ,
192+ license : licenseId ,
193+ } ) ;
194+ } ) ;
195+ } ) ;
196+ it . each ( [
197+ [ { role : 'Author' , name : 'Testing' } , 'author' ] ,
198+ [ { role : 'Editor' , name : 'Testing' } , 'aggregator' ] ,
199+ [ { role : 'Licensee' , name : 'Testing' } , 'copyright_holder' ] ,
200+ [ { role : 'Originator' , name : 'Testing' } , 'provider' ] ,
201+ ] ) ( 'getH5PMetadata should parse CC license %s' , async ( authorObj , field ) => {
202+ const manifestFile = get_metadata_file ( { title : 'Test file' , authors : [ authorObj ] } ) ;
203+ const zip = new JSZip ( ) ;
204+ zip . file ( 'h5p.json' , manifestFile ) ;
205+ await zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
206+ await expect ( getH5PMetadata ( h5pBlob ) ) . resolves . toEqual ( {
207+ title : 'Test file' ,
208+ [ field ] : authorObj . name ,
209+ } ) ;
210+ } ) ;
211+ } ) ;
212+ it ( 'getH5PMetadata should not extract Firstname Surname author' , async ( ) => {
213+ const manifestFile = get_metadata_file ( {
214+ title : 'Test file' ,
215+ authors : [ { name : 'Firstname Surname' , role : 'Author' } ] ,
216+ } ) ;
217+ const zip = new JSZip ( ) ;
218+ zip . file ( 'h5p.json' , manifestFile ) ;
219+ await zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
220+ await expect ( getH5PMetadata ( h5pBlob ) ) . resolves . toEqual ( {
173221 title : 'Test file' ,
174222 } ) ;
175223 } ) ;
@@ -178,17 +226,13 @@ describe('file store', () => {
178226 const manifestFile = get_metadata_file ( {
179227 title : 'Test file' ,
180228 language : 'en' ,
181- authors : 'author1' ,
182- license : 'license1' ,
183229 } ) ;
184230 const zip = new JSZip ( ) ;
185231 zip . file ( 'h5p.json' , manifestFile ) ;
186232 await zip . generateAsync ( { type : 'blob' } ) . then ( async function ( h5pBlob ) {
187- await expect ( Promise . resolve ( getH5PMetadata ( h5pBlob ) ) ) . resolves . toEqual ( {
233+ await expect ( getH5PMetadata ( h5pBlob ) ) . resolves . toEqual ( {
188234 title : 'Test file' ,
189235 language : 'en' ,
190- author : 'author1' ,
191- license : 'license1' ,
192236 } ) ;
193237 } ) ;
194238 } ) ;
0 commit comments