|
| 1 | +// |
| 2 | +// CSDefinitionsTest.swift |
| 3 | +// Contentstack |
| 4 | +// |
| 5 | +// Created for improved test coverage |
| 6 | +// |
| 7 | + |
| 8 | +import XCTest |
| 9 | +@testable import ContentstackSwift |
| 10 | + |
| 11 | +class CSDefinitionsTest: XCTestCase { |
| 12 | + |
| 13 | + // MARK: - HTTPMethod Tests |
| 14 | + |
| 15 | + func testHTTPMethod_get() { |
| 16 | + let method = HTTPMethod.get |
| 17 | + XCTAssertEqual(method.rawValue, "GET") |
| 18 | + XCTAssertEqual(method.httpMethod, "GET") |
| 19 | + } |
| 20 | + |
| 21 | + func testHTTPMethod_post() { |
| 22 | + let method = HTTPMethod.post |
| 23 | + XCTAssertEqual(method.rawValue, "POST") |
| 24 | + XCTAssertEqual(method.httpMethod, "POST") |
| 25 | + } |
| 26 | + |
| 27 | + func testHTTPMethod_put() { |
| 28 | + let method = HTTPMethod.put |
| 29 | + XCTAssertEqual(method.rawValue, "PUT") |
| 30 | + XCTAssertEqual(method.httpMethod, "PUT") |
| 31 | + } |
| 32 | + |
| 33 | + func testHTTPMethod_delete() { |
| 34 | + let method = HTTPMethod.delete |
| 35 | + XCTAssertEqual(method.rawValue, "DELETE") |
| 36 | + XCTAssertEqual(method.httpMethod, "DELETE") |
| 37 | + } |
| 38 | + |
| 39 | + // MARK: - ContentstackRegion Tests |
| 40 | + |
| 41 | + func testContentstackRegion_us() { |
| 42 | + let region = ContentstackRegion.us |
| 43 | + XCTAssertEqual(region.rawValue, "us") |
| 44 | + } |
| 45 | + |
| 46 | + func testContentstackRegion_eu() { |
| 47 | + let region = ContentstackRegion.eu |
| 48 | + XCTAssertEqual(region.rawValue, "eu") |
| 49 | + } |
| 50 | + |
| 51 | + func testContentstackRegion_azureNA() { |
| 52 | + let region = ContentstackRegion.azure_na |
| 53 | + XCTAssertEqual(region.rawValue, "azure-na") |
| 54 | + } |
| 55 | + |
| 56 | + func testContentstackRegion_azureEU() { |
| 57 | + let region = ContentstackRegion.azure_eu |
| 58 | + XCTAssertEqual(region.rawValue, "azure-eu") |
| 59 | + } |
| 60 | + |
| 61 | + func testContentstackRegion_gcpNA() { |
| 62 | + let region = ContentstackRegion.gcp_na |
| 63 | + XCTAssertEqual(region.rawValue, "gcp-na") |
| 64 | + } |
| 65 | + |
| 66 | + func testContentstackRegion_gcpEU() { |
| 67 | + let region = ContentstackRegion.gcp_eu |
| 68 | + XCTAssertEqual(region.rawValue, "gcp-eu") |
| 69 | + } |
| 70 | + |
| 71 | + func testContentstackRegion_au() { |
| 72 | + let region = ContentstackRegion.au |
| 73 | + XCTAssertEqual(region.rawValue, "au") |
| 74 | + } |
| 75 | + |
| 76 | + func testContentstackRegion_equality() { |
| 77 | + let region1 = ContentstackRegion.us |
| 78 | + let region2 = ContentstackRegion.us |
| 79 | + |
| 80 | + XCTAssertEqual(region1, region2) |
| 81 | + } |
| 82 | + |
| 83 | + func testContentstackRegion_inequality() { |
| 84 | + let region1 = ContentstackRegion.us |
| 85 | + let region2 = ContentstackRegion.eu |
| 86 | + |
| 87 | + XCTAssertNotEqual(region1, region2) |
| 88 | + } |
| 89 | + |
| 90 | + // MARK: - CachePolicy Tests |
| 91 | + |
| 92 | + func testCachePolicy_networkOnly() { |
| 93 | + let policy = CachePolicy.networkOnly |
| 94 | + |
| 95 | + switch policy { |
| 96 | + case .networkOnly: |
| 97 | + XCTAssertTrue(true) |
| 98 | + default: |
| 99 | + XCTFail("Expected networkOnly policy") |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + func testCachePolicy_cacheOnly() { |
| 104 | + let policy = CachePolicy.cacheOnly |
| 105 | + |
| 106 | + switch policy { |
| 107 | + case .cacheOnly: |
| 108 | + XCTAssertTrue(true) |
| 109 | + default: |
| 110 | + XCTFail("Expected cacheOnly policy") |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + func testCachePolicy_cacheElseNetwork() { |
| 115 | + let policy = CachePolicy.cacheElseNetwork |
| 116 | + |
| 117 | + switch policy { |
| 118 | + case .cacheElseNetwork: |
| 119 | + XCTAssertTrue(true) |
| 120 | + default: |
| 121 | + XCTFail("Expected cacheElseNetwork policy") |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + func testCachePolicy_networkElseCache() { |
| 126 | + let policy = CachePolicy.networkElseCache |
| 127 | + |
| 128 | + switch policy { |
| 129 | + case .networkElseCache: |
| 130 | + XCTAssertTrue(true) |
| 131 | + default: |
| 132 | + XCTFail("Expected networkElseCache policy") |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + func testCachePolicy_cacheThenNetwork() { |
| 137 | + let policy = CachePolicy.cacheThenNetwork |
| 138 | + |
| 139 | + switch policy { |
| 140 | + case .cacheThenNetwork: |
| 141 | + XCTAssertTrue(true) |
| 142 | + default: |
| 143 | + XCTFail("Expected cacheThenNetwork policy") |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + // MARK: - ResponseType Tests |
| 148 | + |
| 149 | + func testResponseType_cache() { |
| 150 | + let responseType = ResponseType.cache |
| 151 | + |
| 152 | + switch responseType { |
| 153 | + case .cache: |
| 154 | + XCTAssertTrue(true) |
| 155 | + default: |
| 156 | + XCTFail("Expected cache response type") |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + func testResponseType_network() { |
| 161 | + let responseType = ResponseType.network |
| 162 | + |
| 163 | + switch responseType { |
| 164 | + case .network: |
| 165 | + XCTAssertTrue(true) |
| 166 | + default: |
| 167 | + XCTFail("Expected network response type") |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + // MARK: - All Regions Test |
| 172 | + |
| 173 | + func testAllRegions_uniqueRawValues() { |
| 174 | + let regions = [ |
| 175 | + ContentstackRegion.us, |
| 176 | + ContentstackRegion.eu, |
| 177 | + ContentstackRegion.azure_na, |
| 178 | + ContentstackRegion.azure_eu, |
| 179 | + ContentstackRegion.gcp_na, |
| 180 | + ContentstackRegion.gcp_eu, |
| 181 | + ContentstackRegion.au |
| 182 | + ] |
| 183 | + |
| 184 | + let rawValues = regions.map { $0.rawValue } |
| 185 | + let uniqueRawValues = Set(rawValues) |
| 186 | + |
| 187 | + XCTAssertEqual(rawValues.count, uniqueRawValues.count, "All regions should have unique raw values") |
| 188 | + } |
| 189 | + |
| 190 | + static var allTests = [ |
| 191 | + ("testHTTPMethod_get", testHTTPMethod_get), |
| 192 | + ("testHTTPMethod_post", testHTTPMethod_post), |
| 193 | + ("testHTTPMethod_put", testHTTPMethod_put), |
| 194 | + ("testHTTPMethod_delete", testHTTPMethod_delete), |
| 195 | + ("testContentstackRegion_us", testContentstackRegion_us), |
| 196 | + ("testContentstackRegion_eu", testContentstackRegion_eu), |
| 197 | + ("testContentstackRegion_azureNA", testContentstackRegion_azureNA), |
| 198 | + ("testContentstackRegion_azureEU", testContentstackRegion_azureEU), |
| 199 | + ("testContentstackRegion_gcpNA", testContentstackRegion_gcpNA), |
| 200 | + ("testContentstackRegion_gcpEU", testContentstackRegion_gcpEU), |
| 201 | + ("testContentstackRegion_au", testContentstackRegion_au), |
| 202 | + ("testContentstackRegion_equality", testContentstackRegion_equality), |
| 203 | + ("testContentstackRegion_inequality", testContentstackRegion_inequality), |
| 204 | + ("testCachePolicy_networkOnly", testCachePolicy_networkOnly), |
| 205 | + ("testCachePolicy_cacheOnly", testCachePolicy_cacheOnly), |
| 206 | + ("testCachePolicy_cacheElseNetwork", testCachePolicy_cacheElseNetwork), |
| 207 | + ("testCachePolicy_networkElseCache", testCachePolicy_networkElseCache), |
| 208 | + ("testCachePolicy_cacheThenNetwork", testCachePolicy_cacheThenNetwork), |
| 209 | + ("testResponseType_cache", testResponseType_cache), |
| 210 | + ("testResponseType_network", testResponseType_network), |
| 211 | + ("testAllRegions_uniqueRawValues", testAllRegions_uniqueRawValues) |
| 212 | + ] |
| 213 | +} |
| 214 | + |
0 commit comments