Skip to content

Commit f5f49d7

Browse files
authored
Create unit test for LPRequest (#217)
1 parent 1e984d6 commit f5f49d7

File tree

4 files changed

+58
-85
lines changed

4 files changed

+58
-85
lines changed

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
9CB691E11F1601BA002D83D8 /* LPEventCallbackManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CB691E01F1601BA002D83D8 /* LPEventCallbackManagerTest.m */; };
9696
9CD04D941F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */ = {isa = PBXBuildFile; fileRef = 9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */; };
9797
9CD04D951F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */ = {isa = PBXBuildFile; fileRef = 9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */; };
98+
A84527FD215C3035001FA20D /* LPRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A84527FC215C3035001FA20D /* LPRequestTest.m */; };
9899
A8EEA1AB20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
99100
A8EEA1AC20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
100101
B5CCCA2D1D74B64D005ADEE1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B5CCCA2C1D74B64D005ADEE1 /* main.m */; };
@@ -200,6 +201,7 @@
200201
9CB691E01F1601BA002D83D8 /* LPEventCallbackManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPEventCallbackManagerTest.m; sourceTree = "<group>"; };
201202
9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = variables_with_newsfeed_response.json; sourceTree = "<group>"; };
202203
A54ACCFCB36AE8C874708A7F /* libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
204+
A84527FC215C3035001FA20D /* LPRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestTest.m; sourceTree = "<group>"; };
203205
A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = start_with_variant_debug_info_response.json; sourceTree = "<group>"; };
204206
B5CCCA291D74B64D005ADEE1 /* Leanplum-tvOS-SDK_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Leanplum-tvOS-SDK_Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
205207
B5CCCA2C1D74B64D005ADEE1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -253,6 +255,7 @@
253255
isa = PBXGroup;
254256
children = (
255257
07E5C86B1F052B7800A4B092 /* LPActionManagerTest.m */,
258+
A84527FC215C3035001FA20D /* LPRequestTest.m */,
256259
07E5C86C1F052B7800A4B092 /* LPAppIconManagerTest.m */,
257260
07E5C86D1F052B7800A4B092 /* LPEventDataManagerTest.m */,
258261
07E5C86E1F052B7800A4B092 /* ExceptionsTest.m */,
@@ -826,6 +829,7 @@
826829
07E5C8B61F052B7800A4B092 /* LeanplumTest.m in Sources */,
827830
07E5C8AD1F052B7800A4B092 /* LPEventDataManagerTest.m in Sources */,
828831
07E5C8AE1F052B7800A4B092 /* ExceptionsTest.m in Sources */,
832+
A84527FD215C3035001FA20D /* LPRequestTest.m in Sources */,
829833
07E5C8AC1F052B7800A4B092 /* LPAppIconManagerTest.m in Sources */,
830834
07E5C8BA1F052B7800A4B092 /* NewsfeedTest.m in Sources */,
831835
07E5C8AB1F052B7800A4B092 /* LPActionManagerTest.m in Sources */,
@@ -979,7 +983,7 @@
979983
GCC_PRECOMPILE_PREFIX_HEADER = YES;
980984
GCC_PREFIX_HEADER = "Leanplum-SDK/Leanplum-SDK-Prefix.pch";
981985
INFOPLIST_FILE = "Leanplum-SDK/Leanplum-SDK-Info.plist";
982-
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
986+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
983987
MODULE_NAME = ExampleApp;
984988
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
985989
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -997,7 +1001,7 @@
9971001
GCC_PRECOMPILE_PREFIX_HEADER = YES;
9981002
GCC_PREFIX_HEADER = "Leanplum-SDK/Leanplum-SDK-Prefix.pch";
9991003
INFOPLIST_FILE = "Leanplum-SDK/Leanplum-SDK-Info.plist";
1000-
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
1004+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
10011005
MODULE_NAME = ExampleApp;
10021006
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
10031007
PRODUCT_NAME = "$(TARGET_NAME)";
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// LPRequestTest.m
3+
// Leanplum-SDK_Tests
4+
//
5+
// Created by Mayank Sanganeria on 9/26/18.
6+
// Copyright © 2018 Leanplum. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import <Leanplum/LPRequest.h>
11+
12+
@interface LPRequest(UnitTest)
13+
14+
@property (nonatomic, strong) NSString *httpMethod;
15+
16+
@end
17+
18+
@interface LPRequestTest : XCTestCase
19+
20+
@end
21+
22+
@implementation LPRequestTest
23+
24+
- (void)setUp {
25+
// Put setup code here. This method is called before the invocation of each test method in the class.
26+
}
27+
28+
- (void)tearDown {
29+
// Put teardown code here. This method is called after the invocation of each test method in the class.
30+
}
31+
32+
- (void)testPostShouldCreatePostRequest {
33+
NSString *apiMethod = @"apiMethod";
34+
NSDictionary *params = @{@"key": @"value"};
35+
LPRequest *postRequest = [LPRequest post:apiMethod params:params];
36+
37+
XCTAssertEqual(postRequest.apiMethod, apiMethod);
38+
XCTAssertEqual(postRequest.params, params);
39+
XCTAssertTrue([postRequest.httpMethod isEqualToString:@"POST"]);
40+
}
41+
42+
- (void)testGetShouldCreateGetRequest {
43+
NSString *apiMethod = @"apiMethod";
44+
NSDictionary *params = @{@"key": @"value"};
45+
LPRequest *getRequest = [LPRequest get:apiMethod params:params];
46+
47+
XCTAssertEqual(getRequest.apiMethod, apiMethod);
48+
XCTAssertEqual(getRequest.params, params);
49+
XCTAssertTrue([getRequest.httpMethod isEqualToString:@"GET"]);
50+
}
51+
52+
@end

