-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update Evaluation struct to conform to encodable. Update logger. #34
Conversation
let expectedDictionary: [String: Any] = [ | ||
"featureKey": "feature123", | ||
"reason": "allocated", | ||
"bucketValue": NSNull(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not "nil"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'nil' is not compatible with expected dictionary value type 'Any'
func testEncodeEvaluationReturnsValidDatafileContent() throws { | ||
|
||
//GIVEN | ||
let traffic = Traffic(key: "key", segments: .plain("segment"), percentage: 13, allocation: []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for the above, please format to:
Traffic(
key: "key",
segments: .plain("segment"),
percentage: 13,
allocation: [])
Easier to read and follow current code style formating
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(featureKey, forKey: .featureKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All fields which are optional should be encoded using encodeIfPresent
@@ -217,7 +280,70 @@ public class FeaturevisorInstance { | |||
} | |||
|
|||
func getRevision() -> String { | |||
return datafileReader.getRevision() | |||
return self.datafileReader.getRevision() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need self
here?
|
||
// MARK: - Bucketing | ||
|
||
private func getFeature(byKey featureKey: String) -> Feature? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whydo we have changes here and for getBucketKey
?
reason: .allocated | ||
) | ||
|
||
let expectedDictionary: [String: Any] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put expected under // Then. Thanks in advance. I remember that last time I wrote that it should be under GIVEN instead WHEN but // THEN would be better I believe
variableSchema: variableSchema | ||
) | ||
|
||
let mockedTraffic: [String: Any] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use mocked as it's confusing. Rather expectedTraffic
. Also move expected stuff under "THEN"
XCTFail("Failed to decode JSON to a dictionary.") | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have "THEN" where you can assert vs expectedDictionary
as now it's not being used
error as! FeaturevisorError, | ||
FeaturevisorError.invalidURL(string: "hf://wrong url.com") | ||
) | ||
MockURLProtocol.requestHandler = { request in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why such changes here?
@@ -52,23 +188,6 @@ class FeaturevisorInstanceTests: XCTestCase { | |||
return (response, jsonString.data(using: .utf8)) | |||
} | |||
|
|||
var featurevisorOptions = InstanceOptions.default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we have here these changes?
@@ -828,8 +947,18 @@ class FeaturevisorInstanceTests: XCTestCase { | |||
Thread.sleep(forTimeInterval: 0.1) | |||
} | |||
|
|||
// THEN | |||
XCTAssertEqual(refreshedCount, expectedRefreshCount) | |||
MockURLProtocol.requestHandler = { request in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we have here these changes?
@@ -877,28 +1006,6 @@ class FeaturevisorInstanceTests: XCTestCase { | |||
XCTAssertEqual(isRefreshingStopped, true) | |||
} | |||
|
|||
func testSetDatafileByValidJSON() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we have these changes here?
No description provided.