From 17d46dde59507cf5907d44d2b499bb216fb8b599 Mon Sep 17 00:00:00 2001 From: Farshad Date: Wed, 18 Jan 2023 19:55:11 +0100 Subject: [PATCH] feat: opens the LetSee to be overridable --- .../DefaultScenarioProcessor.swift | 10 ++-- .../DirectoryProcessing.swift | 2 +- .../DirectoryRequestPath.swift | 6 +-- .../FileDirectoryProcessor.swift | 4 +- .../DirectoryProcessor/FileInformation.swift | 14 +++--- .../FileInformationBasic.swift | 13 +++--- .../DirectoryProcessor/FileNameParsing.swift | 2 +- .../MockFileInformation.swift | 16 +++++-- .../DirectoryProcessor/MockProcessing.swift | 2 +- .../RawDirectoryProcessor.swift | 6 +-- .../ScenarioProcessing.swift | 2 +- Sources/LetSee/Core/LetSee.swift | 27 ++++++----- .../Core/Services/CategorisedMocks.swift | 2 +- .../LetSee/Core/Services/LetSeeProtocol.swift | 2 +- .../LetSee/InAppView/ScenariosListView.swift | 44 +++++++++--------- .../FileDirectoryProcessorTests.swift | 2 +- Tests/LetSeeTests/LetSeeTests.swift | 46 ++++++++----------- .../FolderWith2Configs/.pathconfigs.json | 3 -- .../details/.pathconfigs.json | 3 -- .../orders/.pathconfigs.json | 3 -- .../Mocks/FolderWithConfig/.pathconfigs.json | 3 -- .../RawDirectoryProcessorTests.swift | 2 +- 22 files changed, 107 insertions(+), 107 deletions(-) delete mode 100644 Tests/LetSeeTests/Mocks/FolderWith2Configs/.pathconfigs.json delete mode 100644 Tests/LetSeeTests/Mocks/FolderWith2Configs/details/.pathconfigs.json delete mode 100644 Tests/LetSeeTests/Mocks/FolderWith2Configs/orders/.pathconfigs.json delete mode 100644 Tests/LetSeeTests/Mocks/FolderWithConfig/.pathconfigs.json diff --git a/Sources/LetSee/Core/DirectoryProcessor/DefaultScenarioProcessor.swift b/Sources/LetSee/Core/DirectoryProcessor/DefaultScenarioProcessor.swift index bb17eba..cf389e1 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/DefaultScenarioProcessor.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/DefaultScenarioProcessor.swift @@ -22,7 +22,7 @@ struct DefaultScenarioProcessor: ScenarioProcessing { scenarioFileInformation.steps.forEach { item in let overriddenPath = globalConfigs?.hasMap(for: item.folder)?.to let mockKey = overriddenPath != nil ? overriddenPath! + item.folder : item.folder - guard let cleanedName = try? JSONFileNameParser().parse(.init(name: item.responseFileName, filePath: URL(string: "/api/")!, relativePath: "")), + guard let cleanedName = try? mockFileNameParse.parse(.init(name: item.responseFileName, filePath: URL(string: "/api/")!, relativePath: "")), let mocks = requestToMockMapper(mockKey), let mock = mocks.mocks.first(where: {$0.name.caseInsensitiveCompare(cleanedName.displayName) == .orderedSame}) else { @@ -39,14 +39,18 @@ struct DefaultScenarioProcessor: ScenarioProcessing { private let _process: (String) throws -> Dictionary private let scenarioDecoder: PropertyListDecoder - + private let mockFileNameParse: FileNameParsing init(directoryProcessor: DS = FileDirectoryProcessor(), - scenarioDecoder: PropertyListDecoder = PropertyListDecoder() + scenarioDecoder: PropertyListDecoder = PropertyListDecoder(), + mockFileNameParse: FileNameParsing = JSONFileNameParser() ) + where DS: DirectoryProcessing, DS.Information == Self.Information { self._process = directoryProcessor.process self.scenarioDecoder = scenarioDecoder + self.mockFileNameParse = mockFileNameParse } + func process(_ path: String) throws -> Dictionary { try _process(path) } diff --git a/Sources/LetSee/Core/DirectoryProcessor/DirectoryProcessing.swift b/Sources/LetSee/Core/DirectoryProcessor/DirectoryProcessing.swift index a26b8ad..446447d 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/DirectoryProcessing.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/DirectoryProcessing.swift @@ -6,7 +6,7 @@ // import Foundation -protocol DirectoryProcessing { +public protocol DirectoryProcessing { associatedtype Information: FileInformationBasic, Comparable /// Analysed the directory and sub directories and creates a dictionary of them func process(_ path: String) throws -> Dictionary diff --git a/Sources/LetSee/Core/DirectoryProcessor/DirectoryRequestPath.swift b/Sources/LetSee/Core/DirectoryProcessor/DirectoryRequestPath.swift index 8e13668..3f82993 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/DirectoryRequestPath.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/DirectoryRequestPath.swift @@ -7,9 +7,9 @@ import Foundation -struct DirectoryRequestPath: Hashable, Comparable { - static func < (lhs: DirectoryRequestPath, rhs: DirectoryRequestPath) -> Bool { - lhs.path < rhs.path +public struct DirectoryRequestPath: Hashable, Comparable { + public static func < (lhs: DirectoryRequestPath, rhs: DirectoryRequestPath) -> Bool { + lhs.path.absoluteString < rhs.path.absoluteString } let path: URL diff --git a/Sources/LetSee/Core/DirectoryProcessor/FileDirectoryProcessor.swift b/Sources/LetSee/Core/DirectoryProcessor/FileDirectoryProcessor.swift index 5e3c3fb..6686190 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/FileDirectoryProcessor.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/FileDirectoryProcessor.swift @@ -64,7 +64,7 @@ struct FileDirectoryProcessor: DirectoryProcessing { } } -struct GlobalMockDirectoryConfig: Decodable, Equatable { +public struct GlobalMockDirectoryConfig: Decodable, Equatable { struct Map: Decodable, Equatable { let folder: String let to: String @@ -89,7 +89,7 @@ struct GlobalMockDirectoryConfig: Decodable, Equatable { case maps } - init(from decoder: Decoder) throws { + public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.maps = try container.decode([GlobalMockDirectoryConfig.Map].self, forKey: .maps).sorted(by: {$0.folder > $1.folder}) } diff --git a/Sources/LetSee/Core/DirectoryProcessor/FileInformation.swift b/Sources/LetSee/Core/DirectoryProcessor/FileInformation.swift index b23e320..2111ffc 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/FileInformation.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/FileInformation.swift @@ -6,19 +6,19 @@ // import Foundation -struct FileInformation: Equatable, Comparable, FileInformationBasic { - var url: URL { +public struct FileInformation: Equatable, Comparable, FileInformationBasic { + public var url: URL { self.filePath } - static func < (lhs: FileInformation, rhs: FileInformation) -> Bool { - lhs.filePath < rhs.filePath + public static func < (lhs: FileInformation, rhs: FileInformation) -> Bool { + lhs.filePath.absoluteString < rhs.filePath.absoluteString } /// File name - let name: String + public let name: String /// Original path - let filePath: URL + public let filePath: URL /// Relative to the top mock folder - let relativePath: String + public let relativePath: String } diff --git a/Sources/LetSee/Core/DirectoryProcessor/FileInformationBasic.swift b/Sources/LetSee/Core/DirectoryProcessor/FileInformationBasic.swift index 5ba3a7a..3239fb6 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/FileInformationBasic.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/FileInformationBasic.swift @@ -6,16 +6,17 @@ // import Foundation -protocol FileInformationBasic { +public protocol FileInformationBasic { var url: URL {get} } -extension URL: Comparable, FileInformationBasic { - var url: URL { - self +struct FileURL: Comparable, FileInformationBasic { + var url: URL + init(url: URL) { + self.url = url } - public static func < (lhs: URL, rhs: URL) -> Bool { - lhs.absoluteString < rhs.absoluteString + static func < (lhs: Self, rhs: Self) -> Bool { + lhs.url.absoluteString < rhs.url.absoluteString } } diff --git a/Sources/LetSee/Core/DirectoryProcessor/FileNameParsing.swift b/Sources/LetSee/Core/DirectoryProcessor/FileNameParsing.swift index c15406a..0efae7e 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/FileNameParsing.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/FileNameParsing.swift @@ -6,6 +6,6 @@ // import Foundation -protocol FileNameParsing { +public protocol FileNameParsing { func parse(_ filePath: FileInformation) throws -> MockFileInformation } diff --git a/Sources/LetSee/Core/DirectoryProcessor/MockFileInformation.swift b/Sources/LetSee/Core/DirectoryProcessor/MockFileInformation.swift index 619e0a0..f739db6 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/MockFileInformation.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/MockFileInformation.swift @@ -6,16 +6,16 @@ // import Foundation -struct MockFileInformation: Equatable, Comparable, FileInformationBasic { - static func < (lhs: MockFileInformation, rhs: MockFileInformation) -> Bool { +public struct MockFileInformation: Equatable, Comparable, FileInformationBasic { + public static func < (lhs: MockFileInformation, rhs: MockFileInformation) -> Bool { lhs.fileInformation < rhs.fileInformation } - var url: URL { + public var url: URL { fileInformation.url } - enum MockStatus { + public enum MockStatus { case success case failure } @@ -29,4 +29,12 @@ struct MockFileInformation: Equatable, Comparable, FileInformationBasic { let status: MockStatus? let displayName: String + + public init(fileInformation: FileInformation, statusCode: Int?, delay: TimeInterval?, status: MockStatus?, displayName: String) { + self.fileInformation = fileInformation + self.statusCode = statusCode + self.delay = delay + self.status = status + self.displayName = displayName + } } diff --git a/Sources/LetSee/Core/DirectoryProcessor/MockProcessing.swift b/Sources/LetSee/Core/DirectoryProcessor/MockProcessing.swift index 6de6463..63a64b0 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/MockProcessing.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/MockProcessing.swift @@ -6,7 +6,7 @@ // import Foundation -protocol MockProcessing: DirectoryProcessing where Information == MockFileInformation { +public protocol MockProcessing: DirectoryProcessing where Information == MockFileInformation { func process(_ path: String) throws -> Dictionary func buildMocks(_ path: String) throws -> Dictionary> } diff --git a/Sources/LetSee/Core/DirectoryProcessor/RawDirectoryProcessor.swift b/Sources/LetSee/Core/DirectoryProcessor/RawDirectoryProcessor.swift index 868c84b..0d02629 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/RawDirectoryProcessor.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/RawDirectoryProcessor.swift @@ -7,7 +7,7 @@ import Foundation struct RawDirectoryProcessor: DirectoryProcessing { - typealias Information = URL + typealias Information = FileURL let fileManager: FileManager init(fileManager: FileManager = .default) { @@ -16,14 +16,14 @@ struct RawDirectoryProcessor: DirectoryProcessing { func process(_ path: String) throws -> Dictionary { let url = URL(fileURLWithPath: path) - var files = Dictionary() + var files = Dictionary() if let enumerator = fileManager.enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey, .parentDirectoryURLKey], options: [ .skipsPackageDescendants]) { for case let fileURL as URL in enumerator { do { let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey, .parentDirectoryURLKey]) if fileAttributes.isRegularFile!, let parentDirectory = fileAttributes.parentDirectory { let directory = DirectoryRequestPath(path: parentDirectory, relativePath: "") - let fileURLs = (files[directory] ?? []) + [fileURL] + let fileURLs = (files[directory] ?? []) + [FileURL(url: fileURL) ] files.updateValue(fileURLs , forKey: directory) } } catch { print(error, fileURL) } diff --git a/Sources/LetSee/Core/DirectoryProcessor/ScenarioProcessing.swift b/Sources/LetSee/Core/DirectoryProcessor/ScenarioProcessing.swift index 07a8acd..4ce8977 100644 --- a/Sources/LetSee/Core/DirectoryProcessor/ScenarioProcessing.swift +++ b/Sources/LetSee/Core/DirectoryProcessor/ScenarioProcessing.swift @@ -6,7 +6,7 @@ // import Foundation -protocol ScenarioProcessing: DirectoryProcessing where Information == FileInformation { +public protocol ScenarioProcessing: DirectoryProcessing where Information == FileInformation { func process(_ path: String) throws -> Dictionary func buildScenarios(for path: String, requestToMockMapper: (String) -> CategorisedMocks?, diff --git a/Sources/LetSee/Core/LetSee.swift b/Sources/LetSee/Core/LetSee.swift index 544c27f..9e31af3 100644 --- a/Sources/LetSee/Core/LetSee.swift +++ b/Sources/LetSee/Core/LetSee.swift @@ -4,6 +4,7 @@ extension LetSee { } /// The LetSee object that serves as the entry point to the library and provides access to the features. final public class LetSee: LetSeeProtocol { + internal(set) public var configuration: Configuration = .default /// All available mocks that LetSee have found on the given mock directory internal(set) public var mocks: Dictionary> = [:] @@ -11,27 +12,29 @@ final public class LetSee: LetSeeProtocol { internal(set) public var scenarios: [Scenario] = [] /// a closure that is called when the mock state of the LetSee object changes. It takes a single argument, a Bool value indicating whether mock is enabled or not. It can be set or retrieved using the set and get functions. public var onMockStateChanged: ((Bool) -> Void)? - public let fileToMockMapper: FileToLetSeeMockMapping + public var jsonFileParser: FileNameParsing public let interceptor: LetSeeInterceptor let mockProcessor: any MockProcessing let fileManager: FileManager let requestToMockMapper: RequestToMockMapper var globalMockDirectoryConfigs: GlobalMockDirectoryConfig? let scenarioProcessor: any ScenarioProcessing - init(configuration: Configuration = .default, fileManager: FileManager = .default, - fileToMockMapper: FileToLetSeeMockMapping = DefaultFileToLetSeeMockMapping(), - interceptor: LetSeeInterceptor = .init(), - mockProcessor: any MockProcessing = DefaultMockProcessor(), - scenarioProcessor: any ScenarioProcessing = DefaultScenarioProcessor(), - requestToMockMapper: @escaping RequestToMockMapper = DefaultRequestToMockMapper.transform + public init(configuration: Configuration = .default, + fileManager: FileManager = .default, + jsonFileParser: (any FileNameParsing)? = nil, + interceptor: LetSeeInterceptor? = nil, + mockProcessor: (any MockProcessing)? = nil, + scenarioProcessor: (any ScenarioProcessing)? = nil, + requestToMockMapper: RequestToMockMapper? = nil ) { self.configuration = configuration self.fileManager = fileManager - self.fileToMockMapper = fileToMockMapper - self.interceptor = interceptor - self.mockProcessor = mockProcessor - self.requestToMockMapper = requestToMockMapper - self.scenarioProcessor = scenarioProcessor + self.jsonFileParser = jsonFileParser ?? JSONFileNameParser() + self.interceptor = interceptor ?? LetSeeInterceptor() + self.mockProcessor = mockProcessor ?? DefaultMockProcessor(directoryProcessor: MockDirectoryProcessor(fileNameParser: self.jsonFileParser)) + self.scenarioProcessor = scenarioProcessor ?? DefaultScenarioProcessor(mockFileNameParse: self.jsonFileParser) + self.requestToMockMapper = requestToMockMapper ?? DefaultRequestToMockMapper.transform + } } diff --git a/Sources/LetSee/Core/Services/CategorisedMocks.swift b/Sources/LetSee/Core/Services/CategorisedMocks.swift index 8eabc06..ae8a129 100644 --- a/Sources/LetSee/Core/Services/CategorisedMocks.swift +++ b/Sources/LetSee/Core/Services/CategorisedMocks.swift @@ -14,4 +14,4 @@ public struct CategorisedMocks: Hashable { public var mocks: [LetSeeMock] } -typealias RequestToMockMapper = ((_: URL, _ mocks: Dictionary>) -> CategorisedMocks?) +public typealias RequestToMockMapper = ((_: URL, _ mocks: Dictionary>) -> CategorisedMocks?) diff --git a/Sources/LetSee/Core/Services/LetSeeProtocol.swift b/Sources/LetSee/Core/Services/LetSeeProtocol.swift index 9e9afac..0b9481b 100644 --- a/Sources/LetSee/Core/Services/LetSeeProtocol.swift +++ b/Sources/LetSee/Core/Services/LetSeeProtocol.swift @@ -26,7 +26,7 @@ public protocol LetSeeProtocol: AnyObject { /// A closure that is called when the mock state of the LetSee object changes. It takes a single argument, a Bool value indicating whether mock is enabled or not. It can be set or retrieved using the set and get functions. var onMockStateChanged: ((Bool) -> Void)? {set get} - var fileToMockMapper: FileToLetSeeMockMapping {get} + var jsonFileParser: FileNameParsing {get} var interceptor: LetSeeInterceptor {get} /// Sets the given `Configuration` for LetSee. diff --git a/Sources/LetSee/InAppView/ScenariosListView.swift b/Sources/LetSee/InAppView/ScenariosListView.swift index b2e1c0c..2b3a9bb 100644 --- a/Sources/LetSee/InAppView/ScenariosListView.swift +++ b/Sources/LetSee/InAppView/ScenariosListView.swift @@ -19,32 +19,34 @@ struct ScenariosListView: View { } public var body: some View { DisclosureGroup(isExpanded: $isScenariosCollapsed, content: { - VStack(alignment: .leading, spacing: 16) { - HStack(spacing: 24){ - if configs.isMockEnabled { - // ProgressView() + ScrollView{ + VStack(alignment: .leading, spacing: 16) { + HStack(spacing: 24){ + if configs.isMockEnabled { + // ProgressView() + } } - } - if !self.viewModel.scenarios.isEmpty { - ForEach(self.viewModel.scenarios, id: \.name) { item in - Button { - self.viewModel.toggleScenario(item) - } label: { - ScenarioRow(isSelected: .constant(item == viewModel.selectedScenario), scenario: item) + if !self.viewModel.scenarios.isEmpty { + ForEach(self.viewModel.scenarios, id: \.name) { item in + Button { + self.viewModel.toggleScenario(item) + } label: { + ScenarioRow(isSelected: .constant(item == viewModel.selectedScenario), scenario: item) + } + + Divider() } - Divider() + } else { + Spacer() + Text("No Scenario is available.") + .font(.subheadline) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center) + Spacer() } - - } else { - Spacer() - Text("No Scenario is available.") - .font(.subheadline) - .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center) - Spacer() } - } - .frame(maxWidth: .infinity, alignment: .leading) + .frame(maxWidth: .infinity, alignment: .leading) + }.frame(maxHeight: 300) }, label: { VStack(alignment: .leading) { if let selectedScenario = self.viewModel.selectedScenario, !isScenariosCollapsed { diff --git a/Tests/LetSeeTests/FileDirectoryProcessorTests.swift b/Tests/LetSeeTests/FileDirectoryProcessorTests.swift index 90b9238..428d7a9 100644 --- a/Tests/LetSeeTests/FileDirectoryProcessorTests.swift +++ b/Tests/LetSeeTests/FileDirectoryProcessorTests.swift @@ -31,7 +31,7 @@ final class FileDirectoryProcessorTests: XCTestCase { let mockFolderWithConfigs = try! sut.process(MockFileManager.defaultMocksDirectoryPath + "/FolderWithConfig") XCTAssertEqual(expectedDirectoryNames, mockFolderWithConfigs.map({$0.key.path.lastPathComponent}).sorted()) - expectedFileNames = [".pathconfigs.json", "error_rejectedPayment.json", "success_arrangementSingleItem.json", "success_validatedPayment.json"].sorted() + expectedFileNames = ["error_rejectedPayment.json", "success_arrangementSingleItem.json", "success_validatedPayment.json"].sorted() XCTAssertEqual(expectedFileNames, mockFolderWithConfigs.flatMap({$0.value}).map({$0.url.lastPathComponent}).sorted()) } diff --git a/Tests/LetSeeTests/LetSeeTests.swift b/Tests/LetSeeTests/LetSeeTests.swift index f9689fc..33cca5c 100644 --- a/Tests/LetSeeTests/LetSeeTests.swift +++ b/Tests/LetSeeTests/LetSeeTests.swift @@ -10,12 +10,24 @@ extension MockFileManager { Bundle.module.path(forResource: defaultMockScenariosDirectoryName, ofType: nil)! } } +struct MockJsonFileParser: FileNameParsing { + func parse(_ filePath: FileInformation) throws -> MockFileInformation { + let fileName = filePath.name.hasSuffix(".json") ? String(filePath.name.dropLast(5)) : filePath.name + let type: MockFileInformation.MockStatus = fileName.hasPrefix("error_") ? .failure : .success + let fileInformation = MockFileInformation(fileInformation: filePath, + statusCode: nil, + delay: nil, + status: type, + displayName: fileName) + return fileInformation + } +} final class LetSeeTests: XCTestCase { private var sut: LetSee! private var defaultBaseURL = URL(string: "https://google.com/")! override func setUp() { - sut = LetSee(fileManager: MockFileManager()) + sut = LetSee(fileManager: MockFileManager(), jsonFileParser: MockJsonFileParser()) LetSee.injectLetSee(sut) } @@ -44,7 +56,7 @@ final class LetSeeTests: XCTestCase { XCTAssertEqual(sut!.configuration, given) } - func testLetSeeCorrectlyAddsMocksFromAGivenDirectoryPath_numberOFMocksInCategorizedMockMocksArrayObjectShouldBeEqualToNumberOfAllJsonFilesInSideTheGivenDirectorySubDirectories(){ + func testLetSeeCorrectlyAddsMocksFromAGivenDirectoryPath_numberOFMocksInCategorizedMocksArrayObjectShouldBeEqualToNumberOfAllJsonFilesInSideTheGivenDirectorySubDirectories(){ let givenMockDirectory = MockFileManager.defaultMocksDirectoryPath let allJsonFilesInGivenMockDirectory = MockFileManager().recursivelyFindAllFiles(for: givenMockDirectory, ofType: "json") sut?.addMocks(from: givenMockDirectory) @@ -55,37 +67,19 @@ final class LetSeeTests: XCTestCase { func testLetSeeCorrectlyAddsMocksFromAGivenDirectoryPath_correctlyMakeSuccessOrFailureMockBasedOnTheFilename(){ let givenMockDirectory = MockFileManager.defaultMocksDirectoryPath let allJsonFilesInGivenMockDirectory = MockFileManager().recursivelyFindAllFiles(for: givenMockDirectory, ofType: "json") + let expectedMocks = allJsonFilesInGivenMockDirectory - .map({ - let json: String = (try? String(contentsOf: $0)) ?? "" - return sut!.fileToMockMapper.map(fileName: $0.lastPathComponent, jsonData: json) + .compactMap({ + return try? MockJsonFileParser().parse(.init(name: $0.lastPathComponent, filePath: $0, relativePath: "")) }) + .map(\.displayName) .sorted() sut?.addMocks(from: givenMockDirectory) let result = sut!.mocks .flatMap(\.value) + .map(\.name) .sorted() - XCTAssertEqual(expectedMocks.map(\.type), result.map(\.type)) - } - - func testLetSeeCorrectlyAddsScenariosFromAGivenDirectoryPath(){ - let configs = GlobalMockDirectoryConfig.isExists(in: URL(fileURLWithPath: MockFileManager.defaultMocksDirectoryPath))! - let mockProcessor = DefaultMockProcessor() - let mocks = try! mockProcessor.buildMocks(MockFileManager.defaultMocksDirectoryPath) - let scenarioProcessor = DefaultScenarioProcessor() - let expectedScenarios = try! scenarioProcessor.buildScenarios(for: MockFileManager.defaultMockScenariosDirectoryPath, requestToMockMapper: {path in - DefaultRequestToMockMapper.transform(request: URL(string: "https://letsee.com/" + path)!, using: mocks) - }, globalConfigs: configs) - - - let givenMockScenariosDirectory = MockFileManager.defaultMockScenariosDirectoryPath - let allPlistFilesInGivenMockScenario = MockFileManager() - .recursivelyFindAllFiles(for: givenMockScenariosDirectory, ofType: "plist") - sut?.addMocks(from: MockFileManager.defaultMocksDirectoryPath) - sut?.addScenarios(from: givenMockScenariosDirectory) - let result = sut!.scenarios - - XCTAssertEqual(expectedScenarios, result) + XCTAssertEqual(expectedMocks, result) } func testLetSeeCorrectlyInterceptsIncomingHttpRequests(){ diff --git a/Tests/LetSeeTests/Mocks/FolderWith2Configs/.pathconfigs.json b/Tests/LetSeeTests/Mocks/FolderWith2Configs/.pathconfigs.json deleted file mode 100644 index f18890a..0000000 --- a/Tests/LetSeeTests/Mocks/FolderWith2Configs/.pathconfigs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "path":"/api/arrangement-manager/client-api/v2/productsummary/context" -} diff --git a/Tests/LetSeeTests/Mocks/FolderWith2Configs/details/.pathconfigs.json b/Tests/LetSeeTests/Mocks/FolderWith2Configs/details/.pathconfigs.json deleted file mode 100644 index 1d68c2c..0000000 --- a/Tests/LetSeeTests/Mocks/FolderWith2Configs/details/.pathconfigs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "path":"/api/arrangement-manager/v4" -} diff --git a/Tests/LetSeeTests/Mocks/FolderWith2Configs/orders/.pathconfigs.json b/Tests/LetSeeTests/Mocks/FolderWith2Configs/orders/.pathconfigs.json deleted file mode 100644 index 7a08a74..0000000 --- a/Tests/LetSeeTests/Mocks/FolderWith2Configs/orders/.pathconfigs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "path":"/api/arrangement-manager/client-api/v3" -} diff --git a/Tests/LetSeeTests/Mocks/FolderWithConfig/.pathconfigs.json b/Tests/LetSeeTests/Mocks/FolderWithConfig/.pathconfigs.json deleted file mode 100644 index f18890a..0000000 --- a/Tests/LetSeeTests/Mocks/FolderWithConfig/.pathconfigs.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "path":"/api/arrangement-manager/client-api/v2/productsummary/context" -} diff --git a/Tests/LetSeeTests/RawDirectoryProcessorTests.swift b/Tests/LetSeeTests/RawDirectoryProcessorTests.swift index 82e1bee..2075bff 100644 --- a/Tests/LetSeeTests/RawDirectoryProcessorTests.swift +++ b/Tests/LetSeeTests/RawDirectoryProcessorTests.swift @@ -30,7 +30,7 @@ final class RawDirectoryProcessorTests: XCTestCase { let mockFolderWithConfigs = try! sut.process(MockFileManager.defaultMocksDirectoryPath + "/FolderWithConfig") XCTAssertEqual(expectedDirectoryNames, mockFolderWithConfigs.map({$0.key.path.lastPathComponent}).sorted()) - expectedFileNames = [".pathconfigs.json", "error_rejectedPayment.json", "success_arrangementSingleItem.json", "success_validatedPayment.json"].sorted() + expectedFileNames = ["error_rejectedPayment.json", "success_arrangementSingleItem.json", "success_validatedPayment.json"].sorted() XCTAssertEqual(expectedFileNames, mockFolderWithConfigs.flatMap({$0.value}).map({$0.url.lastPathComponent}).sorted()) } }