Leanplum-SDK/Classes/Managers/Networking/LPRequest.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ @interface LPRequest()
3131

3232
@end
3333

34-
3534
@implementation LPRequest
3635

3736
- (id)initWithHttpMethod:(NSString *)httpMethod

build.sh

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -113,91 +113,9 @@ main() {
113113
build_ios_dylib
114114
build_tvos_dylib
115115

116-
# Build Static Framework
117-
RELEASE_DIR="$RELEASE_DIR_BASE/static"
118-
mkdir -p "$RELEASE_DIR"
119-
120-
export LP_STATIC=1
121-
cd "$SDK_DIR/Example/"
122-
pod install
123-
cd "$SDK_DIR/Example/Pods"
124-
build_ios
125-
126116
echo "${GREEN} Done.${NORMAL}"
127117
}
128118

129-
#######################################
130-
# Builds the iOS Target.
131-
# Globals:
132-
# None
133-
# Arguments:
134-
# None
135-
# Returns:
136-
# None
137-
#######################################
138-
build_ios() {
139-
echo "Starting build for Leanplum-SDK (iOS)"
140-
141-
run "Building Leanplum-SDK-iOS static (device/armv7) target ..." \
142-
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source" -sdk "${DEVICE_SDK}" \
143-
"$ACTION" ARCHS='armv7' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARMV7_DIR}" \
144-
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode" \
145-
GCC_PREPROCESSOR_DEFINITIONS="PACKAGE_IDENTIFIER=${LEANPLUM_PACKAGE_IDENTIFIER}"
146-
run "Building Leanplum-SDK-iOS static (device/armv7s) target ..." \
147-
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source" -sdk "${DEVICE_SDK}" \
148-
"$ACTION" ARCHS='armv7s' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARMV7S_DIR}" \
149-
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode" \
150-
GCC_PREPROCESSOR_DEFINITIONS="PACKAGE_IDENTIFIER=${LEANPLUM_PACKAGE_IDENTIFIER}"
151-
run "Building Leanplum-SDK-iOS static (device/arm64) target ..." \
152-
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source" -sdk "${DEVICE_SDK}" \
153-
"$ACTION" ARCHS='arm64' RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}${ARM64_DIR}" \
154-
BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode" \
155-
GCC_PREPROCESSOR_DEFINITIONS="PACKAGE_IDENTIFIER=${LEANPLUM_PACKAGE_IDENTIFIER}"
156-
run "Building Leanplum-SDK-iOS static (simulator/i386) target ..." \
157-
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source" -sdk "${SIM_SDK}" \
158-
"$ACTION" ARCHS='i386' VALID_ARCHS='i386' RUN_CLANG_STATIC_ANALYZER=NO \
159-
BUILD_DIR="${BUILD_DIR}${X86_DIR}" BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode" \
160-
GCC_PREPROCESSOR_DEFINITIONS="PACKAGE_IDENTIFIER=${LEANPLUM_PACKAGE_IDENTIFIER}"
161-
run "Building Leanplum-SDK-iOS static (simulator/x86_64) target ..." \
162-
xcodebuild -configuration "${CONFIGURATION}" -target "Leanplum-iOS-SDK-source" -sdk "${SIM_SDK}" \
163-
"$ACTION" ARCHS='x86_64' VALID_ARCHS='x86_64' RUN_CLANG_STATIC_ANALYZER=NO \
164-
BUILD_DIR="${BUILD_DIR}${X8664_DIR}" BUILD_ROOT="${BUILD_ROOT}" OTHER_CFLAGS="-fembed-bitcode" \
165-
GCC_PREPROCESSOR_DEFINITIONS="PACKAGE_IDENTIFIER=${LEANPLUM_PACKAGE_IDENTIFIER}"
166-
167-
mkdir "${RELEASE_DIR}/Leanplum.framework/"
168-
run "Combining builds to universal fat library ..." \
169-
lipo -create -output "${RELEASE_DIR}/Leanplum.framework/Leanplum" \
170-
"${CURRENTCONFIG_ARMV7_DEVICE_DIR}/Leanplum-iOS-SDK-source/libLeanplum-iOS-SDK-source.a" \
171-
"${CURRENTCONFIG_ARMV7S_DEVICE_DIR}/Leanplum-iOS-SDK-source/libLeanplum-iOS-SDK-source.a" \
172-
"${CURRENTCONFIG_ARM64_DEVICE_DIR}/Leanplum-iOS-SDK-source/libLeanplum-iOS-SDK-source.a" \
173-
"${CURRENTCONFIG_X86_DEVICE_DIR}/Leanplum-iOS-SDK-source/libLeanplum-iOS-SDK-source.a" \
174-
"${CURRENTCONFIG_X8664_SIMULATOR_DIR}/Leanplum-iOS-SDK-source/libLeanplum-iOS-SDK-source.a"
175-
176-
# Create .framework package.
177-
mkdir -p "${RELEASE_DIR}/Leanplum.framework"
178-
mkdir -p "${RELEASE_DIR}/Leanplum.framework/Headers"
179-
mkdir -p "${RELEASE_DIR}/Leanplum.framework/Modules"
180-
181-
# Add modulemap.
182-
cat <<EOF > "${RELEASE_DIR}/Leanplum.framework/Modules/module.modulemap"
183-
framework module Leanplum {
184-
umbrella header "Leanplum.h"
185-
export *
186-
module *
187-
{ export * }
188-
}
189-
EOF
190-
191-
# Copy headers.
192-
cp "$SDK_DIR/Leanplum-SDK/Classes/Leanplum.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
193-
cp "$SDK_DIR/Leanplum-SDK/Classes/LPInbox.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
194-
cp "$SDK_DIR/Leanplum-SDK/Classes/LPActionArg.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
195-
cp "$SDK_DIR/Leanplum-SDK/Classes/LPActionContext.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
196-
cp "$SDK_DIR/Leanplum-SDK/Classes/LeanplumCompatibility.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
197-
cp "$SDK_DIR/Leanplum-SDK/Classes/LPVar.h" "${RELEASE_DIR}/Leanplum.framework/Headers"
198-
199-
printf "%s\n" "Successfully built Leanplum-SDK (iOS) Framework."
200-
}
201119

202120
#######################################
203121
# Builds the iOS dynamic library Target.

0 commit comments

Comments
 (0)