Skip to content

Commit ce323a7

Browse files
committed
more tests
1 parent e1ddade commit ce323a7

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Tests/PackageCollectionsTests/PackageCollectionsTests.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,59 @@ final class PackageCollectionsTests: XCTestCase {
9494
}
9595
}
9696

97+
func testDeleteFromStorageWhenLast() throws {
98+
let configuration = PackageCollections.Configuration()
99+
let storage = makeMockStorage()
100+
defer { XCTAssertNoThrow(try storage.close()) }
101+
102+
let mockCollection = makeMockCollections(count: 1).first!
103+
let mockProfile1 = PackageCollectionsModel.Profile(name: "profile-\(UUID().uuidString)")
104+
let mockProfile2 = PackageCollectionsModel.Profile(name: "profile-\(UUID().uuidString)")
105+
106+
let providers = [PackageCollectionsModel.CollectionSourceType.feed: MockProvider([mockCollection])]
107+
let packageCollections = PackageCollections(configuration: configuration, storage: storage, providers: providers)
108+
109+
do {
110+
let list = try await { callback in packageCollections.listCollections(callback: callback) }
111+
XCTAssertEqual(list.count, 0, "list should be empty")
112+
}
113+
114+
_ = try await { callback in packageCollections.addCollection(mockCollection.source, order: nil, to: mockProfile1, callback: callback) }
115+
_ = try await { callback in packageCollections.addCollection(mockCollection.source, order: nil, to: mockProfile2, callback: callback) }
116+
117+
do {
118+
let list1 = try await { callback in packageCollections.listCollections(in: mockProfile1, callback: callback) }
119+
XCTAssertEqual(list1.count, 1, "list count should match")
120+
121+
let list2 = try await { callback in packageCollections.listCollections(in: mockProfile2, callback: callback) }
122+
XCTAssertEqual(list2.count, 1, "list count should match")
123+
}
124+
125+
do {
126+
_ = try await { callback in packageCollections.removeCollection(mockCollection.source, from: mockProfile1, callback: callback) }
127+
let list1 = try await { callback in packageCollections.listCollections(in: mockProfile1, callback: callback) }
128+
XCTAssertEqual(list1.count, 0, "list count should match")
129+
130+
let list2 = try await { callback in packageCollections.listCollections(in: mockProfile2, callback: callback) }
131+
XCTAssertEqual(list2.count, 1, "list count should match")
132+
133+
// check if exists in storage
134+
XCTAssertNoThrow(try await { callback in storage.collections.get(identifier: mockCollection.identifier, callback: callback) })
135+
}
136+
137+
do {
138+
_ = try await { callback in packageCollections.removeCollection(mockCollection.source, from: mockProfile2, callback: callback) }
139+
let list1 = try await { callback in packageCollections.listCollections(in: mockProfile1, callback: callback) }
140+
XCTAssertEqual(list1.count, 0, "list count should match")
141+
142+
let list2 = try await { callback in packageCollections.listCollections(in: mockProfile2, callback: callback) }
143+
XCTAssertEqual(list2.count, 0, "list count should match")
144+
145+
// check if exists in storage
146+
XCTAssertThrowsError(try await { callback in storage.collections.get(identifier: mockCollection.identifier, callback: callback) }, "expected error")
147+
}
148+
}
149+
97150
func testOrdering() throws {
98151
let configuration = PackageCollections.Configuration()
99152
let storage = makeMockStorage()

0 commit comments

Comments
 (0)