diff --git a/Stream-iOS/Stream-iOS/Core/Networking/APIError.swift b/Stream-iOS/Stream-iOS/Core/Networking/APIError.swift new file mode 100644 index 0000000..2cefb24 --- /dev/null +++ b/Stream-iOS/Stream-iOS/Core/Networking/APIError.swift @@ -0,0 +1,13 @@ +// +// APIError.swift +// Stream-iOS +// +// Created by Ullash Podder on 14/07/2026. +// + +import Foundation +enum APIError: Error, Equatable { + case invalidResponse + case httpStatus(Int) + case decodingFailed +} diff --git a/Stream-iOS/Stream-iOS/Core/Networking/CharacterRepository.swift b/Stream-iOS/Stream-iOS/Core/Networking/CharacterRepository.swift new file mode 100644 index 0000000..53cfb66 --- /dev/null +++ b/Stream-iOS/Stream-iOS/Core/Networking/CharacterRepository.swift @@ -0,0 +1,10 @@ +// +// CharacterRepository.swift +// Stream-iOS +// +// Created by Ullash Podder on 14/07/2026. +// + +protocol CharacterRepository: Sendable { + func fetchCharacters(page: Int) async throws -> PagedResponse +} diff --git a/Stream-iOS/Stream-iOS/Core/Networking/Endpoint.swift b/Stream-iOS/Stream-iOS/Core/Networking/Endpoint.swift new file mode 100644 index 0000000..5153f7a --- /dev/null +++ b/Stream-iOS/Stream-iOS/Core/Networking/Endpoint.swift @@ -0,0 +1,26 @@ +// +// Endpoint.swift +// Stream-iOS +// +// Created by Ullash Podder on 14/07/2026. +// + +import Foundation + +struct Endpoint{ + let path : String + let queryItems : [URLQueryItem] + var url:URL? { + var components = URLComponents() + components.scheme = "https" + components.host = "rickandmortyapi.com" + components.path = "/api" + path + components.queryItems = queryItems.isEmpty ? nil : queryItems + return components.url + } +} +extension Endpoint { + static func characters(page:Int) -> Endpoint{ + Endpoint(path: "/character", queryItems: [URLQueryItem(name: "page", value: "\(page)")]) + } +} diff --git a/Stream-iOS/Stream-iOS/Core/Networking/URLSessionCharacterRepository.swift b/Stream-iOS/Stream-iOS/Core/Networking/URLSessionCharacterRepository.swift new file mode 100644 index 0000000..7ef6e29 --- /dev/null +++ b/Stream-iOS/Stream-iOS/Core/Networking/URLSessionCharacterRepository.swift @@ -0,0 +1,8 @@ +// +// URLSessionCharacterRepository.swift +// Stream-iOS +// +// Created by Ullash Podder on 14/07/2026. +// + +import Foundation diff --git a/Stream-iOS/Stream-iOSTests/EndpointTests.swift b/Stream-iOS/Stream-iOSTests/EndpointTests.swift new file mode 100644 index 0000000..13ff3a0 --- /dev/null +++ b/Stream-iOS/Stream-iOSTests/EndpointTests.swift @@ -0,0 +1,16 @@ +// +// EndpointTests.swift +// Stream-iOS +// +// Created by Ullash Podder on 14/07/2026. +// +import Testing +import Foundation +@testable import Stream_iOS + +struct EndpointTests { + @Test func buildsCharacterPageURL() throws { // <- throws here + let url = try #require(Endpoint.characters(page: 3).url) + #expect(url.absoluteString == "https://rickandmortyapi.com/api/character?page=3") + } +} diff --git a/Stream-iOS/Stream-iOSTests/Mocks/MockCharacterRepository.swift b/Stream-iOS/Stream-iOSTests/Mocks/MockCharacterRepository.swift new file mode 100644 index 0000000..dbd7308 --- /dev/null +++ b/Stream-iOS/Stream-iOSTests/Mocks/MockCharacterRepository.swift @@ -0,0 +1,19 @@ +// +// MockCharacterRepository.swift +// Stream-iOS +// +// Created by Ullash Podder on 14/07/2026. +// +//import Testing +//import Foundation +@testable import Stream_iOS + +final class MockCharacterRepository: CharacterRepository, @unchecked Sendable { + var result: Result, Error> = .failure(APIError.invalidResponse) + private(set) var requestedPages: [Int] = [] + + func fetchCharacters(page: Int) async throws -> PagedResponse { + requestedPages.append(page) + return try result.get() + } +} diff --git a/Stream-iOS/Stream-iOSTests/Stream_iOSTests.swift b/Stream-iOS/Stream-iOSTests/Stream_iOSTests.swift deleted file mode 100644 index 2962f51..0000000 --- a/Stream-iOS/Stream-iOSTests/Stream_iOSTests.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// Stream_iOSTests.swift -// Stream-iOSTests -// -// Created by Ullash Podder on 10/07/2026. -// - -import Testing -@testable import Stream_iOS - -struct Stream_iOSTests { - - @Test func example() async throws { - // Write your test here and use APIs like `#expect(...)` to check expected conditions. - // Swift Testing Documentation - // https://developer.apple.com/documentation/testing - } - -}