FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
contentstack-ios/ContentstackTest/SyncTest.m at development · contentstack/contentstack-ios · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
contentstack
/
contentstack-ios
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
3
Code
Issues
0
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
contentstack-ios
/
ContentstackTest
/
SyncTest.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
216 lines (187 loc) · 8.63 KB
Breadcrumbs
contentstack-ios
/
ContentstackTest
/
SyncTest.m
Copy path
File metadata and controls
216 lines (187 loc) · 8.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//
//
SyncTest.m
//
ContentstackTest
//
//
Created by Uttam Ukkoji on 04/07/18.
//
Copyright © 2018 Contentstack. All rights reserved.
//
#
import
<
Contentstack/Contentstack.h
>
#
import
<
XCTest/XCTest.h
>
static
NSInteger
kRequestTimeOutInSeconds
=
60
;
static
NSString
*syncToken =
@"
"
;
@interface
SyncTest
:
XCTestCase
{
Stack *csStack;
Config *config;
CGFloat count;
NSDateFormatter
*formatter;
}
@end
@implementation
SyncTest
- (
void
)
setUp
{
[
super
setUp
];
config = [[Config
alloc
]
init
];
NSString
*path = [[
NSBundle
bundleForClass:
self
.class]
pathForResource:
@"
config
"
ofType:
@"
json
"
];
NSData
*data = [
NSData
dataWithContentsOfFile:
path];
NSDictionary
*dict = [
NSJSONSerialization
JSONObjectWithData:
data
options:
kNilOptions
error:
nil
];
config.
host
= dict[
@"
host
"
];
csStack = [Contentstack
stackWithAPIKey:
dict[
@"
api_key
"
]
accessToken:
dict[
@"
delivery_token
"
]
environmentName:
dict[
@"
environment
"
]
config:
config];
formatter = [[
NSDateFormatter
alloc
]
init
];
formatter.
dateFormat
=
@"
yyyy-MM-dd'T'HH:mm:SSSSSZ
"
;
}
- (
void
)
waitForRequest
{
[
self
waitForExpectationsWithTimeout:
kRequestTimeOutInSeconds
handler:
^(
NSError
*error) {
if
(error) {
XCTFail
(
@"
Could not perform operation (Timed out) ~ ERR:
%@
"
, error.
userInfo
);
}
}];
}
- (
void
)
tearDown
{
//
Put teardown code here. This method is called after the invocation of each test method in the class.
[
super
tearDown
];
}
- (
void
)
testSync
{
count =
0
;
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
Sync
"
];
[csStack
sync:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
count += syncStack.
items
.
count
;
if
(syncStack.
syncToken
!=
nil
) {
syncToken = syncStack.
syncToken
;
XCTAssertEqual
(syncStack.
totalCount
, count);
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
- (
void
)
testSyncToken
{
count =
0
;
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
Sync
"
];
[csStack
syncToken:
syncToken
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
count += syncStack.
items
.
count
;
if
(syncStack.
syncToken
!=
nil
) {
XCTAssertEqual
(syncStack.
totalCount
, syncStack.
totalCount
);
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
- (
void
)
testSyncFromDate
{
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncFromDate
"
];
NSDate
*date = [
NSDate
dateWithTimeIntervalSince1970:
1534617000
];
[csStack
syncFrom:
date
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
event_at
"
]
isKindOfClass:
[
NSString
class
]]) {
NSDate
*daatee = [formatter
dateFromString:
[[item
objectForKey:
@"
event_at
"
]
stringByReplacingOccurrencesOfString:
@"
.
"
withString:
@"
"
]];
XCTAssertLessThanOrEqual
(date.
timeIntervalSince1970
, daatee.
timeIntervalSince1970
);
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
- (
void
)
testSyncPublishType
{
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncPublishType
"
];
[csStack
syncPublishType:
(
ENTRY_DELETED
)
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
type
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[item
objectForKey:
@"
type
"
]
isEqualToString:
@"
entry_deleted
"
]);
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
- (
void
)
testSyncOnlyClass
{
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncOnlyClass
"
];
[csStack
syncOnly:
@"
source
"
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
content_type_uid
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[item
objectForKey:
@"
content_type_uid
"
]
isEqualToString:
@"
source
"
]);
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
} }];
[
self
waitForRequest
];
}
-(
void
)
testSyncOnlyWithLocale
{
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncOnlyWithLocale
"
];
[csStack
syncOnly:
@"
source
"
locale:
@"
en-us
"
from:
nil
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
content_type_uid
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[item
objectForKey:
@"
content_type_uid
"
]
isEqualToString:
@"
source
"
]);
}
if
([[item
objectForKey:
@"
data
"
]
isKindOfClass:
[
NSDictionary
class
]]) {
NSDictionary
*data = [item
objectForKey:
@"
data
"
];
if
([data
valueForKeyPath:
@"
publish_details.locale
"
] !=
nil
&& [[data
objectForKey:
@"
publish_details.locale
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[data
objectForKey:
@"
publish_details.locale
"
]
isEqualToString:
@"
en-us
"
]);
}
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
- (
void
)
testSyncOnlyClassAndDate
{
NSDate
*date = [
NSDate
dateWithTimeIntervalSince1970:
1534617000
];
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncOnlyClassAndDate
"
];
[csStack
syncOnly:
@"
source
"
from:
date
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
content_type_uid
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[item
objectForKey:
@"
content_type_uid
"
]
isEqualToString:
@"
source
"
]);
}
if
([[item
objectForKey:
@"
event_at
"
]
isKindOfClass:
[
NSString
class
]]) {
NSDate
*daatee = [formatter
dateFromString:
[[item
objectForKey:
@"
event_at
"
]
stringByReplacingOccurrencesOfString:
@"
.
"
withString:
@"
"
]];
XCTAssertLessThanOrEqual
(date.
timeIntervalSince1970
, daatee.
timeIntervalSince1970
);
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
} }];
[
self
waitForRequest
];
}
-(
void
)
testSyncLocal
{
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncLocal
"
];
[csStack
syncLocale:
@"
en-us
"
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
data
"
]
isKindOfClass:
[
NSDictionary
class
]]) {
NSDictionary
*data = [item
objectForKey:
@"
data
"
];
if
([data
valueForKeyPath:
@"
publish_details.locale
"
] !=
nil
&& [[data
objectForKey:
@"
publish_details.locale
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[data
objectForKey:
@"
publish_details.locale
"
]
isEqualToString:
@"
en-us
"
]);
}
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
-(
void
)
testSyncLocaleWithDate
{
NSDate
*date = [
NSDate
dateWithTimeIntervalSince1970:
1534617000
];
XCTestExpectation *expectation = [
self
expectationWithDescription:
@"
SyncLocaleWithDate
"
];
[csStack
syncLocale:
@"
en-us
"
from:
date
completion:
^(SyncStack * _Nullable syncStack,
NSError
* _Nullable error) {
for
(
NSDictionary
*item in syncStack.
items
) {
if
([[item
objectForKey:
@"
event_at
"
]
isKindOfClass:
[
NSString
class
]]) {
NSDate
*daatee = [formatter
dateFromString:
[[item
objectForKey:
@"
event_at
"
]
stringByReplacingOccurrencesOfString:
@"
.
"
withString:
@"
"
]];
XCTAssertLessThanOrEqual
(date.
timeIntervalSince1970
, daatee.
timeIntervalSince1970
);
}
if
([[item
objectForKey:
@"
data
"
]
isKindOfClass:
[
NSDictionary
class
]]) {
NSDictionary
*data = [item
objectForKey:
@"
data
"
];
if
([data
objectForKey:
@"
publish_details.locale
"
] !=
nil
&& [[data
objectForKey:
@"
publish_details.locale
"
]
isKindOfClass:
[
NSString
class
]]) {
XCTAssertTrue
([[data
objectForKey:
@"
publish_details.locale
"
]
isEqualToString:
@"
en-us
"
]);
}
}
}
if
(syncStack.
syncToken
!=
nil
) {
[expectation
fulfill
];
}
}];
[
self
waitForRequest
];
}
@end
Back
|
FazBrowse Home
|
New Git URL