Skip to content

Commit

Permalink
Add UserAgentStartUseCase
Browse files Browse the repository at this point in the history
  • Loading branch information
eofster committed Oct 22, 2018
1 parent 410591e commit 4d290b8
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Telephone.xcodeproj/project.pbxproj
Expand Up @@ -416,6 +416,8 @@
8AB677F81F0BFD1E001A47A2 /* ContactCallHistoryRecordGetUseCaseOutputSpy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB677F71F0BFD1E001A47A2 /* ContactCallHistoryRecordGetUseCaseOutputSpy.swift */; };
8AB677FA1F0D19FA001A47A2 /* URI+ContactCallHistoryRecordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB677F91F0D19FA001A47A2 /* URI+ContactCallHistoryRecordTests.swift */; };
8AB677FC1F0D1B3C001A47A2 /* URI+ContactCallHistoryRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB677FB1F0D1B3C001A47A2 /* URI+ContactCallHistoryRecord.swift */; };
8AB78263217A426F002E4DFB /* UserAgentStartUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB78262217A426F002E4DFB /* UserAgentStartUseCase.swift */; };
8AB78265217A4408002E4DFB /* UserAgentStartUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB78264217A4408002E4DFB /* UserAgentStartUseCaseTests.swift */; };
8ABB14191CEC83990056CEDC /* StoreViewStateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8ABB14181CEC83990056CEDC /* StoreViewStateMachine.swift */; };
8ABB141B1CEC86A90056CEDC /* StoreViewStateMachineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8ABB141A1CEC86A90056CEDC /* StoreViewStateMachineTests.swift */; };
8ABB141C1CEC86B10056CEDC /* StoreViewStateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8ABB14181CEC83990056CEDC /* StoreViewStateMachine.swift */; };
Expand Down Expand Up @@ -1297,6 +1299,8 @@
8AB677F71F0BFD1E001A47A2 /* ContactCallHistoryRecordGetUseCaseOutputSpy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactCallHistoryRecordGetUseCaseOutputSpy.swift; sourceTree = "<group>"; };
8AB677F91F0D19FA001A47A2 /* URI+ContactCallHistoryRecordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "URI+ContactCallHistoryRecordTests.swift"; path = "UseCasesTests/URI+ContactCallHistoryRecordTests.swift"; sourceTree = SOURCE_ROOT; };
8AB677FB1F0D1B3C001A47A2 /* URI+ContactCallHistoryRecord.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URI+ContactCallHistoryRecord.swift"; sourceTree = "<group>"; };
8AB78262217A426F002E4DFB /* UserAgentStartUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserAgentStartUseCase.swift; sourceTree = "<group>"; };
8AB78264217A4408002E4DFB /* UserAgentStartUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UserAgentStartUseCaseTests.swift; path = UseCasesTests/UserAgentStartUseCaseTests.swift; sourceTree = SOURCE_ROOT; };
8ABB14181CEC83990056CEDC /* StoreViewStateMachine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreViewStateMachine.swift; sourceTree = "<group>"; };
8ABB141A1CEC86A90056CEDC /* StoreViewStateMachineTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StoreViewStateMachineTests.swift; path = TelephoneTests/StoreViewStateMachineTests.swift; sourceTree = SOURCE_ROOT; };
8ABC9A6E1D522E4D004AC220 /* ReceiptAttributesValidation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReceiptAttributesValidation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2891,6 +2895,8 @@
AA277A631BD542C80030ECE4 /* UserAgentEventTarget.swift */,
AA25AB511BE0F7FB00E677A4 /* UserAgentEventTargets.swift */,
AA25AB4F1BE0F7B600E677A4 /* UserAgentEventTargetsTests.swift */,
8AB78262217A426F002E4DFB /* UserAgentStartUseCase.swift */,
8AB78264217A4408002E4DFB /* UserAgentStartUseCaseTests.swift */,
);
name = "User Agent";
sourceTree = "<group>";
Expand Down Expand Up @@ -4007,6 +4013,7 @@
8A1AF2641F039C4800B9999D /* EnqueuingContactsChangeEventTarget.swift in Sources */,
8ACF85161EE95113006E88FB /* EnqueueingCallHistoryRecordRemoveUseCaseFactory.swift in Sources */,
8ADA26F41C986C9E0066B224 /* SoundConfigurationLoadUseCase.swift in Sources */,
8AB78263217A426F002E4DFB /* UserAgentStartUseCase.swift in Sources */,
8A11B3CC1DDB4640002EDA93 /* URI.swift in Sources */,
8A7E21541CC411F3000D02C3 /* ServiceAddress.swift in Sources */,
8A645FF11E12C8AD00515151 /* MatchedContact.swift in Sources */,
Expand Down Expand Up @@ -4208,6 +4215,7 @@
8A2758721EF1850E002E93D8 /* EnqueuingContactCallHistoryRecordGetUseCaseOutputTests.swift in Sources */,
8A1AF25B1F02AEC200B9999D /* LazyDiscardingContactMatchingIndexTests.swift in Sources */,
8AC1A4431C67C35D007778A2 /* DefaultSoundPlaybackUseCaseTests.swift in Sources */,
8AB78265217A4408002E4DFB /* UserAgentStartUseCaseTests.swift in Sources */,
8AD012AD2126F46A00619781 /* AudioDevicesEventsUserAgentSoundIOSelectionUseCaseTests.swift in Sources */,
8A7E21521CC3F6A5000D02C3 /* ServiceAddressTests.swift in Sources */,
8A7292421EE041AA00338592 /* EnqueuingContactCallHistoryRecordGetAllUseCaseOutputTests.swift in Sources */,
Expand Down
2 changes: 0 additions & 2 deletions Telephone/AKSIPCall.h
Expand Up @@ -27,8 +27,6 @@

