Skip to content

Commit 34c1823

Browse files
committed
Added testcases for where method
1 parent 6da14e7 commit 34c1823

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

ContentstackTest/ContentstackTest.m

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,88 @@ - (void)test04FetchAssets {
203203
[self waitForRequest];
204204
}
205205

206+
- (void)testFetchAssetByQuery01{
207+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Asset By where method"];
208+
AssetLibrary* assets = [csStack assetLibrary];
209+
[assets where:@"title" equalTo:@"image1"];
210+
[assets fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
211+
if (error) {
212+
XCTFail(@"~ ERR: %@, Message = %@", error.userInfo, error.description);
213+
} else {
214+
XCTAssert(type == NETWORK, @"Pass");
215+
XCTAssertNil(error, @"Expected no error, but got: %@", error.userInfo);
216+
XCTAssert(result.count > 0, @"Expected results, but got none.");
217+
}
218+
[expectation fulfill];
219+
}];
220+
[self waitForRequest];
221+
}
222+
223+
- (void)testFetchAssetsByValidFileSize02 {
224+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Asset By valid file size"];
225+
AssetLibrary *assets = [csStack assetLibrary];
226+
[assets where:@"file_size" equalTo:@(53986)]; // Valid file size
227+
[assets fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
228+
XCTAssert(type == NETWORK, @"Pass");
229+
XCTAssertNil(error, @"Expected no error, but got: %@", error.userInfo);
230+
XCTAssert(result.count > 0, @"Expected results, but got none.");
231+
[expectation fulfill];
232+
}];
233+
[self waitForRequest];
234+
}
235+
236+
- (void)testFetchAssetsByNonExistentFileSize03 {
237+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Asset By non-existent file size"];
238+
AssetLibrary *assets = [csStack assetLibrary];
239+
[assets where:@"file_size" equalTo:@(9999999)]; // Non-existent file size
240+
[assets fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
241+
XCTAssert(type == NETWORK, @"Pass");
242+
XCTAssertNil(error, @"Expected no error, but got: %@", error.userInfo);
243+
XCTAssertEqual(result.count, 0, @"Expected no results, but got some.");
244+
[expectation fulfill];
245+
}];
246+
[self waitForRequest];
247+
}
248+
249+
- (void)testFetchAssetsByNonExistentTitle04 {
250+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Asset By non-existent title"];
251+
AssetLibrary *assets = [csStack assetLibrary];
252+
[assets where:@"title" equalTo:@"non-existent-title.png"]; // Non-existent title
253+
[assets fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
254+
XCTAssert(type == NETWORK, @"Pass");
255+
XCTAssertNil(error, @"Expected no error, but got: %@", error.userInfo);
256+
XCTAssertEqual(result.count, 0, @"Expected no results, but got some.");
257+
[expectation fulfill];
258+
}];
259+
[self waitForRequest];
260+
}
261+
262+
- (void)testFetchAssetsByMultipleConditions05 {
263+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Asset By multiple conditions"];
264+
AssetLibrary *assets = [csStack assetLibrary];
265+
[assets where:@"file_size" equalTo:@(6884)]; // Valid file size
266+
[assets where:@"title" equalTo:@"image4"]; // Valid title
267+
[assets fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
268+
XCTAssert(type == NETWORK, @"Pass");
269+
XCTAssertNil(error, @"Expected no error, but got: %@", error.userInfo);
270+
XCTAssert(result.count > 0, @"Expected results, but got none.");
271+
[expectation fulfill];
272+
}];
273+
[self waitForRequest];
274+
}
275+
276+
- (void)testFetchAssetsByInvalidFieldName06 {
277+
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Asset By invalid field name"];
278+
AssetLibrary *assets = [csStack assetLibrary];
279+
[assets where:@"invalid_field" equalTo:@"value"]; // Invalid field name
280+
[assets fetchAll:^(ResponseType type, NSArray *result, NSError *error) {
281+
XCTAssert(type == NETWORK, @"Pass");
282+
XCTAssertNil(error, @"Expected no error, but got: %@", error.userInfo);
283+
XCTAssertEqual(result.count, 0, @"Expected no results.");
284+
[expectation fulfill];
285+
}];
286+
[self waitForRequest];
287+
}
206288

207289
- (void)testGetHeader {
208290
XCTestExpectation *expectation = [self expectationWithDescription:@"Fetch Set Header"];

0 commit comments

Comments
 (0)