@@ -14,7 +14,6 @@ import io.mockk.impl.annotations.MockK
1414import kotlinx.serialization.decodeFromString
1515import kotlinx.serialization.json.buildJsonObject
1616import kotlinx.serialization.json.put
17- import org.json.JSONException
1817import org.json.JSONObject
1918import org.junit.Assert.assertEquals
2019import org.junit.Before
@@ -64,9 +63,11 @@ class NielsenDCRDestinationTest {
6463 }
6564 """ .trimIndent()
6665 )
66+
6767 init {
6868 MockKAnnotations .init (this )
6969 }
70+
7071 @Before
7172 fun setUp () {
7273 mockedNielsenDcrDestination = NielsenDCRDestination ()
@@ -88,6 +89,64 @@ class NielsenDCRDestinationTest {
8889 mockedNielsenDcrDestination.appSdk = mockedAppSdk
8990 }
9091
92+ @Test
93+ fun `screen handled correctly` () {
94+ val sampleEvent = ScreenEvent (
95+ name = " Screen 1" ,
96+ category = " Category 1" ,
97+ properties = buildJsonObject {
98+ put(" variation" , " New Screen" )
99+ put(" assetId" , 123456 )
100+ }
101+ ).apply {
102+ anonymousId = " anonymous_UserID-123"
103+ context = emptyJsonObject
104+ integrations = emptyJsonObject
105+ }
106+ mockedNielsenDcrDestination.screen(sampleEvent)
107+ val screenExpectedMetadata = JSONObject ()
108+ screenExpectedMetadata.put(" assetid" , " 123456" )
109+ screenExpectedMetadata.put(" section" , " Screen 1" )
110+ screenExpectedMetadata.put(" type" , " static" )
111+ screenExpectedMetadata.put(" segB" , " " )
112+ screenExpectedMetadata.put(" segC" , " " )
113+ verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
114+ }
115+
116+ @Test
117+ fun `screen handled with custom settings correctly` () {
118+ mockedNielsenDcrDestination.nielsenDCRSettings?.customSectionProperty = " customSection"
119+ mockedNielsenDcrDestination.nielsenDCRSettings?.contentAssetIdPropertyName = " customContentAssetId"
120+ val sampleEvent = ScreenEvent (
121+ name = " Screen 1" ,
122+ category = " Category 1" ,
123+ properties = buildJsonObject {
124+ put(" variation" , " New Screen" )
125+ put(" customSection" , " customSection" )
126+ put(" customContentAssetId" , 123456 )
127+ }
128+ ).apply {
129+ anonymousId = " anonymous_UserID-123"
130+ context = emptyJsonObject
131+ integrations = buildJsonObject {
132+ put(" nielsen-dcr" , buildJsonObject {
133+ put(" segB" , " segmentB" )
134+ put(" segC" , " segmentC" )
135+ put(" crossId1" , " Cross Id 1 value" )
136+ })
137+ }
138+ }
139+ mockedNielsenDcrDestination.screen(sampleEvent)
140+ val screenExpectedMetadata = JSONObject ()
141+ screenExpectedMetadata.put(" assetid" , " 123456" )
142+ screenExpectedMetadata.put(" section" , " customSection" )
143+ screenExpectedMetadata.put(" type" , " static" )
144+ screenExpectedMetadata.put(" segB" , " segmentB" )
145+ screenExpectedMetadata.put(" segC" , " segmentC" )
146+ screenExpectedMetadata.put(" crossId1" , " Cross Id 1 value" )
147+ verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
148+ }
149+
91150 @Test
92151 fun `settings are updated correctly` () {
93152
@@ -138,7 +197,6 @@ class NielsenDCRDestinationTest {
138197 }
139198
140199 @Test
141- @Throws(JSONException ::class )
142200 fun `track for Video Playback Started with live stream handled correctly` () {
143201 val sampleEvent = TrackEvent (
144202 event = " Video Playback Started" ,
@@ -698,7 +756,6 @@ class NielsenDCRDestinationTest {
698756 verify { mockedAppSdk.loadMetadata(matchJSONObject(expectedMetaData)) }
699757 }
700758
701-
702759 @Test
703760 fun `track for Video Ad Started with type pre-roll handled correctly` () {
704761 val sampleEvent = TrackEvent (
@@ -827,7 +884,6 @@ class NielsenDCRDestinationTest {
827884 JSONAssert .assertEquals(adExpectedMetadata, adCaptureSlot.captured, JSONCompareMode .LENIENT )
828885 }
829886
830-
831887 @Test
832888 fun `track for Video Ad Completed handled correctly` () {
833889 val sampleEvent = TrackEvent (
@@ -848,63 +904,4 @@ class NielsenDCRDestinationTest {
848904 mockedNielsenDcrDestination.track(sampleEvent)
849905 verify{mockedAppSdk.stop()}
850906 }
851-
852-
853- @Test
854- fun `screen handled correctly` () {
855- val sampleEvent = ScreenEvent (
856- name = " Screen 1" ,
857- category = " Category 1" ,
858- properties = buildJsonObject {
859- put(" variation" , " New Screen" )
860- put(" assetId" , 123456 )
861- }
862- ).apply {
863- anonymousId = " anonymous_UserID-123"
864- context = emptyJsonObject
865- integrations = emptyJsonObject
866- }
867- mockedNielsenDcrDestination.screen(sampleEvent)
868- val screenExpectedMetadata = JSONObject ()
869- screenExpectedMetadata.put(" assetid" , " 123456" )
870- screenExpectedMetadata.put(" section" , " Screen 1" )
871- screenExpectedMetadata.put(" type" , " static" )
872- screenExpectedMetadata.put(" segB" , " " )
873- screenExpectedMetadata.put(" segC" , " " )
874- verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
875- }
876-
877- @Test
878- fun `screen handled with custom settings correctly` () {
879- mockedNielsenDcrDestination.nielsenDCRSettings?.customSectionProperty = " customSection"
880- mockedNielsenDcrDestination.nielsenDCRSettings?.contentAssetIdPropertyName = " customContentAssetId"
881- val sampleEvent = ScreenEvent (
882- name = " Screen 1" ,
883- category = " Category 1" ,
884- properties = buildJsonObject {
885- put(" variation" , " New Screen" )
886- put(" customSection" , " customSection" )
887- put(" customContentAssetId" , 123456 )
888- }
889- ).apply {
890- anonymousId = " anonymous_UserID-123"
891- context = emptyJsonObject
892- integrations = buildJsonObject {
893- put(" nielsen-dcr" , buildJsonObject {
894- put(" segB" , " segmentB" )
895- put(" segC" , " segmentC" )
896- put(" crossId1" , " Cross Id 1 value" )
897- })
898- }
899- }
900- mockedNielsenDcrDestination.screen(sampleEvent)
901- val screenExpectedMetadata = JSONObject ()
902- screenExpectedMetadata.put(" assetid" , " 123456" )
903- screenExpectedMetadata.put(" section" , " customSection" )
904- screenExpectedMetadata.put(" type" , " static" )
905- screenExpectedMetadata.put(" segB" , " segmentB" )
906- screenExpectedMetadata.put(" segC" , " segmentC" )
907- screenExpectedMetadata.put(" crossId1" , " Cross Id 1 value" )
908- verify { mockedAppSdk.loadMetadata(matchJSONObject(screenExpectedMetadata)) }
909- }
910907}
0 commit comments