This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Get details of a collection at the given address - Get a list of collection filters - Get a list of collections
- Loading branch information
1 parent
abe389f
commit 502ad16
Showing
7 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Foundation | ||
|
||
// swiftlint:disable:next line_length | ||
/// Ordering options available for ``ImmutableX/listCollections(pageSize:cursor:orderBy:direction:blacklist:whitelist:keyword:)`` | ||
public enum ListCollectionsOrderBy: String, CaseIterable { | ||
case name | ||
case address | ||
case projectId = "project_id" | ||
case createdAt = "created_at" | ||
case updatedAt = "updated_at" | ||
|
||
/// Converts this enum to the type expected by the generated API code | ||
internal var asApiArgument: CollectionsAPI.OrderBy_listCollections { | ||
switch self { | ||
case .name: | ||
return .name | ||
case .address: | ||
return .address | ||
case .projectId: | ||
return .projectId | ||
case .createdAt: | ||
return .createdAt | ||
case .updatedAt: | ||
return .updatedAt | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Tests/ImmutableXCoreTests/Mocks/API/CollectionsAPIMock.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import Foundation | ||
@testable import ImmutableXCore | ||
|
||
final class CollectionsAPIMock: CollectionsAPI { | ||
class GetCollectionCompanion { | ||
var throwableError: Error? | ||
var callsCount = 0 | ||
var returnValue: Collection! | ||
} | ||
|
||
class ListCollectionFiltersCompanion { | ||
var throwableError: Error? | ||
var callsCount = 0 | ||
var returnValue: CollectionFilter! | ||
} | ||
|
||
class ListCollectionsCompanion { | ||
var throwableError: Error? | ||
var callsCount = 0 | ||
var returnValue: ListCollectionsResponse! | ||
} | ||
|
||
static var getCollectionCompanion: GetCollectionCompanion? | ||
static var listCollectionFiltersCompanion: ListCollectionFiltersCompanion? | ||
static var listCollectionsCompanion: ListCollectionsCompanion? | ||
|
||
static func mock(_ companion: GetCollectionCompanion) { | ||
getCollectionCompanion = companion | ||
} | ||
|
||
static func mock(_ companion: ListCollectionFiltersCompanion) { | ||
listCollectionFiltersCompanion = companion | ||
} | ||
|
||
static func mock(_ companion: ListCollectionsCompanion) { | ||
listCollectionsCompanion = companion | ||
} | ||
|
||
static func resetMock() { | ||
getCollectionCompanion = nil | ||
listCollectionFiltersCompanion = nil | ||
listCollectionsCompanion = nil | ||
} | ||
|
||
override class func getCollection(address: String) async throws -> Collection { | ||
let companion = getCollectionCompanion! | ||
companion.callsCount += 1 | ||
|
||
if let error = companion.throwableError { | ||
throw error | ||
} | ||
|
||
return companion.returnValue | ||
} | ||
|
||
override class func listCollectionFilters(address: String, pageSize: Int? = nil, nextPageToken: String? = nil) async throws -> CollectionFilter { | ||
let companion = listCollectionFiltersCompanion! | ||
companion.callsCount += 1 | ||
|
||
if let error = companion.throwableError { | ||
throw error | ||
} | ||
|
||
return companion.returnValue | ||
} | ||
|
||
override class func listCollections(pageSize: Int? = nil, cursor: String? = nil, orderBy: CollectionsAPI.OrderBy_listCollections? = nil, direction: String? = nil, blacklist: String? = nil, whitelist: String? = nil, keyword: String? = nil) async throws -> ListCollectionsResponse { | ||
let companion = listCollectionsCompanion! | ||
companion.callsCount += 1 | ||
|
||
if let error = companion.throwableError { | ||
throw error | ||
} | ||
|
||
return companion.returnValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Tests/ImmutableXCoreTests/Model/ListCollectionsOrderByTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@testable import ImmutableXCore | ||
import XCTest | ||
|
||
final class ListCollectionsOrderByTests: XCTestCase { | ||
func testAsApiArgument() throws { | ||
XCTAssertEqual(ListCollectionsOrderBy.name.asApiArgument, .name) | ||
XCTAssertEqual(ListCollectionsOrderBy.address.asApiArgument, .address) | ||
XCTAssertEqual(ListCollectionsOrderBy.projectId.asApiArgument, .projectId) | ||
XCTAssertEqual(ListCollectionsOrderBy.createdAt.asApiArgument, .createdAt) | ||
XCTAssertEqual(ListCollectionsOrderBy.updatedAt.asApiArgument, .updatedAt) | ||
XCTAssertEqual( | ||
ListCollectionsOrderBy.allCases.map(\.rawValue), | ||
CollectionsAPI.OrderBy_listCollections.allCases.map(\.rawValue) | ||
) | ||
} | ||
} |