-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJSONParsingTests.swift
59 lines (44 loc) · 2.36 KB
/
JSONParsingTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// CommunTests.swift
// CommunTests
//
// Created by Chung Tran on 14/06/2019.
// Copyright © 2019 Commun Limited. All rights reserved.
//
import XCTest
import CyberSwift
class JSONParsingTests: XCTestCase {
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testChainResponseErrorJSON() {
let string = "{\"code\":500,\"message\":\"Internal Service Error\",\"error\":{\"code\":3050003,\"name\":\"eosio_assert_message_exception\",\"what\":\"eosio_assert_message assertion failure\",\"details\":[{\"message\":\"assertion failure with message: not enough power\",\"file\":\"wasm_interface.cpp\",\"line_number\":928,\"method\":\"eosio_assert\"},{\"message\":\"pending console output: \",\"file\":\"apply_context.cpp\",\"line_number\":79,\"method\":\"exec_one\"}]}}"
let object = try? JSONSerialization.jsonObject(with: string.data(using: .utf8)!, options: .allowFragments) as? [String: Any]
let bcError = object?["error"] as? [String: Any]
let details = bcError?["details"] as? [[String: Any]]
let firstDetail = details?.first
let messsage = firstDetail?["message"] as? String
XCTAssertEqual(messsage, "assertion failure with message: not enough power")
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testBase64ToJSON() {
let base64String = "eyJ1c2VySWQiOiJ0c3Q1bGlobHNtYXkiLCJ1c2VybmFtZSI6ImhyZW4tcGlwZW4iLCJwYXNzd29yZCI6IlA1SzU0V1pmem9TR1pzMmlhTHVzeThHRWVkbUJtOHpIYWdBTFQ4Q0dYVEZVb01UVEM3QTMifQ=="
guard let decodedData = Data(base64Encoded: base64String),
let user = try? JSONDecoder().decode(QrCodeDecodedProfile.self, from: decodedData)
else {
XCTAssertFalse(true)
return
}
XCTAssertEqual(user.username, "hren-pipen")
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}