@@ -119,6 +119,61 @@ - (void)tearDown {
119119#pragma mark Test Case - Header
120120
121121
122+ - (void )testStackHeadersEarlyAccess {
123+ XCTestExpectation *expectation = [self expectationWithDescription: @" EarlyAccessHeadersPassed" ];
124+ config = [[Config alloc ] init ];
125+ config.setEarlyAccess = @[@" Taxonomy" , @" Teams" , @" Terms" , @" LivePreview" ];
126+ csStack = [Contentstack stackWithAPIKey: @" apikey" accessToken: @" delivery_token" environmentName: @" environment" config: config];
127+ // Check the headers in the stack
128+ NSDictionary *headers = [csStack getHeaders ];
129+ // Check if the early access headers are set correctly
130+ NSString *expectedHeaderValue = @" Taxonomy,Teams,Terms,LivePreview" ;
131+ NSString *earlyAccessHeader = headers[@" x-header-ea" ];
132+
133+ XCTAssertNotNil (earlyAccessHeader, @" Early access header should be present" );
134+ XCTAssertEqualObjects (earlyAccessHeader, expectedHeaderValue, @" Early access header should match the expected value" );
135+
136+ // Fulfill the expectation to mark the test as completed
137+ [expectation fulfill ];
138+
139+ // Wait for the request to complete
140+ [self waitForExpectationsWithTimeout: kRequestTimeOutInSeconds handler: ^(NSError *error) {
141+ if (error) {
142+ XCTFail (@" Test timed out: %@ " , error.localizedDescription );
143+ }
144+ }];
145+ }
146+
147+ - (void )testNoEarlyAccessHeaders {
148+ XCTestExpectation *expectation = [self expectationWithDescription: @" NoEarlyAccessHeaders" ];
149+ config = [[Config alloc ] init ];
150+ csStack = [Contentstack stackWithAPIKey: @" apikey" accessToken: @" delivery_token" environmentName: @" environment" config: config];
151+
152+ NSDictionary *headers = [csStack getHeaders ];
153+ NSString *earlyAccessHeader = headers[@" x-header-ea" ];
154+ XCTAssertNil (earlyAccessHeader, @" Early access header should not be present when no early access features are set" );
155+
156+ [expectation fulfill ];
157+ [self waitForExpectationsWithTimeout: kRequestTimeOutInSeconds handler: nil ];
158+ }
159+
160+ - (void )testSingleEarlyAccessHeader {
161+ XCTestExpectation *expectation = [self expectationWithDescription: @" SingleEarlyAccessHeader" ];
162+ config = [[Config alloc ] init ];
163+ config.setEarlyAccess = @[@" LivePreview" ];
164+ csStack = [Contentstack stackWithAPIKey: @" apikey" accessToken: @" delivery_token" environmentName: @" environment" config: config];
165+
166+ NSDictionary *headers = [csStack getHeaders ];
167+ NSString *expectedHeaderValue = @" LivePreview" ;
168+ NSString *earlyAccessHeader = headers[@" x-header-ea" ];
169+ XCTAssertNotNil (earlyAccessHeader, @" Early access header should be present" );
170+ XCTAssertEqualObjects (earlyAccessHeader, expectedHeaderValue, @" Single early access header should match the expected value" );
171+
172+ [expectation fulfill ];
173+ [self waitForExpectationsWithTimeout: kRequestTimeOutInSeconds handler: nil ];
174+ }
175+
176+
122177- (void )test01FetchSourceEntries {
123178 XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch All Entries" ];
124179
@@ -203,6 +258,88 @@ - (void)test04FetchAssets {
203258 [self waitForRequest ];
204259}
205260
261+ - (void )testFetchAssetByQuery01 {
262+ XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Asset By where method" ];
263+ AssetLibrary* assets = [csStack assetLibrary ];
264+ [assets where: @" title" equalTo: @" image1" ];
265+ [assets fetchAll: ^(ResponseType type, NSArray *result, NSError *error) {
266+ if (error) {
267+ XCTFail (@" ~ ERR: %@ , Message = %@ " , error.userInfo , error.description );
268+ } else {
269+ XCTAssert (type == NETWORK, @" Pass" );
270+ XCTAssertNil (error, @" Expected no error, but got: %@ " , error.userInfo );
271+ XCTAssert (result.count > 0 , @" Expected results, but got none." );
272+ }
273+ [expectation fulfill ];
274+ }];
275+ [self waitForRequest ];
276+ }
277+
278+ - (void )testFetchAssetsByValidFileSize02 {
279+ XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Asset By valid file size" ];
280+ AssetLibrary *assets = [csStack assetLibrary ];
281+ [assets where: @" file_size" equalTo: @(53986 )]; // Valid file size
282+ [assets fetchAll: ^(ResponseType type, NSArray *result, NSError *error) {
283+ XCTAssert (type == NETWORK, @" Pass" );
284+ XCTAssertNil (error, @" Expected no error, but got: %@ " , error.userInfo );
285+ XCTAssert (result.count > 0 , @" Expected results, but got none." );
286+ [expectation fulfill ];
287+ }];
288+ [self waitForRequest ];
289+ }
290+
291+ - (void )testFetchAssetsByNonExistentFileSize03 {
292+ XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Asset By non-existent file size" ];
293+ AssetLibrary *assets = [csStack assetLibrary ];
294+ [assets where: @" file_size" equalTo: @(9999999 )]; // Non-existent file size
295+ [assets fetchAll: ^(ResponseType type, NSArray *result, NSError *error) {
296+ XCTAssert (type == NETWORK, @" Pass" );
297+ XCTAssertNil (error, @" Expected no error, but got: %@ " , error.userInfo );
298+ XCTAssertEqual (result.count , 0 , @" Expected no results, but got some." );
299+ [expectation fulfill ];
300+ }];
301+ [self waitForRequest ];
302+ }
303+
304+ - (void )testFetchAssetsByNonExistentTitle04 {
305+ XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Asset By non-existent title" ];
306+ AssetLibrary *assets = [csStack assetLibrary ];
307+ [assets where: @" title" equalTo: @" non-existent-title.png" ]; // Non-existent title
308+ [assets fetchAll: ^(ResponseType type, NSArray *result, NSError *error) {
309+ XCTAssert (type == NETWORK, @" Pass" );
310+ XCTAssertNil (error, @" Expected no error, but got: %@ " , error.userInfo );
311+ XCTAssertEqual (result.count , 0 , @" Expected no results, but got some." );
312+ [expectation fulfill ];
313+ }];
314+ [self waitForRequest ];
315+ }
316+
317+ - (void )testFetchAssetsByMultipleConditions05 {
318+ XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Asset By multiple conditions" ];
319+ AssetLibrary *assets = [csStack assetLibrary ];
320+ [assets where: @" file_size" equalTo: @(6884 )]; // Valid file size
321+ [assets where: @" title" equalTo: @" image4" ]; // Valid title
322+ [assets fetchAll: ^(ResponseType type, NSArray *result, NSError *error) {
323+ XCTAssert (type == NETWORK, @" Pass" );
324+ XCTAssertNil (error, @" Expected no error, but got: %@ " , error.userInfo );
325+ XCTAssert (result.count > 0 , @" Expected results, but got none." );
326+ [expectation fulfill ];
327+ }];
328+ [self waitForRequest ];
329+ }
330+
331+ - (void )testFetchAssetsByInvalidFieldName06 {
332+ XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Asset By invalid field name" ];
333+ AssetLibrary *assets = [csStack assetLibrary ];
334+ [assets where: @" invalid_field" equalTo: @" value" ]; // Invalid field name
335+ [assets fetchAll: ^(ResponseType type, NSArray *result, NSError *error) {
336+ XCTAssert (type == NETWORK, @" Pass" );
337+ XCTAssertNil (error, @" Expected no error, but got: %@ " , error.userInfo );
338+ XCTAssertEqual (result.count , 0 , @" Expected no results." );
339+ [expectation fulfill ];
340+ }];
341+ [self waitForRequest ];
342+ }
206343
207344- (void )testGetHeader {
208345 XCTestExpectation *expectation = [self expectationWithDescription: @" Fetch Set Header" ];
0 commit comments