-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from xendit/CC-4538/add-json-helpers
[CC-4538] Added functions to help with json encoding
- Loading branch information
Showing
10 changed files
with
102 additions
and
29 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// JsonEncodeTest.swift | ||
// XenditTests | ||
// | ||
// Created by xendit on 05/05/21. | ||
// | ||
|
||
import XCTest | ||
@testable import Xendit | ||
|
||
class JsonEncodeTests: XCTestCase { | ||
func testEncodeXenditCCToken() { | ||
let encoder = JSONEncoder() | ||
encoder.keyEncodingStrategy = .convertToSnakeCase | ||
let token: XenditCCToken = XenditCCToken.init(response: [ | ||
"id": "123", | ||
"status": "VERIFIED", | ||
"card_info": [ | ||
"bank": "Test bank" | ||
] | ||
])! | ||
let jsonString = try? encoder.encode(token); | ||
XCTAssertTrue(String(data: jsonString!, encoding: .utf8)! == "{\"id\":\"123\",\"status\":\"VERIFIED\",\"card_info\":{\"bank\":\"Test bank\"}}") | ||
|
||
let jsonObject = token.toJsonObject() | ||
print(jsonObject) | ||
XCTAssertTrue(jsonObject["id"] as! String == "123") | ||
let cardInfo = jsonObject["card_info"] as! [String: Any] | ||
XCTAssertTrue(cardInfo["bank"] as! String == "Test bank") | ||
} | ||
} |