mastodon-app-ufficiale-ipho.../MastodonSDK/Tests/MastodonSDKTests/API/MastodonSDK+API+AppTests.swift

84 lines
2.8 KiB
Swift
Raw Normal View History

2021-01-29 12:38:11 +01:00
//
// MastodonSDK+API+AppTests.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import os.log
import XCTest
import Combine
@testable import MastodonSDK
extension MastodonSDKTests {
func testCreateAnAnpplication() throws {
try _testCreateAnAnpplication(domain: domain)
}
func _testCreateAnAnpplication(domain: String) throws {
let theExpectation = expectation(description: "Create An Application")
let query = Mastodon.API.App.CreateQuery(
clientName: "XCTest",
website: nil
)
Mastodon.API.App.create(session: session, domain: domain, query: query)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssertEqual(response.value.name, "XCTest")
XCTAssertEqual(response.value.website, nil)
XCTAssertEqual(response.value.redirectURI, "urn:ietf:wg:oauth:2.0:oob")
os_log("%{public}s[%{public}ld], %{public}s: (%s) clientID %s", ((#file as NSString).lastPathComponent), #line, #function, domain, response.value.clientID ?? "nil")
os_log("%{public}s[%{public}ld], %{public}s: (%s) clientSecret %s", ((#file as NSString).lastPathComponent), #line, #function, domain, response.value.clientSecret ?? "nil")
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 5.0)
}
}
extension MastodonSDKTests {
func testVerifyAppCredentials() throws {
try _testVerifyAppCredentials(domain: domain, accessToken: testToken)
2021-01-29 12:38:11 +01:00
}
func _testVerifyAppCredentials(domain: String, accessToken: String) throws {
let theExpectation = expectation(description: "Verify App Credentials")
let authorization = Mastodon.API.OAuth.Authorization(accessToken: accessToken)
Mastodon.API.App.verifyCredentials(
session: session,
domain: domain,
authorization: authorization
)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure(let error):
XCTFail(error.localizedDescription)
case .finished:
break
}
} receiveValue: { response in
XCTAssertEqual(response.value.name, "XCTest")
XCTAssertEqual(response.value.website, nil)
theExpectation.fulfill()
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 5.0)
}
}