75 lines
2.1 KiB
Swift
75 lines
2.1 KiB
Swift
//
|
|
// GetDataEndpoint+InitTests.swift
|
|
// APIServiceTests
|
|
//
|
|
// Created by Javier Cicchelli on 04/12/2022.
|
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
|
|
@testable import APIService
|
|
|
|
final class GetDataEndpointInitTests: XCTestCase {
|
|
|
|
// MARK: Properties
|
|
|
|
private let itemId = UUID().uuidString
|
|
|
|
private var endpoint: GetDataEndpoint!
|
|
private var username: String!
|
|
private var password: String!
|
|
|
|
// MARK: Test cases
|
|
|
|
func test_withItemId_andProperUsernameAndPassword() throws {
|
|
// GIVEN
|
|
username = "username"
|
|
password = "password"
|
|
|
|
// WHEN
|
|
endpoint = .init(
|
|
itemId: itemId,
|
|
username: username,
|
|
password: password
|
|
)
|
|
|
|
// THEN
|
|
XCTAssertEqual(endpoint.scheme, .Schemes.http)
|
|
XCTAssertEqual(endpoint.host, .Hosts.default)
|
|
XCTAssertEqual(endpoint.path, "/items/\(itemId)/data")
|
|
XCTAssertEqual(endpoint.method, .get)
|
|
XCTAssertEqual(endpoint.credentials.username, username)
|
|
XCTAssertEqual(endpoint.credentials.password, password)
|
|
XCTAssertEqual(endpoint.headers, [:])
|
|
XCTAssertEqual(endpoint.authorizationHeader, [.Header.Keys.authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ="])
|
|
XCTAssertNil(endpoint.body)
|
|
}
|
|
|
|
func test_withItemId_andEmptyUsernameOrPassword() throws {
|
|
// GIVEN
|
|
username = ""
|
|
password = "password"
|
|
|
|
// WHEN
|
|
endpoint = .init(
|
|
itemId: itemId,
|
|
username: username,
|
|
password: password
|
|
)
|
|
|
|
// THEN
|
|
XCTAssertEqual(endpoint.scheme, .Schemes.http)
|
|
XCTAssertEqual(endpoint.host, .Hosts.default)
|
|
XCTAssertEqual(endpoint.path, "/items/\(itemId)/data")
|
|
XCTAssertEqual(endpoint.method, .get)
|
|
XCTAssertEqual(endpoint.credentials.username, username)
|
|
XCTAssertEqual(endpoint.credentials.password, password)
|
|
XCTAssertEqual(endpoint.headers, [:])
|
|
XCTAssertEqual(endpoint.authorizationHeader, [:])
|
|
XCTAssertNil(endpoint.body)
|
|
}
|
|
|
|
}
|