-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to ensure MetaData is encoded correctly in all cases
Also ensures we can't bypass the validation by instantiating the enum case directly.
- Loading branch information
1 parent
4c429f1
commit 432aa36
Showing
5 changed files
with
129 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Networking/NetworkingTests/Encoder/MetaDataEncoderTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import Networking | ||
|
||
/// Check MetaData encoding to Dictionary | ||
/// | ||
class MetaDataEncoderTests: XCTestCase { | ||
func test_encode_metadataString_to_dictionary() throws { | ||
// Given | ||
let metadata = MetaData(metadataID: 1, key: "key", value: "value") | ||
|
||
// When | ||
let dictionary = try metadata.toDictionary() | ||
|
||
// Then | ||
XCTAssertEqual(dictionary["id"] as? Int, 1) | ||
XCTAssertEqual(dictionary["key"] as? String, "key") | ||
XCTAssertEqual(dictionary["value"] as? String, "value") | ||
} | ||
|
||
func test_encode_metadataJson_to_dictionary() throws { | ||
// Given | ||
let metadata = MetaData(metadataID: 1, key: "key", value: "{\"key\":\"value\"}") | ||
|
||
// When | ||
let dictionary = try metadata.toDictionary() | ||
|
||
// Then | ||
let expectedValue = ["key": "value"] | ||
XCTAssertEqual(dictionary["id"] as? Int, 1) | ||
XCTAssertEqual(dictionary["key"] as? String, "key") | ||
XCTAssertEqual(dictionary["value"] as? [String: String], expectedValue) | ||
} | ||
|
||
func test_encode_metadataJsonArray_to_dictionary() throws { | ||
// Given | ||
let metadata = MetaData(metadataID: 1, key: "key", value: "[{\"key\":\"value\"}]") | ||
|
||
// When | ||
let dictionary = try metadata.toDictionary() | ||
|
||
// Then | ||
let expectedValue = [["key": "value"]] | ||
XCTAssertEqual(dictionary["id"] as? Int, 1) | ||
XCTAssertEqual(dictionary["key"] as? String, "key") | ||
XCTAssertEqual(dictionary["value"] as? [[String: String]], expectedValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters