diff --git a/Libraries/Sources/APIService/Endpoints/GetDataEndpoint.swift b/Libraries/Sources/APIService/Endpoints/GetDataEndpoint.swift new file mode 100644 index 0000000..e3ab99a --- /dev/null +++ b/Libraries/Sources/APIService/Endpoints/GetDataEndpoint.swift @@ -0,0 +1,42 @@ +// +// GetDataEndpoint.swift +// APIService +// +// Created by Javier Cicchelli on 04/12/2022. +// Copyright © 2022 Röck+Cöde. All rights reserved. +// + +struct GetDataEndpoint: Endpoint { + let path: String + let method: RequestMethod + let credentials: BasicCredentials + let headers: [String : String] + let body: [String : String]? +} + +// MARK: - Initialisers + +extension GetDataEndpoint { + init( + itemId: String, + username: String, + password: String + ) { + self.path = .init(format: .Formats.itemsDataWithId, itemId) + self.method = .get + self.credentials = .init( + username: username, + password: password + ) + self.headers = [:] + self.body = nil + } +} + +// MARK: - String+Formats + +private extension String { + enum Formats { + static let itemsDataWithId = "/items/%@/data" + } +} diff --git a/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetDataEndpoint+InitTests.swift b/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetDataEndpoint+InitTests.swift new file mode 100644 index 0000000..3803111 --- /dev/null +++ b/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetDataEndpoint+InitTests.swift @@ -0,0 +1,74 @@ +// +// 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 + + let itemId = UUID().uuidString + + var endpoint: GetDataEndpoint! + var username: String! + 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() async 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) + } + +} diff --git a/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetItemsEndpoint+InitTests.swift b/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetItemsEndpoint+InitTests.swift index 5d1fc3d..1834a34 100644 --- a/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetItemsEndpoint+InitTests.swift +++ b/Libraries/Tests/APIServiceTests/Cases/Endpoints/GetItemsEndpoint+InitTests.swift @@ -6,8 +6,8 @@ // Copyright © 2022 Röck+Cöde. All rights reserved. // -import XCTest import Foundation +import XCTest @testable import APIService @@ -23,7 +23,7 @@ final class GetItemsEndpointInitTests: XCTestCase { // MARK: Test cases - func test_withProperUsernameAndPassword() throws { + func test_withItemId_andProperUsernameAndPassword() throws { // GIVEN username = "username" password = "password" @@ -47,7 +47,7 @@ final class GetItemsEndpointInitTests: XCTestCase { XCTAssertNil(endpoint.body) } - func test_withEmptyUsernameOrPassword() async throws { + func test_withItemId_andEmptyUsernameOrPassword() async throws { // GIVEN username = "" password = "password"