Implemented the GetDataEndpoint endpoint.
This commit is contained in:
parent
6e03a97622
commit
90d13b2651
42
Libraries/Sources/APIService/Endpoints/GetDataEndpoint.swift
Normal file
42
Libraries/Sources/APIService/Endpoints/GetDataEndpoint.swift
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,8 +6,8 @@
|
|||||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import XCTest
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import XCTest
|
||||||
|
|
||||||
@testable import APIService
|
@testable import APIService
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ final class GetItemsEndpointInitTests: XCTestCase {
|
|||||||
|
|
||||||
// MARK: Test cases
|
// MARK: Test cases
|
||||||
|
|
||||||
func test_withProperUsernameAndPassword() throws {
|
func test_withItemId_andProperUsernameAndPassword() throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
username = "username"
|
username = "username"
|
||||||
password = "password"
|
password = "password"
|
||||||
@ -47,7 +47,7 @@ final class GetItemsEndpointInitTests: XCTestCase {
|
|||||||
XCTAssertNil(endpoint.body)
|
XCTAssertNil(endpoint.body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_withEmptyUsernameOrPassword() async throws {
|
func test_withItemId_andEmptyUsernameOrPassword() async throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
username = ""
|
username = ""
|
||||||
password = "password"
|
password = "password"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user