From c9408fbb025b688b0d93796202c94e1d3c23b51f Mon Sep 17 00:00:00 2001 From: Angelo Paparazzi Date: Mon, 24 Aug 2020 13:11:44 -0400 Subject: [PATCH] fix: `createEnrichment` hand edit and test fixes --- Source/DiscoveryV2/Discovery.swift | 5 ++--- Tests/DiscoveryV1Tests/DiscoveryTests.swift | 4 ++-- Tests/DiscoveryV2Tests/DiscoveryV2Tests.swift | 2 +- .../LanguageTranslatorV3Tests/Resources/glossary.tmx | 4 ++-- WatsonDeveloperCloud.xcodeproj/project.pbxproj | 11 +++++++++-- .../xcshareddata/xcschemes/DiscoveryV1.xcscheme | 3 +++ 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Source/DiscoveryV2/Discovery.swift b/Source/DiscoveryV2/Discovery.swift index d13501706..61a00371f 100644 --- a/Source/DiscoveryV2/Discovery.swift +++ b/Source/DiscoveryV2/Discovery.swift @@ -1535,9 +1535,7 @@ public class Discovery { { // construct body let multipartFormData = MultipartFormData() - if let enrichmentData = "\(enrichment)".data(using: .utf8) { - multipartFormData.append(enrichmentData, withName: "enrichment") - } + if let file = file { multipartFormData.append(file, withName: "file", mimeType: "application/octet-stream", fileName: "filename") } @@ -1546,6 +1544,7 @@ public class Discovery { completionHandler(nil, WatsonError.serialization(values: "request body")) return } + multipartFormData.append(enrichmentJSON, withName: "enrichment") guard let body = try? multipartFormData.toData() else { diff --git a/Tests/DiscoveryV1Tests/DiscoveryTests.swift b/Tests/DiscoveryV1Tests/DiscoveryTests.swift index 626b7e47c..8a79d753c 100644 --- a/Tests/DiscoveryV1Tests/DiscoveryTests.swift +++ b/Tests/DiscoveryV1Tests/DiscoveryTests.swift @@ -1024,7 +1024,7 @@ class DiscoveryTests: XCTestCase { let collectionID = collection.collectionID! let expectation1 = self.expectation(description: "addDocument") - let metadata = "{ \"name\": \"Kennedy Speech\" }" + let metadata = "{ \"name\": \"Kennedy Speech2\" }" var documentID: String! discovery.addDocument( environmentID: environmentID, @@ -1072,7 +1072,7 @@ class DiscoveryTests: XCTestCase { XCTAssertEqual(result.documentID, documentID) XCTAssert(result.status == "processing" || result.status == "available") XCTAssertGreaterThan(result.statusDescription.count, 0) - XCTAssertEqual(result.filename, "KennedySpeech.html") + XCTAssert(result.filename == nil || result.filename == "KennedySpeech.html") XCTAssertEqual(result.fileType, "html") XCTAssertEqual(result.notices.count, 0) expectation2.fulfill() diff --git a/Tests/DiscoveryV2Tests/DiscoveryV2Tests.swift b/Tests/DiscoveryV2Tests/DiscoveryV2Tests.swift index 360a1d075..353428226 100644 --- a/Tests/DiscoveryV2Tests/DiscoveryV2Tests.swift +++ b/Tests/DiscoveryV2Tests/DiscoveryV2Tests.swift @@ -919,7 +919,7 @@ class DiscoveryTests: XCTestCase { let enrichmentData = loadDocument(name: "TestEnrichments", ext: "csv") let enrichmentOptions = EnrichmentOptions(languages: ["en"], entityType: "keyword", regularExpression: nil, resultField: nil) let enrichment = CreateEnrichment(name: "Dictionary", description: "test dictionary", type: "dictionary", options: enrichmentOptions) - discovery.createEnrichment(projectID: projectID, file: enrichmentData, enrichment: enrichment) { + discovery.createEnrichment(projectID: projectID, enrichment: enrichment, file: enrichmentData) { response, error in if let error = error { diff --git a/Tests/LanguageTranslatorV3Tests/Resources/glossary.tmx b/Tests/LanguageTranslatorV3Tests/Resources/glossary.tmx index c3d0012a6..7f811486e 100644 --- a/Tests/LanguageTranslatorV3Tests/Resources/glossary.tmx +++ b/Tests/LanguageTranslatorV3Tests/Resources/glossary.tmx @@ -9,7 +9,7 @@ International Business Machines - + International Business Machines @@ -17,7 +17,7 @@ patent - + brevent diff --git a/WatsonDeveloperCloud.xcodeproj/project.pbxproj b/WatsonDeveloperCloud.xcodeproj/project.pbxproj index 1940b6819..bd09bc2b2 100644 --- a/WatsonDeveloperCloud.xcodeproj/project.pbxproj +++ b/WatsonDeveloperCloud.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ 12F800581DF71AD9006851D6 /* WatsonCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A6C7B3C1D8C960300CD97FA /* WatsonCredentials.swift */; }; 12F8005C1DF71BA1006851D6 /* Discovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12F8005B1DF71BA1006851D6 /* Discovery.swift */; }; 12F8005E1DF71BED006851D6 /* DiscoveryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12F8005D1DF71BED006851D6 /* DiscoveryTests.swift */; }; + 3EDCC07524F02F6200672463 /* Language.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCC07324F02F6200672463 /* Language.swift */; }; + 3EDCC07624F02F6200672463 /* Languages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCC07424F02F6200672463 /* Languages.swift */; }; 5F2C5BE622E9FA0900A7628D /* SearchResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2C5BE322E9FA0900A7628D /* SearchResult.swift */; }; 5F2C5BE722E9FA0900A7628D /* SearchResultHighlight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2C5BE422E9FA0900A7628D /* SearchResultHighlight.swift */; }; 5F2C5BE822E9FA0900A7628D /* SearchResultMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F2C5BE522E9FA0900A7628D /* SearchResultMetadata.swift */; }; @@ -1048,6 +1050,8 @@ 12F800481DF71921006851D6 /* DiscoveryV1Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DiscoveryV1Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 12F8005B1DF71BA1006851D6 /* Discovery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Discovery.swift; sourceTree = ""; }; 12F8005D1DF71BED006851D6 /* DiscoveryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiscoveryTests.swift; sourceTree = ""; }; + 3EDCC07324F02F6200672463 /* Language.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Language.swift; path = Models/Language.swift; sourceTree = ""; }; + 3EDCC07424F02F6200672463 /* Languages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Languages.swift; path = Models/Languages.swift; sourceTree = ""; }; 5F2C5BE322E9FA0900A7628D /* SearchResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchResult.swift; sourceTree = ""; }; 5F2C5BE422E9FA0900A7628D /* SearchResultHighlight.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchResultHighlight.swift; sourceTree = ""; }; 5F2C5BE522E9FA0900A7628D /* SearchResultMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchResultMetadata.swift; sourceTree = ""; }; @@ -2915,8 +2919,7 @@ 7E2B507224E3184F007AAFC4 /* TestEnrichments.csv */, 7EDF42502382E09C00B7CAE3 /* KennedySpeech.html */, ); - name = Resources; - path = ../../../Tests/DiscoveryV2Tests/Resources; + path = Resources; sourceTree = ""; }; 920645F4212E2880004ACCC9 /* Dependencies */ = { @@ -3252,6 +3255,8 @@ CAD2685320CAF28A002BA2C4 /* LanguageTranslatorV3 */ = { isa = PBXGroup; children = ( + 3EDCC07324F02F6200672463 /* Language.swift */, + 3EDCC07424F02F6200672463 /* Languages.swift */, CAD2686A20CAF919002BA2C4 /* LanguageTranslator.swift */, CA28815E20CB090700FC992C /* Models */, CA28817320CB092500FC992C /* Tests */, @@ -5645,6 +5650,7 @@ files = ( CA28817D20CB099D00FC992C /* IdentifiedLanguages.swift in Sources */, CA28818020CB099D00FC992C /* TranslationModels.swift in Sources */, + 3EDCC07624F02F6200672463 /* Languages.swift in Sources */, CA28817E20CB099D00FC992C /* TranslationModel.swift in Sources */, CAD2686E20CAF919002BA2C4 /* LanguageTranslator.swift in Sources */, CA28817A20CB099D00FC992C /* IdentifiableLanguage.swift in Sources */, @@ -5656,6 +5662,7 @@ CA28818120CB099D00FC992C /* TranslateRequest.swift in Sources */, CA54269E229ECBC30077618A /* InsecureConnection.swift in Sources */, CA28817C20CB099D00FC992C /* TranslationResult.swift in Sources */, + 3EDCC07524F02F6200672463 /* Language.swift in Sources */, CAEBE47C22A6B9C200F86C3A /* DocumentStatus.swift in Sources */, CA28817B20CB099D00FC992C /* Translation.swift in Sources */, ); diff --git a/WatsonDeveloperCloud.xcodeproj/xcshareddata/xcschemes/DiscoveryV1.xcscheme b/WatsonDeveloperCloud.xcodeproj/xcshareddata/xcschemes/DiscoveryV1.xcscheme index e95e9fdca..5888a80c2 100644 --- a/WatsonDeveloperCloud.xcodeproj/xcshareddata/xcschemes/DiscoveryV1.xcscheme +++ b/WatsonDeveloperCloud.xcodeproj/xcshareddata/xcschemes/DiscoveryV1.xcscheme @@ -72,6 +72,9 @@ ReferencedContainer = "container:WatsonDeveloperCloud.xcodeproj"> + +