2020-08-09 08:04:43 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
import Combine
|
|
|
|
import CombineExpectations
|
|
|
|
@testable import Metatext
|
|
|
|
|
|
|
|
class AuthenticationServiceTests: XCTestCase {
|
2020-08-09 11:27:38 +00:00
|
|
|
func testAuthentication() throws {
|
|
|
|
let sut = AuthenticationService(environment: .development)
|
2020-08-09 08:04:43 +00:00
|
|
|
let instanceURL = URL(string: "https://mastodon.social")!
|
2020-08-09 11:27:38 +00:00
|
|
|
let appAuthorizationRecorder = sut.authorizeApp(instanceURL: instanceURL).record()
|
|
|
|
let appAuthorization = try wait(for: appAuthorizationRecorder.next(), timeout: 1)
|
2020-08-09 08:04:43 +00:00
|
|
|
|
2020-08-09 11:27:38 +00:00
|
|
|
XCTAssertEqual(appAuthorization.clientId, "AUTHORIZATION_CLIENT_ID_STUB_VALUE")
|
|
|
|
XCTAssertEqual(appAuthorization.clientSecret, "AUTHORIZATION_CLIENT_SECRET_STUB_VALUE")
|
2020-08-09 08:04:43 +00:00
|
|
|
|
2020-08-09 11:27:38 +00:00
|
|
|
let accessTokenRecorder = sut.authenticate(
|
|
|
|
instanceURL: instanceURL,
|
|
|
|
appAuthorization: appAuthorization)
|
|
|
|
.record()
|
|
|
|
let accessToken = try wait(for: accessTokenRecorder.next(), timeout: 1)
|
2020-08-09 08:04:43 +00:00
|
|
|
|
2020-08-09 11:27:38 +00:00
|
|
|
XCTAssertEqual(accessToken.accessToken, "ACCESS_TOKEN_STUB_VALUE")
|
2020-08-09 08:04:43 +00:00
|
|
|
}
|
|
|
|
}
|