Updated the project documentation in the package.
This commit is contained in:
@@ -72,6 +72,31 @@ This leverages HTTP cache headers from the server and persists cached responses
|
||||
|
||||
Alternatively, cache the results returned by ``AmiiboService`` directly in your application using any storage mechanism that fits your needs, such as an in-memory dictionary, a database, or a file-based store.
|
||||
|
||||
## Testing
|
||||
|
||||
The ``AmiiboClient`` protocol enables creating custom mock clients for testing, eliminating the need for network calls in unit tests. Conform to ``AmiiboClient`` and return stubbed data or throw ``AmiiboServiceError`` errors to verify your application's behavior:
|
||||
|
||||
```swift
|
||||
import AmiiboService
|
||||
|
||||
struct MyMockClient: AmiiboClient {
|
||||
var error: AmiiboServiceError?
|
||||
|
||||
func getAmiibos(
|
||||
by filter: AmiiboFilter
|
||||
) async throws(AmiiboServiceError) -> [Amiibo] {
|
||||
if let error { throw error }
|
||||
return []
|
||||
}
|
||||
|
||||
// Implement remaining protocol requirements...
|
||||
}
|
||||
|
||||
let service = AmiiboService(client: MyMockClient())
|
||||
```
|
||||
|
||||
Inject the mock client into ``AmiiboService`` via its ``AmiiboService/init(client:)`` initializer to test how your code handles empty results, specific errors, or any other scenario without relying on the live backend.
|
||||
|
||||
## Tasks
|
||||
|
||||
This library offers a set of ready-to-use tasks that simplify the interaction with the library, which the developer can use from any `Terminal` application.
|
||||
|
||||
Reference in New Issue
Block a user