Skip to content

Commit 541bfe2

Browse files
authored
Merge pull request #48 from contentstack/staging
Release
2 parents f0e8544 + ebbc2f1 commit 541bfe2

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

Contentstack.xcworkspace/xcshareddata/xcschemes/Contentstack iOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1100"
3+
LastUpgradeVersion = "1540"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Sources/ContentstackConfig.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public struct ContentstackConfig {
1111

1212
/// The singleton instance of 'ContentstackConfig'.
1313
public static let `default` = ContentstackConfig()
14+
public var earlyAccess: [String]?
1415

1516
/// Initialize 'ContentstackConfig' default values.
1617
public init() {}
@@ -52,6 +53,9 @@ public struct ContentstackConfig {
5253

5354
return userAgentString
5455
}
56+
public mutating func setEarlyAccess(_ earlyAccess: [String]) {
57+
self.earlyAccess = earlyAccess
58+
}
5559

5660
// MARK: Private
5761
private func platformVersionString() -> String? {
@@ -111,4 +115,18 @@ public struct ContentstackConfig {
111115

112116
return appBundleId + "/" + versionNumberString
113117
}
118+
119+
/// Internal method to get headers including early access
120+
internal func getHeaders() -> [String: String] {
121+
var headers: [String: String] = [
122+
"X-User-Agent": sdkVersionString(),
123+
"User-Agent": userAgentString()
124+
]
125+
126+
if let earlyAccess = earlyAccess, !earlyAccess.isEmpty {
127+
headers["x-header-ea"] = earlyAccess.joined(separator: ",")
128+
}
129+
130+
return headers
131+
}
114132
}

Tests/ContentstackConfigTest.swift

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,67 @@ class ContentstackConfigTest: XCTestCase {
8787
let stack = makeStackSut(config: config)
8888
XCTAssertEqual(stack.jsonDecoder.userInfo[.timeZoneContextKey] as? TimeZone, timeZone)
8989
}
90+
func testEarlyAccessMultipleValues() {
91+
var config = ContentstackConfig()
92+
let earlyAccess : [String] = ["Taxonomy","Teams"]
93+
config.setEarlyAccess(earlyAccess)
94+
_ = makeStackSut(config: config)
95+
let headers = config.getHeaders()
96+
XCTAssertTrue(headers.keys.contains("x-header-ea"))
97+
XCTAssertEqual(headers["x-header-ea"], "Taxonomy,Teams")
98+
}
99+
100+
func testDefaultEarlyAccessIsNil() {
101+
var config = ContentstackConfig()
102+
config.setEarlyAccess([])
103+
_ = makeStackSut(config: config)
104+
let headers = config.getHeaders()
105+
print("headers::",headers)
106+
XCTAssertFalse(headers.keys.contains("x-header-ea"), "The headers should not contain the 'x-header-ea' key when early access is not set.")
107+
}
108+
109+
func testEarlyAccessSingleValue() {
110+
var config = ContentstackConfig()
111+
let earlyAccessFeatures = ["feature1"]
112+
config.setEarlyAccess(earlyAccessFeatures)
113+
_ = makeStackSut(config: config)
114+
let headers = config.getHeaders()
115+
XCTAssertTrue(headers.keys.contains("x-header-ea"), "The headers should contain the 'x-header-ea' key.")
116+
XCTAssertEqual(headers["x-header-ea"], "feature1", "The 'x-header-ea' value should match the single early access value passed.")
117+
}
118+
119+
func testGetHeadersWithoutEarlyAccess() {
120+
let config = ContentstackConfig()
121+
let headers = config.getHeaders()
122+
XCTAssertFalse(headers.keys.contains("x-header-ea"))
123+
}
124+
125+
func testMultipleEarlyAccessWithSpaces() {
126+
var config = ContentstackConfig()
127+
let earlyAccess: [String] = ["Feature One", "Feature Two"]
128+
config.setEarlyAccess(earlyAccess)
129+
_ = makeStackSut(config: config)
130+
let headers = config.getHeaders()
131+
XCTAssertTrue(headers.keys.contains("x-header-ea"), "The headers should contain the 'x-header-ea' key.")
132+
XCTAssertEqual(headers["x-header-ea"], "Feature One,Feature Two", "The 'x-header-ea' value should match the early access values with spaces.")
133+
}
134+
135+
func testDefaultConfigHasNoEarlyAccessHeaders() {
136+
let config = ContentstackConfig()
137+
_ = makeStackSut(config: config)
138+
let headers = config.getHeaders()
139+
XCTAssertFalse(headers.keys.contains("x-header-ea"), "The default config should not contain the 'x-header-ea' key.")
140+
}
90141

91142
static var allTests = [
92143
("testUserAgent", testUserAgent),
93144
("testXUserAgent", testXUserAgent),
94-
("testTimeZone_changetoCurrent", testTimeZone_changetoCurrent)
145+
("testTimeZone_changetoCurrent", testTimeZone_changetoCurrent),
146+
("testEarlyAccessMultipleValues", testEarlyAccessMultipleValues),
147+
("testDefaultEarlyAccessIsNil", testDefaultEarlyAccessIsNil),
148+
("testEarlyAccessSingleValue", testEarlyAccessSingleValue),
149+
("testGetHeadersWithoutEarlyAccess", testGetHeadersWithoutEarlyAccess),
150+
("testMultipleEarlyAccessWithSpaces", testMultipleEarlyAccessWithSpaces),
151+
("testDefaultConfigHasNoEarlyAccessHeaders", testDefaultConfigHasNoEarlyAccessHeaders),
95152
]
96153
}

0 commit comments

Comments
 (0)