diff --git a/ContentstackSwift.xcodeproj/project.pbxproj b/ContentstackSwift.xcodeproj/project.pbxproj index c5bfbce..f4e0989 100644 --- a/ContentstackSwift.xcodeproj/project.pbxproj +++ b/ContentstackSwift.xcodeproj/project.pbxproj @@ -269,6 +269,10 @@ 672F769A2E55ADBE00C248D6 /* AsyncAwaitAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 672F76982E55ADBE00C248D6 /* AsyncAwaitAPITest.swift */; }; 672F769B2E55ADBE00C248D6 /* AsyncAwaitAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 672F76982E55ADBE00C248D6 /* AsyncAwaitAPITest.swift */; }; 6750778E2D3E256A0076A066 /* DVR in Frameworks */ = {isa = PBXBuildFile; productRef = 6750778D2D3E256A0076A066 /* DVR */; }; + 678CBD072EF10CBA00B72390 /* ContentstackMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 678CBD062EF10CBA00B72390 /* ContentstackMessages.swift */; }; + 678CBD082EF10CBA00B72390 /* ContentstackMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 678CBD062EF10CBA00B72390 /* ContentstackMessages.swift */; }; + 678CBD092EF10CBA00B72390 /* ContentstackMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 678CBD062EF10CBA00B72390 /* ContentstackMessages.swift */; }; + 678CBD0A2EF10CBA00B72390 /* ContentstackMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 678CBD062EF10CBA00B72390 /* ContentstackMessages.swift */; }; 67AA38EA2EB9D44800C0E2C0 /* CSDefinitionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67AA38E92EB9D44800C0E2C0 /* CSDefinitionsTest.swift */; }; 67AA38EB2EB9D44800C0E2C0 /* CSDefinitionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67AA38E92EB9D44800C0E2C0 /* CSDefinitionsTest.swift */; }; 67AA38EC2EB9D44800C0E2C0 /* CSDefinitionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67AA38E92EB9D44800C0E2C0 /* CSDefinitionsTest.swift */; }; @@ -456,6 +460,7 @@ 47B4DC612C232A8200370CFC /* TaxonomyTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaxonomyTest.swift; sourceTree = ""; }; 47C6EFC12C0B5B9400F0D5CF /* Taxonomy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Taxonomy.swift; sourceTree = ""; }; 672F76982E55ADBE00C248D6 /* AsyncAwaitAPITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncAwaitAPITest.swift; sourceTree = ""; }; + 678CBD062EF10CBA00B72390 /* ContentstackMessages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentstackMessages.swift; sourceTree = ""; }; 67AA38E92EB9D44800C0E2C0 /* CSDefinitionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSDefinitionsTest.swift; sourceTree = ""; }; 67AA38ED2EB9D46200C0E2C0 /* QueryParameterTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryParameterTest.swift; sourceTree = ""; }; 67AA38F12EB9D46800C0E2C0 /* QueryOperationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryOperationTest.swift; sourceTree = ""; }; @@ -807,6 +812,7 @@ 0F4FBCB12420D2CA007B8CAE /* Query */, 0FFA5D60241F5561003B3AF5 /* Utilities */, 0FFA5D5B241F5134003B3AF5 /* Stack.swift */, + 678CBD062EF10CBA00B72390 /* ContentstackMessages.swift */, 67EE21DE2DDB3FFE005AC119 /* CSURLSessionDelegate.swift */, 0FFA5D83241F808F003B3AF5 /* Asset.swift */, 0FFA5D97241F8EB2003B3AF5 /* Entry.swift */, @@ -1172,6 +1178,7 @@ 0FB4CAC924332C5200A385B1 /* ImageOperation.swift in Sources */, 0F4A245C24224D3100159C24 /* ContentstackResponse.swift in Sources */, 0FFA5D93241F8214003B3AF5 /* EndPoint.swift in Sources */, + 678CBD0A2EF10CBA00B72390 /* ContentstackMessages.swift in Sources */, 0FFA5DB4241F99F9003B3AF5 /* FatalError.swift in Sources */, 0F024674243217D800F72181 /* ImageTransformError.swift in Sources */, 0FFA5D74241F6BFA003B3AF5 /* Date.swift in Sources */, @@ -1267,6 +1274,7 @@ 0FB4CACA24332C5200A385B1 /* ImageOperation.swift in Sources */, 0F4A245D24224D3100159C24 /* ContentstackResponse.swift in Sources */, 0FFA5D94241F8214003B3AF5 /* EndPoint.swift in Sources */, + 678CBD072EF10CBA00B72390 /* ContentstackMessages.swift in Sources */, 0FFA5DB6241F99F9003B3AF5 /* FatalError.swift in Sources */, 0F024675243217D800F72181 /* ImageTransformError.swift in Sources */, 0FFA5D75241F6BFA003B3AF5 /* Date.swift in Sources */, @@ -1362,6 +1370,7 @@ 0FB4CACB24332C5200A385B1 /* ImageOperation.swift in Sources */, 0F4A245E24224D3100159C24 /* ContentstackResponse.swift in Sources */, 0FFA5D95241F8214003B3AF5 /* EndPoint.swift in Sources */, + 678CBD092EF10CBA00B72390 /* ContentstackMessages.swift in Sources */, 0FFA5DB8241F99F9003B3AF5 /* FatalError.swift in Sources */, 0F024676243217D800F72181 /* ImageTransformError.swift in Sources */, 0FFA5D76241F6BFA003B3AF5 /* Date.swift in Sources */, @@ -1457,6 +1466,7 @@ 0FB4CACC24332C5200A385B1 /* ImageOperation.swift in Sources */, 0F4A245F24224D3100159C24 /* ContentstackResponse.swift in Sources */, 0FFA5D96241F8214003B3AF5 /* EndPoint.swift in Sources */, + 678CBD082EF10CBA00B72390 /* ContentstackMessages.swift in Sources */, 0FFA5DBA241F99F9003B3AF5 /* FatalError.swift in Sources */, 0F024677243217D800F72181 /* ImageTransformError.swift in Sources */, 0FFA5D77241F6BFA003B3AF5 /* Date.swift in Sources */, diff --git a/Sources/Asset.swift b/Sources/Asset.swift index 1d4ba9a..362dcd5 100644 --- a/Sources/Asset.swift +++ b/Sources/Asset.swift @@ -228,7 +228,7 @@ extension Asset: ResourceQueryable { /// ``` public func fetch(_ completion: @escaping (Result, ResponseType) -> Void) where ResourceType: EndpointAccessible, ResourceType: Decodable { - guard let uid = self.uid else { fatalError("Please provide Asset uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.assetUIDRequired) } self.stack.fetch(endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, parameters: parameters + [QueryParameter.uid: uid], @@ -255,7 +255,7 @@ extension Asset: ResourceQueryable { @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) public func fetch() async throws -> ResourceType where ResourceType: EndpointAccessible & Decodable { - guard let uid = self.uid else { fatalError("Please provide Asset uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.assetUIDRequired) } let response: ContentstackResponse = try await self.stack.fetch( endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, diff --git a/Sources/ContentType.swift b/Sources/ContentType.swift index 043a2ba..a60b8ef 100644 --- a/Sources/ContentType.swift +++ b/Sources/ContentType.swift @@ -45,7 +45,7 @@ public class ContentType: CachePolicyAccessible { ///``` public func entry(uid: String? = nil) -> Entry { if self.uid == nil { - fatalError("Please provide ContentType uid") + fatalError(ContentstackMessages.contentTypeUIDRequired) } return Entry(uid, contentType: self) } @@ -160,7 +160,7 @@ extension ContentType: ResourceQueryable { /// ``` public func fetch(_ completion: @escaping (Result, ResponseType) -> Void) where ResourceType: EndpointAccessible, ResourceType: Decodable { - guard let uid = self.uid else { fatalError("Please provide ContentType uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.contentTypeUIDRequired) } self.stack.fetch(endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, parameters: parameters + [QueryParameter.uid: uid], @@ -187,7 +187,7 @@ extension ContentType: ResourceQueryable { @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) public func fetch() async throws -> ResourceType where ResourceType: EndpointAccessible & Decodable { - guard let uid = self.uid else { fatalError("Please provide ContentType uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.contentTypeUIDRequired) } let response: ContentstackResponse = try await self.stack.fetch( endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, diff --git a/Sources/ContentstackMessages.swift b/Sources/ContentstackMessages.swift new file mode 100644 index 0000000..e267998 --- /dev/null +++ b/Sources/ContentstackMessages.swift @@ -0,0 +1,106 @@ +// +// ContentstackMessages.swift +// Contentstack +// +// Created by Contentstack on 16/12/25. +// + +import Foundation + +/// Centralized location for all user-facing messages in the Contentstack SDK. +/// This includes error messages, validation messages, and informational messages. +internal enum ContentstackMessages { + + // MARK: - UID Required Messages + + static let assetUIDRequired = "Asset UID is required. Provide a valid Asset UID and try again." + static let contentTypeUIDRequired = "Content Type UID is required. Provide a valid Content Type UID and try again." + static let entryUIDRequired = "Entry UID is required. Provide a valid Entry UID and try again." + static let globalFieldUIDRequired = "Global Field UID is required. Provide a valid Global Field UID and try again." + + // MARK: - URL Validation Messages + + static let invalidURLString = "The URL string is not valid. Provide a valid URL and try again." + + // MARK: - Sync Messages + + static let syncTokenConflict = "Sync Token and Pagination Token cannot be used together. Provide only one token and try again." + + // MARK: - Image Transform Messages + + static let qualityParameterRange = """ + The value for Quality parameters can be entered in \ + any whole number (taken as a percentage) between 1 and 100. + """ + + static let dprParameterRange = """ + The value for dpr parameter could be a whole number (between 0 and 10000) \ + or any decimal number (between 0.0 and 9999.9999...). + """ + + static let blurParameterRange = """ + The value for blur parameter could be a whole decimal number (between 1 and 1000). + """ + + static let saturationParameterRange = """ + The value for saturation parameter could be a whole decimal number (between -100 and 100). + """ + + static let contrastParameterRange = """ + The value for contrast parameter could be a whole decimal number (between -100 and 100). + """ + + static let brightnessParameterRange = """ + The value for brightness parameter could be a whole decimal number (between -100 and 100). + """ + + static let sharpenParameterRange = """ + The value for `amount` parameter could be a whole decimal number (between 0 and 10). \ + The value for `radius` parameter could be a whole decimal number (between 1 and 1000). \ + The value for `threshold` parameter could be a whole decimal number (between 0 and 255). + """ + + static let cropAspectRatioRequired = """ + Along with the crop parameter aspect-ration, \ + you also need to specify either the width or height parameter or both \ + in the API request to return an output image with the correct dimensions. + """ + + static let canvasAspectRatioRequired = """ + Along with the canvas parameter aspect-ration, \ + you also need to specify either the width or height parameter or both \ + in the API request to return an output image with the correct dimensions. + """ + + static let invalidHexColor = """ + Invalid Hexadecimal value, \ + it should be 3-digit or 6-digit hexadecimal value. + """ + + static let invalidRGBColor = """ + Invalid Red or Blue or Green or alpha value, \ + the value ranging anywhere between 0 and 255 for each. + """ + + static let invalidRGBAColor = """ + Invalid Red or Blue or Green or alpha value, \ + the value ranging anywhere between 0 and 255 for each \ + and the alpha value with 0.0 being fully transparent \ + and 1.0 being completely opaque. + """ + + static let duplicateImageTransform = """ + Cannot specify two instances of ImageTransform of the same case.\ + i.e. `[.format(.png), .format(.jpg)]` is invalid. + """ + + static let invalidImageOptions = """ + The SDK was unable to generate a valid URL for the given ImageOptions. \ + Please contact the maintainer on Github with a copy of the query + """ + + // MARK: - Internal/Debug Messages + + static let unsupportedEndpointType = "Unsupported endpoint type encountered during response decoding" +} + diff --git a/Sources/ContentstackResponse.swift b/Sources/ContentstackResponse.swift index 647a0a6..3a89c7d 100644 --- a/Sources/ContentstackResponse.swift +++ b/Sources/ContentstackResponse.swift @@ -108,7 +108,7 @@ where ItemType: EndpointAccessible & Decodable { } default: - print("sync") + ContentstackLogger.log(.error, message: ContentstackMessages.unsupportedEndpointType) } } } diff --git a/Sources/Entry.swift b/Sources/Entry.swift index e566fc3..ffd67ef 100644 --- a/Sources/Entry.swift +++ b/Sources/Entry.swift @@ -54,7 +54,7 @@ public class Entry: EntryQueryable, CachePolicyAccessible { /// } public func query() -> Query { if self.contentType.uid == nil { - fatalError("Please provide ContentType uid") + fatalError(ContentstackMessages.contentTypeUIDRequired) } let query = Query(contentType: self.contentType) if let uid = self.uid { @@ -85,7 +85,7 @@ public class Entry: EntryQueryable, CachePolicyAccessible { public func query(_ entry: EntryType.Type) -> QueryOn where EntryType: EntryDecodable & FieldKeysQueryable { if self.contentType.uid == nil { - fatalError("Please provide ContentType uid") + fatalError(ContentstackMessages.contentTypeUIDRequired) } let query = QueryOn(contentType: self.contentType) if let uid = self.uid { @@ -156,7 +156,7 @@ extension Entry: ResourceQueryable { /// ``` public func fetch(_ completion: @escaping (Result, ResponseType) -> Void) where ResourceType: EndpointAccessible, ResourceType: Decodable { - guard let uid = self.uid else { fatalError("Please provide Entry uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.entryUIDRequired) } self.stack.fetch(endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, parameters: parameters + [QueryParameter.uid: uid, @@ -184,7 +184,7 @@ extension Entry: ResourceQueryable { @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) public func fetch() async throws -> ResourceType where ResourceType: EndpointAccessible & Decodable { - guard let uid = self.uid else { fatalError("Please provide Entry uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.entryUIDRequired) } let response: ContentstackResponse = try await self.stack.fetch( endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, diff --git a/Sources/GlobalField.swift b/Sources/GlobalField.swift index 8bf8231..6282fef 100644 --- a/Sources/GlobalField.swift +++ b/Sources/GlobalField.swift @@ -62,7 +62,7 @@ extension GlobalField: ResourceQueryable { /// ``` public func fetch(_ completion: @escaping (Result, ResponseType) -> Void) where ResourceType: EndpointAccessible & Decodable { - guard let uid = self.uid else { fatalError("Please provide Global Field uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.globalFieldUIDRequired) } self.stack.fetch(endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, parameters: parameters + [QueryParameter.uid: uid], @@ -89,7 +89,7 @@ extension GlobalField: ResourceQueryable { @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) public func fetch() async throws -> ResourceType where ResourceType: EndpointAccessible & Decodable { - guard let uid = self.uid else { fatalError("Please provide Global Field uid") } + guard let uid = self.uid else { fatalError(ContentstackMessages.globalFieldUIDRequired) } let response: ContentstackResponse = try await self.stack.fetch( endpoint: ResourceType.endpoint, cachePolicy: self.cachePolicy, diff --git a/Sources/ImageOperation.swift b/Sources/ImageOperation.swift index 390ffa5..6b236bb 100644 --- a/Sources/ImageOperation.swift +++ b/Sources/ImageOperation.swift @@ -98,11 +98,7 @@ internal enum ImageOperation: Equatable, Hashable { case .qualiy(let quality) where quality > 0 && quality <= 100: return [URLQueryItem(name: ImageParameter.quality, value: String(quality))] case .qualiy: - let message = """ - The value for Quality parameters can be entered in - any whole number (taken as a percentage) between 1 and 100. - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.qualityParameterRange) case .resize(let resize): return resize.urlQueryItem() case .crop(let crop): @@ -134,39 +130,23 @@ internal enum ImageOperation: Equatable, Hashable { case .dpr(let dprValue) where dprValue >= 0 && dprValue < 10000: return [URLQueryItem(name: ImageParameter.dpr, value: String(dprValue))] case .dpr: - let message = """ - The value for dpr parameter could be a whole number (between 0 and 10000) - or any decimal number (between 0.0 and 9999.9999...). - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.dprParameterRange) case .blur(let blurvalue) where blurvalue >= 1 && blurvalue < 1000: return [URLQueryItem(name: ImageParameter.blur, value: String(blurvalue))] case .blur: - let message = """ - The value for blur parameter could be a whole decimal number (between 1 and 1000). - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.blurParameterRange) case .saturation(let value) where value >= -100 && value <= 100: return [URLQueryItem(name: ImageParameter.saturation, value: value.stringValue)] case .saturation: - let message = """ - The value for saturation parameter could be a whole decimal number (between -100 and 100). - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.saturationParameterRange) case .contrast(let value) where value >= -100 && value <= 100: return [URLQueryItem(name: ImageParameter.contrast, value: value.stringValue)] case .contrast: - let message = """ - The value for contrast parameter could be a whole decimal number (between -100 and 100). - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.contrastParameterRange) case .brightness(let value) where value >= -100 && value <= 100: return [URLQueryItem(name: ImageParameter.brightness, value: value.stringValue)] case .brightness: - let message = """ - The value for brightness parameter could be a whole decimal number (between -100 and 100). - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.brightnessParameterRange) case .fetchFirstFrame: return [URLQueryItem(name: ImageParameter.frame, value: "1")] case .sharpen(amount: let amount, radius: let radius, threshold: let threshold) @@ -175,12 +155,7 @@ internal enum ImageOperation: Equatable, Hashable { && threshold >= 0 && threshold <= 255: return [URLQueryItem(name: ImageParameter.sharpen, value: "a\(amount),r\(radius),t\(threshold)")] case .sharpen: - let message = """ - The value for `amount` parameter could be a whole decimal number (between 0 and 10). - The value for `radius` parameter could be a whole decimal number (between 1 and 1000). - The value for `threshold` parameter could be a whole decimal number (between 0 and 255). - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.sharpenParameterRange) } } diff --git a/Sources/ImageOperations.swift b/Sources/ImageOperations.swift index 7a63261..a30315f 100644 --- a/Sources/ImageOperations.swift +++ b/Sources/ImageOperations.swift @@ -160,12 +160,7 @@ public enum Crop { case .aspectRatio(let sizes, let ratio, let mode): sizes.urlQueryItem(queryItems: &queryItems) if queryItems.count == 0 { - let message = """ - Along with the crop parameter aspect-ration, - you also need to specify either the width or height parameter or both - in the API request to return an output image with the correct dimensions. - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.cropAspectRatioRequired) } values = [ratio] if let value = mode.value { @@ -223,12 +218,7 @@ public enum Canvas { case .aspectRatio(let sizes, let ratio): sizes.urlQueryItem(queryItems: &queryItems) if queryItems.count == 0 { - let message = """ - Along with the canvas parameter aspect-ration, - you also need to specify either the width or height parameter or both - in the API request to return an output image with the correct dimensions. - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.canvasAspectRatioRequired) } values = [ratio] case .region(let region): @@ -396,25 +386,11 @@ public enum Color { && alpha >= 0.0 && alpha <= 1.0: return [URLQueryItem(name: ImageParameter.backgroundColor, value: "\(red)\(green)\(blue)\(alpha)")] case .hex: - let message = """ - Invalid Hexadecimal value, - it should be 3-digit or 6-digit hexadecimal value. - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.invalidHexColor) case .rgb: - let message = """ - Invalid Red or Blue or Green or alpha value, - the value ranging anywhere between 0 and 255 for each. - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.invalidRGBColor) case .rgba: - let message = """ - Invalid Red or Blue or Green or alpha value, - the value ranging anywhere between 0 and 255 for each - and the alpha value with 0.0 being fully transparent - and 1.0 being completely opaque. - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.invalidRGBAColor) } } } diff --git a/Sources/SyncStack.swift b/Sources/SyncStack.swift index 550fa99..3d3ced5 100644 --- a/Sources/SyncStack.swift +++ b/Sources/SyncStack.swift @@ -48,7 +48,7 @@ public final class SyncStack: Decodable { /// - paginationToken: The paginationToken to fetch next batch of data. public init(syncToken: String = "", paginationToken: String = "") { if !syncToken.isEmpty && !paginationToken.isEmpty { - fatalError("Both Sync Token and Pagination Token can not be presnet.") + fatalError(ContentstackMessages.syncTokenConflict) } self.syncToken = syncToken self.paginationToken = paginationToken diff --git a/Sources/Utils.swift b/Sources/Utils.swift index 28aed2c..d3a3ac9 100644 --- a/Sources/Utils.swift +++ b/Sources/Utils.swift @@ -33,7 +33,7 @@ public extension String { // Will make a `URL` from the current `String` instance if possible. func toURL() throws -> URL { guard var urlComponents = URLComponents(string: self) else { - throw ImageTransformError(message: "Invalid URL String: \(self)") + throw ImageTransformError(message: ContentstackMessages.invalidURLString) } // Append https scheme if not present. @@ -42,7 +42,7 @@ public extension String { } guard let url = urlComponents.url else { - throw ImageTransformError(message: "Invalid URL String: \(self)") + throw ImageTransformError(message: ContentstackMessages.invalidURLString) } return url } @@ -63,8 +63,7 @@ public extension String { let imageOperation = imageTransform.imageOperation let uniqueImageOptions = Array(Set(imageOperation)) guard uniqueImageOptions.count == imageOperation.count else { - throw ImageTransformError(message: "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + throw ImageTransformError(message: ContentstackMessages.duplicateImageTransform) } guard !imageOperation.isEmpty else { @@ -73,7 +72,7 @@ public extension String { let urlString = try toURL().absoluteString guard var urlComponents = URLComponents(string: urlString) else { - throw ImageTransformError(message: "The url string is not valid: \(urlString)") + throw ImageTransformError(message: ContentstackMessages.invalidURLString) } urlComponents.queryItems = try imageOperation.flatMap { option in @@ -81,11 +80,7 @@ public extension String { } guard let url = urlComponents.url else { - let message = """ - The SDK was unable to generate a valid URL for the given ImageOptions. - Please contact the maintainer on Github with a copy of the query \(urlString) - """ - throw ImageTransformError(message: message) + throw ImageTransformError(message: ContentstackMessages.invalidImageOptions + " \(urlString)") } return url } diff --git a/Tests/ContentTypeTest.swift b/Tests/ContentTypeTest.swift index d3a4f1a..a98f4ae 100644 --- a/Tests/ContentTypeTest.swift +++ b/Tests/ContentTypeTest.swift @@ -25,7 +25,7 @@ final class ContentTypeTests: XCTestCase { // } func testEntry_ContentTypeUidNotProvided_FatalError() { - expectFatalError(expectedMessage: "Please provide ContentType uid") { + expectFatalError(expectedMessage: "Content Type UID is required. Provide a valid Content Type UID and try again.") { _ = makeEntrySut() } } diff --git a/Tests/EntryTest.swift b/Tests/EntryTest.swift index aec4d3b..f7006f3 100644 --- a/Tests/EntryTest.swift +++ b/Tests/EntryTest.swift @@ -23,14 +23,14 @@ class EntryTest: XCTestCase { // } func testEntryQuery_ContentTypeUidNotProvided_FatalError() { - expectFatalError(expectedMessage: "Please provide ContentType uid") { + expectFatalError(expectedMessage: "Content Type UID is required. Provide a valid Content Type UID and try again.") { let query = Entry(nil, contentType: makeContentTypeSut()).query() XCTAssertNil(query) } } func testEntryQueryTyped_ContentTypeUidNotProvided_FatalError() { - expectFatalError(expectedMessage: "Please provide ContentType uid") { + expectFatalError(expectedMessage: "Content Type UID is required. Provide a valid Content Type UID and try again.") { let query = Entry(nil, contentType: makeContentTypeSut()).query(Product.self) XCTAssertNil(query) } diff --git a/Tests/ImageTransformEquatableTest.swift b/Tests/ImageTransformEquatableTest.swift index f4f195d..949803f 100644 --- a/Tests/ImageTransformEquatableTest.swift +++ b/Tests/ImageTransformEquatableTest.swift @@ -12,8 +12,8 @@ class ImageTransformEquatableTest: XCTestCase { func testSharpen_invalidParams_shouldThrowError() { let message = """ - The value for `amount` parameter could be a whole decimal number (between 0 and 10). - The value for `radius` parameter could be a whole decimal number (between 1 and 1000). + The value for `amount` parameter could be a whole decimal number (between 0 and 10). \ + The value for `radius` parameter could be a whole decimal number (between 1 and 1000). \ The value for `threshold` parameter could be a whole decimal number (between 0 and 255). """ do { @@ -96,8 +96,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } do { @@ -105,8 +104,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -115,8 +113,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -125,8 +122,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -135,8 +131,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -145,8 +140,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -155,8 +149,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -165,8 +158,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } } @@ -177,8 +169,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -187,8 +178,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -197,8 +187,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -207,8 +196,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -217,8 +205,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -227,8 +214,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -237,8 +223,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -247,8 +232,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } @@ -257,8 +241,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } do { @@ -266,8 +249,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } do { @@ -275,8 +257,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } do { @@ -284,8 +265,7 @@ class ImageTransformEquatableTest: XCTestCase { XCTAssertNil(url) } catch let error { if let imageError = error as? ImageTransformError { - XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case." - + "i.e. `[.format(.png), .format(.jpg)]` is invalid.") + XCTAssertEqual(imageError.message, "Cannot specify two instances of ImageTransform of the same case.i.e. `[.format(.png), .format(.jpg)]` is invalid.") } } } diff --git a/Tests/ImageTransformTest.swift b/Tests/ImageTransformTest.swift index b66b411..faf9443 100644 --- a/Tests/ImageTransformTest.swift +++ b/Tests/ImageTransformTest.swift @@ -41,7 +41,7 @@ class ImageTransformTest: XCTestCase { let quality: UInt = 101 let imageTransform = makeImageTransformSUT().qualiy(quality) let message = """ - The value for Quality parameters can be entered in + The value for Quality parameters can be entered in \ any whole number (taken as a percentage) between 1 and 100. """ do { @@ -190,13 +190,13 @@ class ImageTransformTest: XCTestCase { func testCropCanvasAspectRatio_NoSizeSpecified_Throws() { let ratio = "1:2" let cropMessage = """ - Along with the crop parameter aspect-ration, - you also need to specify either the width or height parameter or both + Along with the crop parameter aspect-ration, \ + you also need to specify either the width or height parameter or both \ in the API request to return an output image with the correct dimensions. """ let canvasMessage = """ - Along with the canvas parameter aspect-ration, - you also need to specify either the width or height parameter or both + Along with the canvas parameter aspect-ration, \ + you also need to specify either the width or height parameter or both \ in the API request to return an output image with the correct dimensions. """ diff --git a/Tests/ImageTransformTestAdditional.swift b/Tests/ImageTransformTestAdditional.swift index ba02033..3de67a1 100644 --- a/Tests/ImageTransformTestAdditional.swift +++ b/Tests/ImageTransformTestAdditional.swift @@ -124,7 +124,7 @@ class ImageTransformTestAdditional: XCTestCase { func testBackgroundColorHex_withInvalidValues_shouldThrowError() { let message = """ - Invalid Hexadecimal value, + Invalid Hexadecimal value, \ it should be 3-digit or 6-digit hexadecimal value. """ do { @@ -177,7 +177,7 @@ class ImageTransformTestAdditional: XCTestCase { func testBackgroundColorRGB_withInvalidValues_shouldThrowError() { let message = """ - Invalid Red or Blue or Green or alpha value, + Invalid Red or Blue or Green or alpha value, \ the value ranging anywhere between 0 and 255 for each. """ do { @@ -211,9 +211,9 @@ class ImageTransformTestAdditional: XCTestCase { func testBackgroundColorRGBA_withInvalidValues_shouldThrowError() { let message = """ - Invalid Red or Blue or Green or alpha value, - the value ranging anywhere between 0 and 255 for each - and the alpha value with 0.0 being fully transparent + Invalid Red or Blue or Green or alpha value, \ + the value ranging anywhere between 0 and 255 for each \ + and the alpha value with 0.0 being fully transparent \ and 1.0 being completely opaque. """ do { @@ -274,7 +274,7 @@ class ImageTransformTestAdditional: XCTestCase { func testDPR_InvalidParam_shouldThrow() { let message = """ - The value for dpr parameter could be a whole number (between 0 and 10000) + The value for dpr parameter could be a whole number (between 0 and 10000) \ or any decimal number (between 0.0 and 9999.9999...). """ do {