Skip to content
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

Closed
wants to merge 18 commits into from

Conversation

PatrykPiwowarczyk
Copy link
Contributor

@PatrykPiwowarczyk PatrykPiwowarczyk commented Sep 27, 2023

No description provided.

@PatrykPiwowarczyk PatrykPiwowarczyk requested a review from a team as a code owner September 27, 2023 12:42
Sources/FeaturevisorSDK/Instance+Dictionary.swift Outdated Show resolved Hide resolved
Sources/FeaturevisorSDK/Instance.swift Outdated Show resolved Hide resolved
let expectedDictionary: [String: Any] = [
"featureKey": "feature123",
"reason": "allocated",
"bucketValue": NSNull(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not "nil"?

Copy link
Contributor Author

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: [])
Copy link
Contributor

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)
Copy link
Contributor

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()
Copy link
Contributor

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? {
Copy link
Contributor

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] = [
Copy link
Contributor

@polok polok Oct 4, 2023

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] = [
Copy link
Contributor

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
}

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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() {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants