-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPT-1998 Мелкий рефакторинг + моки на билдер (1) #133
Merged
mrandrewsmith
merged 7 commits into
5.0.0
from
SPT-1998-refactor-builders-and-add-mocks
May 24, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6b07004
SPT-1998 refactor builders and add mocks
mrandrewsmith 01319c9
SPT-1998 append missed files
mrandrewsmith 0e11984
SPT-1998 append builder tests
mrandrewsmith 839c8d0
SPT-1998 remove unused files
mrandrewsmith 332afd4
SPT-1998 add merge node
mrandrewsmith c114116
SPT-1998 fix node stub type
mrandrewsmith a9b9219
SPT-1998 fix rebase
mrandrewsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Example/Modules/MockServer/MockServer/FakeChainBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// FakeChainBuilder.swift | ||
// | ||
// | ||
// Created by Andrei Frolov on 02.05.24. | ||
// | ||
|
||
import NodeKit | ||
import NodeKitMock | ||
|
||
public final class FakeChainBuilder<Route: URLRouteProvider>: URLChainBuilder<Route> { | ||
|
||
public init() { | ||
super.init( | ||
serviceChainProvider: URLServiceChainProvider(session: NetworkMock().urlSession) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// UrlCacheReaderNode.swift | ||
// URLCacheReaderNode.swift | ||
// CoreNetKitWithExample | ||
// | ||
// Created by Александр Кравченков on 28/11/2018. | ||
|
@@ -8,50 +8,54 @@ | |
|
||
import Foundation | ||
|
||
/// Ошибки для узла `UrlCacheReaderNode` | ||
/// Ошибки для узла `URLCacheReaderNode` | ||
/// | ||
/// - cantLoadDataFromCache: Случается, если запрос в кэш завершился с ошибкой | ||
/// - cantSerializeJson: Случается, если запрос в кэш завершился успешно, но не удалось сериализовать ответ в JSON | ||
/// - cantCastToJson: Случается, если сериализовать ответ удалось, но каст к `Json` или к `[Json]` завершился с ошибкой | ||
public enum BaseUrlCacheReaderError: Error { | ||
public enum BaseURLCacheReaderError: Error { | ||
case cantLoadDataFromCache | ||
case cantSerializeJson | ||
case cantCastToJson | ||
} | ||
|
||
/// Этот узел отвечает за чтение данных из URL кэша. | ||
/// Сам по себе узел является листом и не может быть встроен в сквозную цепочку. | ||
open class UrlCacheReaderNode: AsyncNode { | ||
open class URLCacheReaderNode: AsyncNode { | ||
|
||
public init() { } | ||
public var needsToThrowError: Bool | ||
|
||
public init(needsToThrowError: Bool) { | ||
self.needsToThrowError = needsToThrowError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а зачем оно добавилось, если никак не используется? |
||
} | ||
|
||
/// Посылает запрос в кэш и пытается сериализовать данные в JSON. | ||
open func process( | ||
_ data: UrlNetworkRequest, | ||
_ data: URLNetworkRequest, | ||
logContext: LoggingContextProtocol | ||
) async -> NodeResult<Json> { | ||
guard let cachedResponse = extractCachedUrlResponse(data.urlRequest) else { | ||
return .failure(BaseUrlCacheReaderError.cantLoadDataFromCache) | ||
guard let cachedResponse = extractCachedURLResponse(data.urlRequest) else { | ||
return .failure(BaseURLCacheReaderError.cantLoadDataFromCache) | ||
} | ||
|
||
guard let jsonObjsect = try? JSONSerialization.jsonObject( | ||
with: cachedResponse.data, | ||
options: .allowFragments | ||
) else { | ||
return .failure(BaseUrlCacheReaderError.cantSerializeJson) | ||
return .failure(BaseURLCacheReaderError.cantSerializeJson) | ||
} | ||
|
||
guard let json = jsonObjsect as? Json else { | ||
guard let json = jsonObjsect as? [Json] else { | ||
return .failure(BaseUrlCacheReaderError.cantCastToJson) | ||
return .failure(BaseURLCacheReaderError.cantCastToJson) | ||
} | ||
return .success([MappingUtils.arrayJsonKey: json]) | ||
} | ||
|
||
return .success(json) | ||
} | ||
|
||
private func extractCachedUrlResponse(_ request: URLRequest) -> CachedURLResponse? { | ||
private func extractCachedURLResponse(_ request: URLRequest) -> CachedURLResponse? { | ||
if let response = URLCache.shared.cachedResponse(for: request) { | ||
return response | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С новым
MergedAsyncStreamNode
эту ноду можно упразднить и встраивать кэширование как mergedNode где первый это CacheReader, а второй это NextProcessor.