Skip to content

Commit

Permalink
Rename CTJsonTemplateProducer init
Browse files Browse the repository at this point in the history
  • Loading branch information
nzagorchev committed Oct 2, 2024
1 parent e390c39 commit f072912
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
Invalid definitions throw `NSException` with name `CleverTapCustomTemplateException` when ``defineTemplates:`` is called.
@param jsonTemplateDefinitions A string with a json definition of templates in the following format:
@param jsonTemplatesDefinition A string with a json definition of templates in the following format:
```
{
"TemplateName": {
Expand Down Expand Up @@ -72,18 +72,18 @@ NS_ASSUME_NONNULL_BEGIN
@param functionPresenter A presenter for all functions in the json definitions. Required if there
is at least one template with type "function".
*/
- (nonnull instancetype)initWithJsonTemplateDefinitions:(nonnull NSString *)jsonTemplateDefinitions
- (nonnull instancetype)initWithJson:(nonnull NSString *)jsonTemplatesDefinition
templatePresenter:(nonnull id<CTTemplatePresenter>)templatePresenter
functionPresenter:(nonnull id<CTTemplatePresenter>)functionPresenter;


/*!
Creates ``CTCustomTemplate``s based on the `jsonTemplateDefinitions` this ``CTJsonTemplateProducer`` was initialized with.
Creates ``CTCustomTemplate``s based on the `jsonTemplatesDefinition` this ``CTJsonTemplateProducer`` was initialized with.
@param instanceConfig The config of the CleverTap instance.
@return A set of the custom templates created.
This method throws an `NSException` with name `CleverTapCustomTemplateException` if an invalid JSON format or values occur while parsing `jsonTemplateDefinitions`.
This method throws an `NSException` with name `CleverTapCustomTemplateException` if an invalid JSON format or values occur while parsing `jsonTemplatesDefinition`.
See the exception reason for details.
*/
- (NSSet<CTCustomTemplate *> * _Nonnull)defineTemplates:(CleverTapInstanceConfig * _Nonnull)instanceConfig;
Expand Down
10 changes: 5 additions & 5 deletions CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@

@interface CTJsonTemplateProducer ()

@property (nonatomic, strong) NSString *jsonTemplateDefinitions;
@property (nonatomic, strong) NSString *jsonTemplatesDefinition;
@property (nonatomic, strong) id<CTTemplatePresenter> templatePresenter;
@property (nonatomic, strong) id<CTTemplatePresenter> functionPresenter;

@end

@implementation CTJsonTemplateProducer

- (nonnull instancetype)initWithJsonTemplateDefinitions:(nonnull NSString *)jsonTemplateDefinitions
- (nonnull instancetype)initWithJson:(nonnull NSString *)jsonTemplatesDefinition
templatePresenter:(nonnull id<CTTemplatePresenter>)templatePresenter
functionPresenter:(nonnull id<CTTemplatePresenter>)functionPresenter {
if (self = [super init]) {
self.jsonTemplateDefinitions = jsonTemplateDefinitions;
self.jsonTemplatesDefinition = jsonTemplatesDefinition;
self.templatePresenter = templatePresenter;
self.functionPresenter = functionPresenter;
}
return self;
}

- (NSSet<CTCustomTemplate *> * _Nonnull)defineTemplates:(CleverTapInstanceConfig * _Nonnull)instanceConfig {
if (!self.jsonTemplateDefinitions || [self.jsonTemplateDefinitions length] == 0) {
if (!self.jsonTemplatesDefinition || [self.jsonTemplatesDefinition length] == 0) {
@throw([NSException
exceptionWithName:CLTAP_CUSTOM_TEMPLATE_EXCEPTION
reason:@"CleverTap: JSON template definitions cannot be nil or empty."
userInfo:nil]);
}

NSData *jsonData = [self.jsonTemplateDefinitions dataUsingEncoding:NSUTF8StringEncoding];
NSData *jsonData = [self.jsonTemplatesDefinition dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *jsonDefinitions = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)setUp {
- (void)testJsonDefinitions {
NSString *json = [NSString stringWithFormat:@"{%@, %@}", self.template1, self.function1];

CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:json templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJson:json templatePresenter:self.presenter functionPresenter:self.presenter];

NSSet *templates = [producer defineTemplates:self.config];
XCTAssertEqual(2, templates.count);
Expand Down Expand Up @@ -79,7 +79,7 @@ - (void)testNoArguments {
" }"
" }"
"}";
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:noArgumentsJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJson:noArgumentsJson templatePresenter:self.presenter functionPresenter:self.presenter];

NSSet *templates = [producer defineTemplates:self.config];
CTCustomTemplate *template1 = [self templateWithName:@"template-1" inSet:templates];
Expand All @@ -90,26 +90,26 @@ - (void)testNoArguments {

- (void)testNoJson {
NSString *nilJson = nil;
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:nilJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJson:nilJson templatePresenter:self.presenter functionPresenter:self.presenter];

XCTAssertThrowsSpecificNamed([producer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);
}

- (void)testPresenterNotProvided {
#pragma clang diagnostic ignored "-Wnonnull"
NSString *templateJson = [NSString stringWithFormat:@"{%@}", self.template1];
CTJsonTemplateProducer *templateJsonProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:templateJson templatePresenter:nil functionPresenter:self.presenter];
CTJsonTemplateProducer *templateJsonProducer = [[CTJsonTemplateProducer alloc] initWithJson:templateJson templatePresenter:nil functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([templateJsonProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

NSString *functionJson = [NSString stringWithFormat:@"{%@}", self.function1];
CTJsonTemplateProducer *functionJsonProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:functionJson templatePresenter:self.presenter functionPresenter:nil];
CTJsonTemplateProducer *functionJsonProducer = [[CTJsonTemplateProducer alloc] initWithJson:functionJson templatePresenter:self.presenter functionPresenter:nil];
XCTAssertThrowsSpecificNamed([functionJsonProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);
#pragma clang diagnostic pop
}

- (void)testInvalidJson {
NSString *invalidJson = @"{[]}";
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJson:invalidJson templatePresenter:self.presenter functionPresenter:self.presenter];

XCTAssertThrowsSpecificNamed([producer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);
}
Expand All @@ -128,7 +128,7 @@ - (void)testEmptyObjectArgument {
" }"
"}" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:json templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJson:json templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([producer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);
}

Expand All @@ -146,7 +146,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidTemplateTypeProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidTemplateTypeJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidTemplateTypeProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidTemplateTypeJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidTemplateTypeProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

// Invalid Argument Type JSON
Expand All @@ -162,7 +162,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidArgumentTypeProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidArgumentTypeJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidArgumentTypeProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidArgumentTypeJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidArgumentTypeProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

// Invalid File Value JSON
Expand All @@ -178,7 +178,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidFileValueJsonProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidFileValueJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidFileValueJsonProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidFileValueJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidFileValueJsonProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

// Invalid Function File Value JSON
Expand All @@ -194,7 +194,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidFunctionFileValueJsonProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidFunctionFileValueJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidFunctionFileValueJsonProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidFunctionFileValueJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidFunctionFileValueJsonProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

// Invalid Action Value JSON
Expand All @@ -210,7 +210,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidActionValueJsonProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidActionValueJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidActionValueJsonProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidActionValueJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidActionValueJsonProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

// Invalid Function Action JSON
Expand All @@ -226,7 +226,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidFunctionActionProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidFunctionActionJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidFunctionActionProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidFunctionActionJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidFunctionActionProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);

// Invalid Nested File JSON
Expand All @@ -246,7 +246,7 @@ - (void)testInvalidValues {
"}"
"}";

CTJsonTemplateProducer *invalidNestedFileJsonProducer = [[CTJsonTemplateProducer alloc] initWithJsonTemplateDefinitions:invalidNestedFileJson templatePresenter:self.presenter functionPresenter:self.presenter];
CTJsonTemplateProducer *invalidNestedFileJsonProducer = [[CTJsonTemplateProducer alloc] initWithJson:invalidNestedFileJson templatePresenter:self.presenter functionPresenter:self.presenter];
XCTAssertThrowsSpecificNamed([invalidNestedFileJsonProducer defineTemplates:self.config], NSException, CLTAP_CUSTOM_TEMPLATE_EXCEPTION);
}

Expand Down

0 comments on commit f072912

Please sign in to comment.