64 lines
2.0 KiB
Swift

//
// GetMeEndpoint+InitTests.swift
// APIServiceTests
//
// Created by Javier Cicchelli on 04/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import XCTest
@testable import APIService
final class GetMeEndpointInitTests: XCTestCase {
// MARK: Properties
var endpoint: GetMeEndpoint!
var username: String!
var password: String!
// MARK: Test cases
func test_withProperUsernameAndPassword() throws {
// GIVEN
username = "username"
password = "password"
// WHEN
endpoint = .init(username: username, password: password)
// THEN
XCTAssertEqual(endpoint.scheme, .Schemes.http)
XCTAssertEqual(endpoint.host, .Hosts.default)
XCTAssertEqual(endpoint.path, "/me")
XCTAssertEqual(endpoint.method, .get)
XCTAssertEqual(endpoint.credentials.username, username)
XCTAssertEqual(endpoint.credentials.password, password)
XCTAssertEqual(endpoint.headers, [.Header.Keys.contentType: .Header.Values.contentTypeJSON])
XCTAssertEqual(endpoint.authorizationHeader, [.Header.Keys.authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ="])
XCTAssertNil(endpoint.body)
}
func test_withEmptyUsernameOrPassword() async throws {
// GIVEN
username = ""
password = "password"
// WHEN
endpoint = .init(username: username, password: password)
// THEN
XCTAssertEqual(endpoint.scheme, .Schemes.http)
XCTAssertEqual(endpoint.host, .Hosts.default)
XCTAssertEqual(endpoint.path, "/me")
XCTAssertEqual(endpoint.method, .get)
XCTAssertEqual(endpoint.credentials.username, username)
XCTAssertEqual(endpoint.credentials.password, password)
XCTAssertEqual(endpoint.headers, [.Header.Keys.contentType: .Header.Values.contentTypeJSON])
XCTAssertEqual(endpoint.authorizationHeader, [:])
XCTAssertNil(endpoint.body)
}
}