File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed
Sources/AlgoliaSearchClient/Models/Search/Response/SearchResponse/Auxiliary/FacetStats
Tests/AlgoliaSearchClientTests/Unit/Model Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ public struct FacetStats: Codable {
1818 public let max : Double
1919
2020 /// The average of all values.
21- public let avg : Double
21+ public let avg : Double ?
2222
2323 /// The sum of all values.
24- public let sum : Double
24+ public let sum : Double ?
2525
2626}
Original file line number Diff line number Diff line change 1+ //
2+ // FacetStats.swift
3+ //
4+ //
5+ // Created by Vladislav Fitc on 16/03/2022.
6+ //
7+
8+ import Foundation
9+ import XCTest
10+ @testable import AlgoliaSearchClient
11+
12+ class FacetStatsTests : XCTestCase {
13+
14+ func testDecoding( ) throws {
15+ let jsonData = """
16+ {
17+ " min " : 10,
18+ " max " : 200,
19+ " avg " : 105,
20+ " sum " : 210,
21+ }
22+ """ . data ( using: . utf8) !
23+ let facetStats = try JSONDecoder ( ) . decode ( FacetStats . self, from: jsonData)
24+ XCTAssertEqual ( facetStats. min, 10 )
25+ XCTAssertEqual ( facetStats. max, 200 )
26+ XCTAssertEqual ( facetStats. avg, 105 )
27+ XCTAssertEqual ( facetStats. sum, 210 )
28+ }
29+
30+ func testMissingSumAvgDecoding( ) throws {
31+ let jsonData = """
32+ {
33+ " min " : 10,
34+ " max " : 200,
35+ }
36+ """ . data ( using: . utf8) !
37+ let facetStats = try JSONDecoder ( ) . decode ( FacetStats . self, from: jsonData)
38+ XCTAssertEqual ( facetStats. min, 10 )
39+ XCTAssertEqual ( facetStats. max, 200 )
40+ XCTAssertNil ( facetStats. avg)
41+ XCTAssertNil ( facetStats. sum)
42+ }
43+
44+ }
You can’t perform that action at this time.
0 commit comments