From 1836e0851bcc3db60f7aa6016193d62f539aa402 Mon Sep 17 00:00:00 2001 From: Alexander Osokin Date: Mon, 30 Oct 2023 17:46:43 +0000 Subject: [PATCH] IOS-4927 Try to make tests locale independent --- .../Common/JSON/JSONStringConvertible.swift | 7 ++++++- TangemSdk/TangemSdkTests/JSONRPCTests.swift | 13 ++----------- TangemSdk/TangemSdkTests/TlvTests.swift | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/TangemSdk/TangemSdk/Common/JSON/JSONStringConvertible.swift b/TangemSdk/TangemSdk/Common/JSON/JSONStringConvertible.swift index ea49c9f21..83b720061 100644 --- a/TangemSdk/TangemSdk/Common/JSON/JSONStringConvertible.swift +++ b/TangemSdk/TangemSdk/Common/JSON/JSONStringConvertible.swift @@ -20,7 +20,12 @@ public extension JSONStringConvertible { let data = (try? JSONEncoder.tangemSdkEncoder.encode(self)) ?? Data() return String(data: data, encoding: .utf8)! } - + + var testJson: String { + let data = (try? JSONEncoder.tangemSdkTestEncoder.encode(self)) ?? Data() + return String(data: data, encoding: .utf8)! + } + func eraseToAnyResponse() -> AnyJSONRPCResponse { AnyJSONRPCResponse(self) } diff --git a/TangemSdk/TangemSdkTests/JSONRPCTests.swift b/TangemSdk/TangemSdkTests/JSONRPCTests.swift index 696f76301..37ccfd8e3 100644 --- a/TangemSdk/TangemSdkTests/JSONRPCTests.swift +++ b/TangemSdk/TangemSdkTests/JSONRPCTests.swift @@ -92,17 +92,8 @@ class JSONRPCTests: XCTestCase { func testJsonResponse() { let response = SuccessResponse(cardId: "c000111122223333") let result: Result = .success(response) - let jsonResponse = result.toJsonResponse(id: 1).json - let testResponse = - """ - { - "jsonrpc" : "2.0", - "result" : { - "cardId" : "c000111122223333" - }, - "id" : 1 - } - """ + let jsonResponse = result.toJsonResponse(id: 1).testJson + let testResponse = "{\"id\":1,\"jsonrpc\":\"2.0\",\"result\":{\"cardId\":\"c000111122223333\"}}" XCTAssertEqual(jsonResponse, testResponse) } diff --git a/TangemSdk/TangemSdkTests/TlvTests.swift b/TangemSdk/TangemSdkTests/TlvTests.swift index 1256444f8..a67810f1b 100644 --- a/TangemSdk/TangemSdkTests/TlvTests.swift +++ b/TangemSdk/TangemSdkTests/TlvTests.swift @@ -177,7 +177,7 @@ class TlvTests: XCTestCase { //test dateTime let date: Date = try! cardDataDecoder.decode(.manufactureDateTime) - let dateString = date.toString(style: .short) + let dateString = date.toString(style: .short, locale: Locale(identifier: "en_US")) XCTAssertEqual(dateString, "7/27/18") let dateWrong: Int? = try? cardDataDecoder.decode(.manufactureDateTime)