Skip to content
Snippets Groups Projects
Commit bd122a10 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add FileSend model

parent f01aa47c
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Foundation
public struct FileSend: Equatable {
public init(
name: String,
type: String,
preview: Data,
contents: Data
) {
self.name = name
self.type = type
self.preview = preview
self.contents = contents
}
public var name: String
public var type: String
public var preview: Data
public var contents: Data
}
extension FileSend: Codable {
enum CodingKeys: String, CodingKey {
case name = "Name"
case type = "Type"
case preview = "Preview"
case contents = "Contents"
}
public static func decode(_ data: Data) throws -> Self {
try JSONDecoder().decode(Self.self, from: data)
}
public func encode() throws -> Data {
try JSONEncoder().encode(self)
}
}
import CustomDump
import XCTest
@testable import ElixxirDAppsSDK
final class FileSendTests: XCTestCase {
func testCoding() throws {
let name = "testfile.txt"
let type = "text file"
let previewB64 = "aXQncyBtZSBhIHByZXZpZXc="
let contentsB64 = "VGhpcyBpcyB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZmlsZSBpbiBieXRlcw=="
let jsonString = """
{
"Name": "\(name)",
"Type": "\(type)",
"Preview": "\(previewB64)",
"Contents": "\(contentsB64)"
}
"""
let jsonData = jsonString.data(using: .utf8)!
let fileSend = try FileSend.decode(jsonData)
XCTAssertNoDifference(fileSend, FileSend(
name: name,
type: type,
preview: Data(base64Encoded: previewB64)!,
contents: Data(base64Encoded: contentsB64)!
))
let encodedFileSend = try fileSend.encode()
let decodedFileSend = try FileSend.decode(encodedFileSend)
XCTAssertNoDifference(decodedFileSend, fileSend)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment