Implemented the GetItemsEndpoint endpoint.
This commit is contained in:
parent
bfb47ea0f8
commit
6e03a97622
@ -0,0 +1,42 @@
|
|||||||
|
//
|
||||||
|
// GetItemsEndpoint.swift
|
||||||
|
// APIService
|
||||||
|
//
|
||||||
|
// Created by Javier Cicchelli on 04/12/2022.
|
||||||
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
struct GetItemsEndpoint: Endpoint {
|
||||||
|
let path: String
|
||||||
|
let method: RequestMethod
|
||||||
|
let credentials: BasicCredentials
|
||||||
|
let headers: [String : String]
|
||||||
|
let body: [String : String]?
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Initialisers
|
||||||
|
|
||||||
|
extension GetItemsEndpoint {
|
||||||
|
init(
|
||||||
|
itemId: String,
|
||||||
|
username: String,
|
||||||
|
password: String
|
||||||
|
) {
|
||||||
|
self.path = .init(format: .Formats.itemsWithId, itemId)
|
||||||
|
self.method = .get
|
||||||
|
self.credentials = .init(
|
||||||
|
username: username,
|
||||||
|
password: password
|
||||||
|
)
|
||||||
|
self.headers = [.Header.Keys.contentType: .Header.Values.contentTypeJSON]
|
||||||
|
self.body = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - String+Formats
|
||||||
|
|
||||||
|
private extension String {
|
||||||
|
enum Formats {
|
||||||
|
static let itemsWithId = "/items/%@"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
//
|
||||||
|
// GetItemsEndpoint+InitTests.swift
|
||||||
|
// APIServiceTests
|
||||||
|
//
|
||||||
|
// Created by Javier Cicchelli on 04/12/2022.
|
||||||
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import XCTest
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@testable import APIService
|
||||||
|
|
||||||
|
final class GetItemsEndpointInitTests: XCTestCase {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
let itemId = UUID().uuidString
|
||||||
|
|
||||||
|
var endpoint: GetItemsEndpoint!
|
||||||
|
var username: String!
|
||||||
|
var password: String!
|
||||||
|
|
||||||
|
// MARK: Test cases
|
||||||
|
|
||||||
|
func test_withProperUsernameAndPassword() 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)
|
||||||
|
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(
|
||||||
|
itemId: itemId,
|
||||||
|
username: username,
|
||||||
|
password: password
|
||||||
|
)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
XCTAssertEqual(endpoint.scheme, .Schemes.http)
|
||||||
|
XCTAssertEqual(endpoint.host, .Hosts.default)
|
||||||
|
XCTAssertEqual(endpoint.path, "/items/" + itemId)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user