Skip to content

Commit

Permalink
SPT-1998 fix pr
Browse files Browse the repository at this point in the history
  • Loading branch information
mrandrewsmith committed Apr 24, 2024
1 parent 2de673b commit 66df030
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 41 deletions.
6 changes: 1 addition & 5 deletions NodeKit/CacheNode/UrlCacheReaderNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public enum BaseUrlCacheReaderError: Error {
/// Сам по себе узел является листом и не может быть встроен в сквозную цепочку.
open class UrlCacheReaderNode: AsyncNode {

public var needsToThrowError: Bool

public init(needsToThrowError: Bool) {
self.needsToThrowError = needsToThrowError
}
public init() { }

/// Посылает запрос в кэш и пытается сериализовать данные в JSON.
open func process(
Expand Down
12 changes: 0 additions & 12 deletions NodeKit/Layers/Utils/AccessSafe/TokenRefresherActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ public protocol TokenRefresherActorProtocol: Actor {
/// - Parameter logContext: контекст для записи логов
/// - Returns результат обновления токена
func refresh(logContext: LoggingContextProtocol) async -> NodeResult<Void>

/// Обновлят цепочку обновления токена
///
/// - Parameter tokenRefreshChain: цепочка обновления токена
func update(tokenRefreshChain: some AsyncNode<Void, Void>)
}

/// Релизация протокола актора для создания таски обновления токена
Expand Down Expand Up @@ -51,13 +46,6 @@ actor TokenRefresherActor: TokenRefresherActorProtocol {
}
return await task.value
}

/// Обновлят цепочку обновления токена
///
/// - Parameter tokenRefreshChain: цепочка обновления токена
func update(tokenRefreshChain: some AsyncNode<Void, Void>) {
self.tokenRefreshChain = tokenRefreshChain
}

private func resultFromNewTask(logContext: LoggingContextProtocol) async -> NodeResult<Void> {
let refreshTask = Task {
Expand Down
14 changes: 9 additions & 5 deletions NodeKit/Layers/Utils/AccessSafe/TokenRefresherNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import Foundation
/// Ответ возращает в той очереди, из которой узел был вызыван.
open class TokenRefresherNode: AsyncNode {

/// Цепочка для обновления токена.
public let tokenRefreshChain: any AsyncNode<Void, Void>
/// Актор для обновления токена.
private let tokenRefresherActor: TokenRefresherActorProtocol

/// Инициаллизирует
///
/// - Parameter tokenRefreshChain: Цепочка для обновления токена.
public init(tokenRefreshChain: any AsyncNode<Void, Void>) {
self.tokenRefresherActor = TokenRefresherActor(tokenRefreshChain: tokenRefreshChain)
}

/// Инициаллизирует
///
/// - Parameter tokenRefresherActor: Актор для обновления токена.
public init(tokenRefreshChain: any AsyncNode<Void, Void>, tokenRefresherActor: TokenRefresherActorProtocol? = nil) {
self.tokenRefreshChain = tokenRefreshChain
self.tokenRefresherActor = tokenRefresherActor ?? TokenRefresherActor(tokenRefreshChain: tokenRefreshChain)
public init(tokenRefresherActor: TokenRefresherActorProtocol) {
self.tokenRefresherActor = tokenRefresherActor
}

/// Проверяет, был ли отправлен запрос на обновление токена
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class CacheReaderNodeTests: XCTestCase {
override func setUp() {
super.setUp()
logContextMock = LoggingContextMock()
sut = UrlCacheReaderNode(needsToThrowError: true)
sut = UrlCacheReaderNode()
}

override func tearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ final class TokenRefresherActorTests: XCTestCase {

// MARK: - Tests

func testUpdate_thenChainUpdated() async {
// given

let expectedChain = AsyncNodeMock<Void, Void>()
expectedChain.stubbedAsyncProccessResult = .success(())

// when

await sut.update(tokenRefreshChain: expectedChain)
_ = await sut.refresh(logContext: logContextMock)

// then

XCTAssertEqual(expectedChain.invokedAsyncProcessCount, 1)
XCTAssertFalse(tokenRefreshChain.invokedAsyncProcess)
}

func testRefresh_thenProcessCalledOnce() async {
// given

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class TokenRefresherNodeTests: XCTestCase {
logContextMock = LoggingContextMock()
tokenRefreshChainMock = AsyncNodeMock()
sut = TokenRefresherNode(
tokenRefreshChain: tokenRefreshChainMock,
tokenRefresherActor: tokenRefresherActorMock
)
}
Expand Down

0 comments on commit 66df030

Please sign in to comment.