Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .swiftpm/product.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "CBA25149-CE25-449E-A308-EE7557C98D23",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {

},
"testTargets" : [
{
"target" : {
"containerPath" : "container:",
"identifier" : "Coffee-KitTests",
"name" : "Coffee-KitTests"
}
}
],
"version" : 1
}
9 changes: 7 additions & 2 deletions .swiftpm/xcode/xcshareddata/xcschemes/Coffee-Kit.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:.swiftpm/product.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
Expand Down
4 changes: 2 additions & 2 deletions Sources/Coffee-Kit/Webservice/Manager/MenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Foundation

// MARK: - Computed Properties

public var itemSequence: CoffeeService {
return CoffeeService(databaseAPI: webservice.databaseAPI)
public var itemSequence: ProductService {
return ProductService(databaseAPI: webservice.databaseAPI)
}

// MARK: - Initializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
import Foundation

@MainActor
public struct CoffeeService {
public struct ProductService {
// MARK: Properties

let coffeeURL: URL
let productURL: URL

// MARK: Initializer

public init(databaseAPI: DatabaseAPI) {
self.coffeeURL = databaseAPI.baseURL / "coffee"
print(coffeeURL)
self.productURL = databaseAPI.baseURL / "coffee"
print(productURL)
}

// MARK: Methods

public func getIds() async throws -> [String] {
let coffeeIdsUrl = coffeeURL / "ids"
let (data, response) = try await URLSession.shared.data(from: coffeeIdsUrl)
let productIdsUrl = productURL / "ids"
let (data, response) = try await URLSession.shared.data(from: productIdsUrl)

guard let drinkIds = try? JSONDecoder().decode([String].self, from: data) else {
guard let productIds = try? JSONDecoder().decode([String].self, from: data) else {
print(response)
print("""
Error in \(#file)
Expand All @@ -36,15 +36,15 @@ public struct CoffeeService {
throw FetchError.decodingError
}

return drinkIds
return productIds
}

public func load(by id: consuming String) async throws -> Product {
let coffeeByIdUrl = coffeeURL / "id" / id
let coffeeByIdUrl = productURL / "id" / id

let (data, response) = try await URLSession.shared.data(from: coffeeByIdUrl)

guard let coffee = try? JSONDecoder().decode(Product.self, from: data) else {
guard let product = try? JSONDecoder().decode(Product.self, from: data) else {
print(response)

let stacktrace = Thread.callStackSymbols.joined(separator: "\n")
Expand All @@ -57,16 +57,16 @@ public struct CoffeeService {
throw FetchError.decodingError
}

return coffee
return product
}

public func load(by ids: [String]) async -> AsyncThrowingStream<Product, Error> {
return AsyncThrowingStream<Product, Error> { continuation in
Task {
do {
for id in ids {
let coffeeModel = try await load(by: id)
continuation.yield(coffeeModel)
let productModel = try await load(by: id)
continuation.yield(productModel)
}
continuation.finish()
} catch {
Expand Down
19 changes: 18 additions & 1 deletion Tests/Coffee-KitTests/Coffee_LoverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import XCTest

final class Coffee_LoverTests: XCTestCase {
fileprivate func decodingCoffeTest() async throws {
func testDecodingProduct() throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.

let ressource = """
Expand All @@ -35,4 +35,21 @@ final class Coffee_LoverTests: XCTestCase {

XCTAssertEqual(product.id.uuidString, "e074867a-0c6a-49ff-87ca-b1ba5dae5236".uppercased())
}

func testEncodingProduct() {
let product = Product()
guard let data = try? JSONEncoder().encode(product)
else {
XCTFail("Encoding failed")
return
}

guard let json = String(data: data, encoding: .utf8)
else {
XCTFail("Decoding failed")
return
}

XCTAssertFalse(json.isEmpty)
}
}
6 changes: 4 additions & 2 deletions Tests/Coffee-KitTests/OrderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Foundation
import XCTest

final class OrderTests: XCTestCase {
fileprivate func testTakingOrder() async {
func testTakingOrder() async {
let databaseAPI = DatabaseAPI.dev
let webservice = await WebserviceProvider(inMode: databaseAPI)
let orderManager = await OrderManager(from: webservice)
_ = await OrderManager(from: webservice)
//
// var products = orderManager.shoppingCard
// products.add( CakeModel(), to: "Cakes")
Expand All @@ -25,4 +25,6 @@ final class OrderTests: XCTestCase {
//
// await orderManager.takeOrder()
}


}
Loading