@@ -11,6 +11,7 @@ import {
1111 parseIntegrity ,
1212 parseItem ,
1313 parseLicense ,
14+ parseLiveItem ,
1415 parseLocation ,
1516 parseLocked ,
1617 parsePerson ,
@@ -1888,7 +1889,183 @@ describe('parseImages', () => {
18881889 } )
18891890} )
18901891
1891- // parseLiveItem
1892+ describe ( 'parseLiveItem' , ( ) => {
1893+ it ( 'should parse complete liveItem object' , ( ) => {
1894+ const value = {
1895+ '@status' : 'live' ,
1896+ '@start' : '2023-06-15T15:00:00Z' ,
1897+ '@end' : '2023-06-15T16:00:00Z' ,
1898+ 'podcast:contentlink' : [
1899+ {
1900+ '@href' : 'https://example.com/livestream' ,
1901+ '#text' : 'Watch our livestream' ,
1902+ } ,
1903+ {
1904+ '@href' : 'https://example.com/chat' ,
1905+ '#text' : 'Join the chat' ,
1906+ } ,
1907+ ] ,
1908+ // Below are items from a regular Item object.
1909+ 'podcast:person' : [
1910+ {
1911+ '#text' : 'Jane Doe' ,
1912+ '@role' : 'host' ,
1913+ } ,
1914+ ] ,
1915+ 'podcast:location' : {
1916+ '#text' : 'New York, NY' ,
1917+ '@geo' : '40.7128,-74.0060' ,
1918+ } ,
1919+ }
1920+ const expected = {
1921+ status : 'live' ,
1922+ start : '2023-06-15T15:00:00Z' ,
1923+ end : '2023-06-15T16:00:00Z' ,
1924+ contentlinks : [
1925+ {
1926+ href : 'https://example.com/livestream' ,
1927+ display : 'Watch our livestream' ,
1928+ } ,
1929+ {
1930+ href : 'https://example.com/chat' ,
1931+ display : 'Join the chat' ,
1932+ } ,
1933+ ] ,
1934+ persons : [
1935+ {
1936+ display : 'Jane Doe' ,
1937+ role : 'host' ,
1938+ } ,
1939+ ] ,
1940+ location : {
1941+ display : 'New York, NY' ,
1942+ geo : '40.7128,-74.0060' ,
1943+ } ,
1944+ }
1945+
1946+ expect ( parseLiveItem ( value ) ) . toEqual ( expected )
1947+ } )
1948+
1949+ it ( 'should parse liveItem with only required fields' , ( ) => {
1950+ const value = {
1951+ '@status' : 'pending' ,
1952+ '@start' : '2023-06-15T15:00:00Z' ,
1953+ }
1954+ const expected = {
1955+ status : 'pending' ,
1956+ start : '2023-06-15T15:00:00Z' ,
1957+ }
1958+
1959+ expect ( parseLiveItem ( value ) ) . toEqual ( expected )
1960+ } )
1961+
1962+ it ( 'should parse liveItem with single contentLink as object' , ( ) => {
1963+ const value = {
1964+ '@status' : 'live' ,
1965+ '@start' : '2023-06-15T15:00:00Z' ,
1966+ 'podcast:contentlink' : {
1967+ '@href' : 'https://example.com/livestream' ,
1968+ '#text' : 'Watch our livestream' ,
1969+ } ,
1970+ }
1971+ const expected = {
1972+ status : 'live' ,
1973+ start : '2023-06-15T15:00:00Z' ,
1974+ contentlinks : [
1975+ {
1976+ href : 'https://example.com/livestream' ,
1977+ display : 'Watch our livestream' ,
1978+ } ,
1979+ ] ,
1980+ }
1981+
1982+ expect ( parseLiveItem ( value ) ) . toEqual ( expected )
1983+ } )
1984+
1985+ it ( 'should handle coercible values' , ( ) => {
1986+ const value = {
1987+ '@status' : 123 ,
1988+ '@start' : 456 ,
1989+ '@end' : 789 ,
1990+ }
1991+ const expected = {
1992+ status : '123' ,
1993+ start : '456' ,
1994+ end : '789' ,
1995+ }
1996+
1997+ expect ( parseLiveItem ( value ) ) . toEqual ( expected )
1998+ } )
1999+
2000+ it ( 'should handle objects with mixed valid and invalid properties' , ( ) => {
2001+ const value = {
2002+ '@status' : 'live' ,
2003+ '@start' : '2023-06-15T15:00:00Z' ,
2004+ '@invalid' : 'property' ,
2005+ 'podcast:contentlink' : [
2006+ {
2007+ '@href' : 'https://example.com/livestream' ,
2008+ '#text' : 'Watch our livestream' ,
2009+ } ,
2010+ {
2011+ '#text' : 'Invalid link' , // Missing href.
2012+ } ,
2013+ ] ,
2014+ }
2015+ const expected = {
2016+ status : 'live' ,
2017+ start : '2023-06-15T15:00:00Z' ,
2018+ contentlinks : [
2019+ {
2020+ href : 'https://example.com/livestream' ,
2021+ display : 'Watch our livestream' ,
2022+ } ,
2023+ ] ,
2024+ }
2025+
2026+ expect ( parseLiveItem ( value ) ) . toEqual ( expected )
2027+ } )
2028+
2029+ it ( 'should return undefined if status is missing' , ( ) => {
2030+ const value = {
2031+ '@start' : '2023-06-15T15:00:00Z' ,
2032+ '@end' : '2023-06-15T16:00:00Z' ,
2033+ }
2034+
2035+ expect ( parseLiveItem ( value ) ) . toBeUndefined ( )
2036+ } )
2037+
2038+ it ( 'should return undefined if start is missing' , ( ) => {
2039+ const value = {
2040+ '@status' : 'live' ,
2041+ '@end' : '2023-06-15T16:00:00Z' ,
2042+ }
2043+
2044+ expect ( parseLiveItem ( value ) ) . toBeUndefined ( )
2045+ } )
2046+
2047+ it ( 'should return undefined for empty objects' , ( ) => {
2048+ const value = { }
2049+
2050+ expect ( parseLiveItem ( value ) ) . toBeUndefined ( )
2051+ } )
2052+
2053+ it ( 'should return undefined for objects with only unrelated properties' , ( ) => {
2054+ const value = {
2055+ '@unrelated' : 'property' ,
2056+ random : 'value' ,
2057+ }
2058+
2059+ expect ( parseLiveItem ( value ) ) . toBeUndefined ( )
2060+ } )
2061+
2062+ it ( 'should return undefined for not supported input' , ( ) => {
2063+ expect ( parseLiveItem ( 'not an object' ) ) . toBeUndefined ( )
2064+ expect ( parseLiveItem ( undefined ) ) . toBeUndefined ( )
2065+ expect ( parseLiveItem ( null ) ) . toBeUndefined ( )
2066+ expect ( parseLiveItem ( [ ] ) ) . toBeUndefined ( )
2067+ } )
2068+ } )
18922069
18932070describe ( 'parseContentLink' , ( ) => {
18942071 it ( 'should parse complete content link object' , ( ) => {
0 commit comments