Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Feb 7, 2022
1 parent 33e2e41 commit 4caeb51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.0.1...4.1.0)

__Improvements__
- Let the OS and developer decide if app tracking authorization is required when using ParseAnalytics. ParseAnalytics can now take any Codable value in its' dimensions instead of just strings. Added new properties, "dimensionsCodable" and "date" to ParseAnalytics. The "at" property will be deprecated in ParseSwift 5.0.0, so developers should switch to "date". ParseAnalytics can now be properly decoded after encoding with a JSONEncoder. This is useful if ParseAnalytics need to be stored locally and sent to the server later ([#341](https://github.com/parse-community/Parse-Swift/pull/341)), thanks to [Corey Baker](https://github.com/cbaker6).
- Let the OS and developer decide if app tracking authorization is required when using ParseAnalytics. ParseAnalytics can now take any Codable value in its' dimensions instead of just strings. Added a new property "date" to ParseAnalytics. The "at" property will be deprecated in ParseSwift 5.0.0, so developers should switch to "date". ParseAnalytics can now be properly decoded after encoding with a JSONEncoder. This is useful if ParseAnalytics need to be stored locally and sent to the server later ([#341](https://github.com/parse-community/Parse-Swift/pull/341)), thanks to [Corey Baker](https://github.com/cbaker6).

### 4.0.1
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.0.0...4.0.1)
Expand Down
14 changes: 1 addition & 13 deletions Sources/ParseSwift/Types/ParseAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ public struct ParseAnalytics: ParseType, Hashable {
public var date: Date?

/// The dictionary of information by which to segment this event.
/// - warning: This will be changed to [String: Codable] in ParseSwift 5.0.0.
public var dimensions: [String: String]? {
get {
convertToString(dimensionsAnyCodable)
}
set {
dimensionsAnyCodable = convertToAnyCodable(newValue)
}
}

/// The dictionary of information by which to segment this event.
/// - warning: This will be deprecated in ParseSwift 5.0.0 in favor of `dimensions`.
public var dimensionsCodable: [String: Codable]? {
public var dimensions: [String: Codable]? {
get {
convertToString(dimensionsAnyCodable)
}
Expand Down
29 changes: 15 additions & 14 deletions Tests/ParseSwiftTests/ParseAnalyticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ParseAnalyticsTests: XCTestCase {
XCTAssertEqual(command2.method, API.Method.POST)
XCTAssertNotNil(command2.body)
XCTAssertEqual(command2.body?.at, date)
XCTAssertEqual(command2.body?.dimensions, dimensions)
XCTAssertNotNil(command2.body?.dimensions)

event2.at = nil //Clear date for comparison
let decoded = event2.debugDescription
Expand Down Expand Up @@ -96,15 +96,15 @@ class ParseAnalyticsTests: XCTestCase {
let dimensions = ["stop": "drop"]
let dimensions2 = ["open": "up shop"]
var event = ParseAnalytics(name: name, dimensions: dimensions)
XCTAssertEqual(event.dimensions, dimensions)
let encodedDimensions = try ParseCoding.jsonEncoder().encode(AnyCodable(event.dimensions))
let decodedDictionary = try ParseCoding.jsonDecoder().decode([String: String].self,
from: encodedDimensions)
XCTAssertEqual(decodedDictionary, dimensions)
event.dimensions = dimensions2
XCTAssertEqual(event.dimensions, dimensions2)
event.dimensionsCodable = dimensions2
XCTAssertEqual(event.dimensions, dimensions2)
let encoded = try ParseCoding.jsonEncoder().encode(event.dimensions)
let encoded = try ParseCoding.jsonEncoder().encode(AnyCodable(event.dimensions))
let encodedExpected = try ParseCoding.jsonEncoder().encode(dimensions2)
XCTAssertEqual(encoded, encodedExpected)
let encoded2 = try ParseCoding.jsonEncoder().encode(AnyCodable(event.dimensionsCodable))
let encoded2 = try ParseCoding.jsonEncoder().encode(event.dimensionsAnyCodable)
XCTAssertEqual(encoded2, encodedExpected)
}

Expand All @@ -117,20 +117,21 @@ class ParseAnalyticsTests: XCTestCase {
dimensions3[key] = value
}
var event = ParseAnalytics(name: name, dimensions: dimensions)
XCTAssertEqual(event.dimensions, dimensions)
event.dimensionsCodable = dimensions2
XCTAssertNotEqual(event.dimensions, dimensions)
XCTAssertNotEqual(event.dimensions, dimensions3)
XCTAssertEqual(event.dimensions, dimensions2)
event.dimensions = dimensions2
let encoded = try ParseCoding.jsonEncoder().encode(AnyCodable(event.dimensions))
let encodedExpected = try ParseCoding.jsonEncoder().encode(dimensions2)
XCTAssertEqual(encoded, encodedExpected)
}

func testUpdateDimensionsNonInitially() throws {
let name = "hello"
let dimensions = ["stop": "drop"]
var event = ParseAnalytics(name: name)
XCTAssertNil(event.dimensions)
event.dimensionsCodable = dimensions
XCTAssertEqual(event.dimensions, dimensions)
event.dimensions = dimensions
let encoded = try ParseCoding.jsonEncoder().encode(AnyCodable(event.dimensions))
let encodedExpected = try ParseCoding.jsonEncoder().encode(dimensions)
XCTAssertEqual(encoded, encodedExpected)
}

#if os(iOS)
Expand Down

0 comments on commit 4caeb51

Please sign in to comment.