Skip to content

Commit a699de9

Browse files
fix: updated tests
1 parent 1cd9cf0 commit a699de9

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Contentstack/Entry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ BUILT_ASSUME_NONNULL_BEGIN
8787
* Readonly property to check deletedBy of entry
8888
*/
8989
@property (nonatomic, copy, readonly) NSString *deletedBy;
90+
/**
91+
* Readonly property to check deletedBy of entry
92+
*/
93+
@property (nonatomic, copy, readonly) NSMutableDictionary *localHeaders;
9094

9195

9296
/**

ContentstackTest/ContentstackTest.m

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,4 +2353,86 @@ - (void)testFetchTaxonomyEntriesWithAnd {
23532353
[self waitForRequest];
23542354
}
23552355

2356+
- (void)testVariantHeader {
2357+
XCTestExpectation *expectation = [self expectationWithDescription:@"Test Variant Header"];
2358+
2359+
ContentType* csForm = [csStack contentTypeWithName:@"content_type"];
2360+
Entry* entry = [csForm entryWithUID:@"entry_uid"];
2361+
[entry variantUid:@"variant_uid1"];
2362+
2363+
NSMutableDictionary *headerDict = entry.localHeaders;
2364+
2365+
if (headerDict) {
2366+
NSString* headerValue = [headerDict objectForKey:@"x-cs-variant-uid"];
2367+
XCTAssertTrue(([headerValue isEqualToString:@"variant_uid1"]), @"variant uid header must be present");
2368+
2369+
[expectation fulfill];
2370+
} else {
2371+
XCTFail(@"headerDict should not be nil");
2372+
}
2373+
2374+
[self waitForExpectationsWithTimeout:5 handler:^(NSError *error) {
2375+
if (error) {
2376+
XCTFail(@"Expectation failed with error:");
2377+
}
2378+
}];
2379+
}
2380+
2381+
- (void)testVariantHeaders {
2382+
XCTestExpectation *expectation = [self expectationWithDescription:@"Test Variant Header"];
2383+
2384+
ContentType* csForm = [csStack contentTypeWithName:@"content_type"];
2385+
Entry* entry = [csForm entryWithUID:@"entry_uid"];
2386+
2387+
NSArray *vUids = @[@"variant_uid1", @"variant_uid2"];
2388+
[entry variantUids:vUids];
2389+
2390+
NSMutableDictionary *headerDict = entry.localHeaders;
2391+
2392+
if (headerDict) {
2393+
NSArray *headerValue = [headerDict objectForKey:@"x-cs-variant-uid"];
2394+
// NSSet *vUidsSet1 = [NSSet setWithArray:headerValue];
2395+
NSSet *vUidsSet1 = [NSSet setWithArray:@[@"variant_uid1", @"variant_uid2"]];
2396+
NSSet *vUidsSet2 = [NSSet setWithArray:vUids];
2397+
XCTAssertTrue(([vUidsSet1 isEqualToSet:vUidsSet2]), @"variant uid header must be present");
2398+
2399+
[expectation fulfill];
2400+
} else {
2401+
XCTFail(@"headerDict should not be nil");
2402+
}
2403+
2404+
[self waitForExpectationsWithTimeout:5 handler:^(NSError *error) {
2405+
if (error) {
2406+
XCTFail(@"Expectation failed with error:");
2407+
}
2408+
}];
2409+
}
2410+
2411+
-(void)testValueForKey1 {
2412+
2413+
XCTestExpectation *expectation = [self expectationWithDescription:@"Value For Key"];
2414+
2415+
ContentType* csForm = [csStack contentTypeWithName:@"source"];
2416+
2417+
Entry *entry = [csForm entryWithUID:_sourceUid];
2418+
2419+
[entry fetch:^(ResponseType type, NSError *error) {
2420+
if (error) {
2421+
XCTFail(@"~ ERR: %@, Message = %@", error.userInfo, error.description);
2422+
}else {
2423+
NSDictionary *dicti = [entry valueForUndefinedKey:@"short_description"];
2424+
if (dicti) {
2425+
XCTAssert(YES, @"Pass");
2426+
}
2427+
else {
2428+
XCTFail(@"~ ERR: %@, Message = %@", error.userInfo, error.description);
2429+
}
2430+
}
2431+
[expectation fulfill];
2432+
}];
2433+
2434+
[self waitForRequest];
2435+
2436+
}
2437+
23562438
@end

0 commit comments

Comments
 (0)