Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Added Start group processing controller #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions OathVideoPartnerSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@
E241041421C3FA8300036290 /* VRMRequestController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E241040C21C3FA8200036290 /* VRMRequestController.swift */; };
E241041621C3FAF400036290 /* VRMRequestControllerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E241041321C3FA8300036290 /* VRMRequestControllerTest.swift */; };
E241041721C3FB3A00036290 /* VRMRequestController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E241040C21C3FA8200036290 /* VRMRequestController.swift */; };
E241041921C4075300036290 /* StartVRMGroupProcessingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E241041821C4075300036290 /* StartVRMGroupProcessingController.swift */; };
E241041A21C4075300036290 /* StartVRMGroupProcessingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E241041821C4075300036290 /* StartVRMGroupProcessingController.swift */; };
E241041C21C4078E00036290 /* StartVRMGroupProcessingControllerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E241041B21C4078E00036290 /* StartVRMGroupProcessingControllerTest.swift */; };
E2629D07211228FA006ED117 /* TelemetryMetricsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2629D06211228FA006ED117 /* TelemetryMetricsTest.swift */; };
E2629D3C21147ECE006ED117 /* NoVpaidUrlFixture.json in Resources */ = {isa = PBXBuildFile; fileRef = E2629D3521147ECE006ED117 /* NoVpaidUrlFixture.json */; };
E2D649A8208A431D00152ADE /* VideoImpressionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D649A7208A431D00152ADE /* VideoImpressionTest.swift */; };
Expand Down Expand Up @@ -563,6 +566,8 @@
E231AA78213402C3008C5B6A /* AdStartTimeoutControllerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdStartTimeoutControllerTest.swift; sourceTree = "<group>"; };
E241040C21C3FA8200036290 /* VRMRequestController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VRMRequestController.swift; sourceTree = "<group>"; };
E241041321C3FA8300036290 /* VRMRequestControllerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VRMRequestControllerTest.swift; sourceTree = "<group>"; };
E241041821C4075300036290 /* StartVRMGroupProcessingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartVRMGroupProcessingController.swift; sourceTree = "<group>"; };
E241041B21C4078E00036290 /* StartVRMGroupProcessingControllerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartVRMGroupProcessingControllerTest.swift; sourceTree = "<group>"; };
E2629D06211228FA006ED117 /* TelemetryMetricsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TelemetryMetricsTest.swift; path = sources/telemetry/TelemetryMetricsTest.swift; sourceTree = "<group>"; };
E2629D3521147ECE006ED117 /* NoVpaidUrlFixture.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = NoVpaidUrlFixture.json; sourceTree = "<group>"; };
E2D649A7208A431D00152ADE /* VideoImpressionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoImpressionTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -721,6 +726,8 @@
E241041321C3FA8300036290 /* VRMRequestControllerTest.swift */,
06F8DBC121C2A2D40019021D /* StartAdProcessingController.swift */,
06F8DBC021C2A2D40019021D /* StartAdProcessingControllerTest.swift */,
E241041821C4075300036290 /* StartVRMGroupProcessingController.swift */,
E241041B21C4078E00036290 /* StartVRMGroupProcessingControllerTest.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1682,6 +1689,7 @@
5070535A1DAE9700003C023A /* Memoise.swift in Sources */,
50A11DCD1D59D7E000F4A068 /* ProcessAdItem.swift in Sources */,
50A11DCE1D59D7E000F4A068 /* ContextStartedDetector.swift in Sources */,
E241041A21C4075300036290 /* StartVRMGroupProcessingController.swift in Sources */,
50A11DD11D59D7E000F4A068 /* ExecuteOnce.swift in Sources */,
50A11DD31D59D7E000F4A068 /* VideoActionsDetector.swift in Sources */,
50A11DD41D59D7E000F4A068 /* XMLParser.swift in Sources */,
Expand Down Expand Up @@ -1724,6 +1732,7 @@
DEB112431E3277C1007E65BD /* Provider.swift in Sources */,
DEB4DA6F1C9B10EB00D6FD08 /* OnMainThread.swift in Sources */,
5087484E1C80783700F2511A /* TrackingPixelsGenerator.swift in Sources */,
E241041921C4075300036290 /* StartVRMGroupProcessingController.swift in Sources */,
504CA74A1C870225006D0ADF /* VideoLoadingDetector.swift in Sources */,
DE1F30341C99A7D500F70BAB /* Stub.swift in Sources */,
DE22C78D1D0EFAA000F47147 /* Disposable.swift in Sources */,
Expand Down Expand Up @@ -1855,6 +1864,7 @@
505136191C917A3B00629078 /* QuartileDetectorTests.swift in Sources */,
0640B18D20C983F3007DCB3F /* VerifyBuldTests.swift in Sources */,
0672086F2125A7AF007C07D7 /* ObserverTests.swift in Sources */,
E241041C21C4078E00036290 /* StartVRMGroupProcessingControllerTest.swift in Sources */,
508748271C80753800F2511A /* DictionaryParseJSONTests.swift in Sources */,
505136171C90A35100629078 /* UserActionInitiatedTests.swift in Sources */,
FE940A001F3DD56600A867CD /* IntentDetectorTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion PlayerCore
4 changes: 3 additions & 1 deletion sources/OVPSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ public struct OVPSDK {

func setupVRMWithNewCore() {
let adStartProcessing = StartAdProcessingController(dispatch: dispatcher)
let startGroupProcessing = StartVRMGroupProcessingController(dispatch: dispatcher)
let vrmRequestController = VRMRequestController(dispatch: dispatcher,
groupsMapper: mapGroups) { url -> Future<VRMProvider.Response?> in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

groupsMapper: mapGroups) { url in
return Future { fullfill in
self.vrmProvider.requestAds(with: .init(url: url,
cachePolicy: .useProtocolCachePolicy,
Expand All @@ -419,6 +420,7 @@ public struct OVPSDK {

_ = player.store.state.addObserver { state in
vrmRequestController.process(with: state)
startGroupProcessing.process(with: state)
}

_ = player.addObserver { playerProps in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2018, Oath Inc.
// Licensed under the terms of the MIT License. See LICENSE.md file in project root for terms.

import Foundation
import PlayerCore

final class StartVRMGroupProcessingController {

let dispatch: (PlayerCore.Action) -> ()

init(dispatch: @escaping (PlayerCore.Action) -> ()) {
self.dispatch = dispatch
}

func process(with state: PlayerCore.State) {
process(with: state.vrmCurrentGroup.currentGroup,
groupsQueue: state.vrmGroupsQueue.groupsQueue)
}

func process(with currentGroup: VRMCore.Group?,
groupsQueue: [VRMCore.Group]) {
guard currentGroup == nil,
let nextGroup = groupsQueue.first else { return }

dispatch(VRMCore.startGroupProcessing(group: nextGroup))

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2018, Oath Inc.
// Licensed under the terms of the MIT License. See LICENSE.md file in project root for terms.

import XCTest
@testable import OathVideoPartnerSDK
@testable import PlayerCore

class StartVRMGroupProcessingControllerTest: XCTestCase {

let recorder = Recorder()
let firstGroup = VRMCore.Group(items: [])
let secondGroup = VRMCore.Group(items: [])

var sut: StartVRMGroupProcessingController!

override func setUp() {
super.setUp()
let dispatch = recorder.hook("testDispatchFirstGroup") { target, recorded in
guard let target = target as? PlayerCore.VRMCore.StartGroupProcessing,
let recorded = recorded as? PlayerCore.VRMCore.StartGroupProcessing else {
return false
}
return target.group == recorded.group

} as (PlayerCore.Action) -> ()

sut = StartVRMGroupProcessingController(dispatch: dispatch)
}

override func tearDown() {
recorder.verify {}
recorder.clean()
super.tearDown()
}

func testDispatchFirstGroup() {
recorder.record {
sut.process(with: nil,
groupsQueue: [firstGroup, secondGroup])
}

recorder.verify {
sut.dispatch(VRMCore.startGroupProcessing(group: firstGroup))
}
}

func testStartLastGroup() {
recorder.record {
sut.process(with: nil,
groupsQueue: [secondGroup])
}

recorder.verify {
sut.dispatch(VRMCore.startGroupProcessing(group: secondGroup))
}
}

func testNonEmptyCurrentGroup() {
recorder.record {
sut.process(with: firstGroup,
groupsQueue: [secondGroup])
}

recorder.verify {}
}

func testEmptyCurrentGroupAndQueue() {
recorder.record {
sut.process(with: nil,
groupsQueue: [])
}

recorder.verify {}
}
}