Skip to content

Instantly share code, notes, and snippets.

@SeanROlszewski
Last active January 21, 2019 19:29
Show Gist options
  • Save SeanROlszewski/decfeee6feadd436fff3273dcbde896b to your computer and use it in GitHub Desktop.
Save SeanROlszewski/decfeee6feadd436fff3273dcbde896b to your computer and use it in GitHub Desktop.
class CryptoCompareResponseTests: XCTestCase {
func test_deserialization() {
let path = Bundle(for: CryptoCompareResponseTests.self).path(forResource: "CryptoCompareResponse", ofType: "json")!
let examplePayload = try! Data(contentsOf: URL(fileURLWithPath: path))
guard let response = try? JSONDecoder().decode(CryptoCompareResponse.self, from: examplePayload) else {
XCTFail("Was unable to decode the data from the payload")
return
}
guard response.data.count == 3 else {
XCTFail("Expected there to be 3 data points, but got \(response.data.count)")
return
}
XCTAssertEqual(response.data[0].time, 1515801600)
XCTAssertEqual(response.data[0].closingPrice, 1272.88, accuracy: 0.01)
XCTAssertEqual(response.data[1].time, 1516060800)
XCTAssertEqual(response.data[2].time, 1516320000)
}
}
describe("Setup handling") {
afterEach {
let workingDirectory = self.rootTestDirectory
try? FileManager.default.removeItem(atPath: "\(workingDirectory)/muter.conf.json")
}
it("creates a configuration file named muter.conf.json with placeholder values in a specified directory") {
let workingDirectory = self.rootTestDirectory
guard let _ = try? setupMuter(using: FileManager.default, and: workingDirectory),
let contents = FileManager.default.contents(atPath: "\(workingDirectory)/muter.conf.json"),
let _ = try? JSONDecoder().decode(MuterConfiguration.self, from: contents) else {
fail("Expected a valid configuration file to be written")
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment