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

53 lines
1.8 KiB
Swift
Raw Normal View History

2021-01-29 12:38:11 +01:00
//
// MastodonSDK+API+OAuthTests.swift
//
//
// Created by MainasuK Cirno on 2021/1/29.
//
import os.log
import XCTest
import Combine
@testable import MastodonSDK
extension MastodonSDKTests {
func testOAuthAuthorize() throws {
try _testOAuthAuthorize(domain: domain)
}
func _testOAuthAuthorize(domain: String) throws {
2021-07-08 08:17:35 +02:00
let query = Mastodon.API.OAuth.AuthorizeQuery(clientID: "StubClientID", redirectURI: "mastodon://joinmastodon.org/oauth")
2021-01-29 12:38:11 +01:00
let authorizeURL = Mastodon.API.OAuth.authorizeURL(domain: domain, query: query)
os_log("%{public}s[%{public}ld], %{public}s: (%s) authorizeURL %s", ((#file as NSString).lastPathComponent), #line, #function, domain, authorizeURL.absoluteString)
XCTAssertEqual(
authorizeURL.absoluteString,
"\(URL.httpScheme(domain: domain))://\(domain)/oauth/authorize?response_type=code&client_id=StubClientID&redirect_uri=mastodon://joinmastodon.org/oauth&scope=read%20write%20follow%20push"
2021-01-29 12:38:11 +01:00
)
}
func testRevokeToken() throws {
_testRevokeTokenFail()
}
func _testRevokeTokenFail() {
2021-07-08 08:17:35 +02:00
let theExpectation = expectation(description: "Revoke Instance Information")
let query = Mastodon.API.OAuth.RevokeTokenQuery(clientID: "StubClientID", clientSecret: "", token: "")
Mastodon.API.OAuth.revokeToken(session: session, domain: domain, query: query)
.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
case .failure:
theExpectation.fulfill()
case .finished:
XCTFail("Success in a failed test?")
}
} receiveValue: { response in
}
.store(in: &disposeBag)
wait(for: [theExpectation], timeout: 10.0)
}
2021-01-29 12:38:11 +01:00
}