From f072912e2445765d69bc1155acd9594d652f1e90 Mon Sep 17 00:00:00 2001 From: Nikola Zagorchev Date: Wed, 2 Oct 2024 23:08:12 +0300 Subject: [PATCH] Rename CTJsonTemplateProducer init --- .../CustomTemplates/CTJsonTemplateProducer.h | 8 +++--- .../CustomTemplates/CTJsonTemplateProducer.m | 10 +++---- .../CTJsonTemplateProducerTest.m | 28 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.h b/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.h index 67933289..1e6aec23 100644 --- a/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.h +++ b/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.h @@ -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": { @@ -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)templatePresenter functionPresenter:(nonnull id)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 * _Nonnull)defineTemplates:(CleverTapInstanceConfig * _Nonnull)instanceConfig; diff --git a/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.m b/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.m index 9de7bb21..d17b9e2c 100644 --- a/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.m +++ b/CleverTapSDK/InApps/CustomTemplates/CTJsonTemplateProducer.m @@ -15,7 +15,7 @@ @interface CTJsonTemplateProducer () -@property (nonatomic, strong) NSString *jsonTemplateDefinitions; +@property (nonatomic, strong) NSString *jsonTemplatesDefinition; @property (nonatomic, strong) id templatePresenter; @property (nonatomic, strong) id functionPresenter; @@ -23,11 +23,11 @@ @interface CTJsonTemplateProducer () @implementation CTJsonTemplateProducer -- (nonnull instancetype)initWithJsonTemplateDefinitions:(nonnull NSString *)jsonTemplateDefinitions +- (nonnull instancetype)initWithJson:(nonnull NSString *)jsonTemplatesDefinition templatePresenter:(nonnull id)templatePresenter functionPresenter:(nonnull id)functionPresenter { if (self = [super init]) { - self.jsonTemplateDefinitions = jsonTemplateDefinitions; + self.jsonTemplatesDefinition = jsonTemplatesDefinition; self.templatePresenter = templatePresenter; self.functionPresenter = functionPresenter; } @@ -35,14 +35,14 @@ - (nonnull instancetype)initWithJsonTemplateDefinitions:(nonnull NSString *)json } - (NSSet * _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]; diff --git a/CleverTapSDKTests/InApps/CustomTemplates/CTJsonTemplateProducerTest.m b/CleverTapSDKTests/InApps/CustomTemplates/CTJsonTemplateProducerTest.m index 9a355672..e9351a5c 100644 --- a/CleverTapSDKTests/InApps/CustomTemplates/CTJsonTemplateProducerTest.m +++ b/CleverTapSDKTests/InApps/CustomTemplates/CTJsonTemplateProducerTest.m @@ -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); @@ -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]; @@ -90,7 +90,7 @@ - (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); } @@ -98,18 +98,18 @@ - (void)testNoJson { - (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); } @@ -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); } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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); }