NS_ASSUME_NONNULL_BEGIN

extern const NSInteger kAKSIPCallsMax;

typedef NS_ENUM(NSUInteger, AKSIPCallState) {
// Before INVITE is sent or received.
kAKSIPCallNullState = PJSIP_INV_STATE_NULL,
Expand Down
2 changes: 0 additions & 2 deletions Telephone/AKSIPCall.m
Expand Up @@ -28,8 +28,6 @@
#define THIS_FILE "AKSIPCall.m"


const NSInteger kAKSIPCallsMax = 8;

@interface AKSIPCall () {
URI *_remote;
BOOL _incoming;
Expand Down
2 changes: 2 additions & 0 deletions Telephone/AKSIPUserAgent.h
Expand Up @@ -87,6 +87,8 @@ extern const NSInteger kAKSIPUserAgentInvalidIdentifier;
// A pool used by the underlying PJSUA library of the receiver.
@property(readonly, assign) pj_pool_t *pool;

@property(nonatomic, assign) NSInteger maxCalls;

// An array of DNS servers to use by the receiver. If set, DNS SRV will be
// enabled. Only first kAKSIPUserAgentNameServersMax are used.
@property(nonatomic, copy) NSArray *nameServers;
Expand Down
2 changes: 1 addition & 1 deletion Telephone/AKSIPUserAgent.m
Expand Up @@ -309,7 +309,7 @@ - (void)thread_startInAutoreleasePoolWithCompletion:(void (^ _Nonnull)(BOOL didS
pjsua_media_config_default(&mediaConfig);
pjsua_transport_config_default(&transportConfig);

userAgentConfig.max_calls = (unsigned)kAKSIPCallsMax;
userAgentConfig.max_calls = (unsigned)self.maxCalls;
userAgentConfig.use_timer = PJSUA_SIP_TIMER_INACTIVE;

if ([[self nameServers] count] > 0) {
Expand Down
2 changes: 2 additions & 0 deletions UseCases/UserAgent.swift
Expand Up @@ -20,6 +20,8 @@ import Domain

public protocol UserAgent: class {
var isStarted: Bool { get }
var maxCalls: Int { get set }
func start()
func audioDevices() throws -> [UserAgentAudioDevice]
func updateAudioDevices()
func selectSoundIODeviceIDs(input: Int, output: Int) throws
Expand Down
49 changes: 49 additions & 0 deletions UseCases/UserAgentStartUseCase.swift
@@ -0,0 +1,49 @@
//
// UserAgentStartUseCase.swift
// Telephone
//
// Copyright © 2008-2016 Alexey Kuznetsov
// Copyright © 2016-2018 64 Characters
//
// Telephone is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Telephone is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//

public final class UserAgentStartUseCase {
private lazy var purchaseCheck: UseCase = {
return self.factory.make(output: WeakPurchaseCheckUseCaseOutput(origin: self))
}()

private let agent: UserAgent
private let factory: PurchaseCheckUseCaseFactory

public init(agent: UserAgent, factory: PurchaseCheckUseCaseFactory) {
self.agent = agent
self.factory = factory
}
}

extension UserAgentStartUseCase: UseCase {
public func execute() {
purchaseCheck.execute()
}
}

extension UserAgentStartUseCase: PurchaseCheckUseCaseOutput {
public func didCheckPurchase(expiration: Date) {
agent.maxCalls = 30
agent.start()
}

public func didFailCheckingPurchase() {
agent.maxCalls = 3
agent.start()
}
}
7 changes: 7 additions & 0 deletions UseCasesTestDoubles/UserAgentSpy.swift
Expand Up @@ -21,6 +21,9 @@ import UseCases

public final class UserAgentSpy {
public var isStarted = false
public var maxCalls = 0

public var didCallStart = false

public private(set) var didCallAudioDevices = false
public var audioDevicesResult = [UserAgentAudioDevice]()
Expand All @@ -36,6 +39,10 @@ public final class UserAgentSpy {
}

extension UserAgentSpy: UserAgent {
public func start() {
didCallStart = true
}

public func audioDevices() throws -> [UserAgentAudioDevice] {
didCallAudioDevices = true
return audioDevicesResult
Expand Down
43 changes: 43 additions & 0 deletions UseCasesTests/UserAgentStartUseCaseTests.swift
@@ -0,0 +1,43 @@
//
// UserAgentStartUseCaseTests.swift
// Telephone
//
// Copyright © 2008-2016 Alexey Kuznetsov
// Copyright © 2016-2018 64 Characters
//
// Telephone is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Telephone is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//

import UseCases
import UseCasesTestDoubles
import XCTest

final class UserAgentStartUseCaseTests: XCTestCase {
func testSetsMaxCallsToThirtyAndStartsUserAgentWhenReceiptIsValid() {
let agent = UserAgentSpy()
let sut = UserAgentStartUseCase(agent: agent, factory: PurchaseCheckUseCaseFactory(receipt: ValidReceipt()))

sut.execute()

XCTAssertEqual(agent.maxCalls, 30)
XCTAssertTrue(agent.didCallStart)
}

func testSetsMaxCallsToThreeAndStartsUserAgentWhenReceiptIsInvalid() {
let agent = UserAgentSpy()
let sut = UserAgentStartUseCase(agent: agent, factory: PurchaseCheckUseCaseFactory(receipt: InvalidReceipt()))

sut.execute()

XCTAssertEqual(agent.maxCalls, 3)
XCTAssertTrue(agent.didCallStart)
}
}

0 comments on commit 4d290b8

Please sign in to comment.