Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 67cb94b

Browse files
authored
Use custom ISO8601 with ms formatting for Activity published (#596)
2 parents b53112a + ab84f68 commit 67cb94b

File tree

5 files changed

+111
-3
lines changed

5 files changed

+111
-3
lines changed

Podfile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ source 'https://cdn.cocoapods.org/'
55
inhibit_all_warnings!
66
use_frameworks!
77

8-
platform :ios, '13.0'
8+
APP_IOS_DEPLOYMENT_TARGET = Gem::Version.new('13.0')
9+
10+
platform :ios, APP_IOS_DEPLOYMENT_TARGET
911

1012
def wordpresskit_pods
1113
pod 'Alamofire', '~> 4.8.0'
@@ -31,3 +33,14 @@ target 'WordPressKitTests' do
3133
pod 'OHHTTPStubs/Swift', '~> 9.0'
3234
pod 'OCMock', '~> 3.4'
3335
end
36+
37+
# Let Pods targets inherit deployment target from the app
38+
post_install do |installer|
39+
installer.pods_project.targets.each do |target|
40+
target.build_configurations.each do |configuration|
41+
ios_deployment_key = 'IPHONEOS_DEPLOYMENT_TARGET'
42+
pod_ios_deployment_target = Gem::Version.new(configuration.build_settings[ios_deployment_key])
43+
configuration.build_settings.delete(ios_deployment_key) if pod_ios_deployment_target <= APP_IOS_DEPLOYMENT_TARGET
44+
end
45+
end
46+
end

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ SPEC CHECKSUMS:
5050
WordPressShared: 04403b43f821c4ed2b84a2112ef9f64f1e7cdceb
5151
wpxmlrpc: 68db063041e85d186db21f674adf08d9c70627fd
5252

53-
PODFILE CHECKSUM: 5e4ba02626e43d8ae1cdc02077e9086e8861cd77
53+
PODFILE CHECKSUM: 7998039b722f0fe77c684f509f0478349cf5fb9b
5454

5555
COCOAPODS: 1.11.3

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
3F3195AD266FF94B00397EE7 /* ZendeskMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F3195AC266FF94B00397EE7 /* ZendeskMetadata.swift */; };
4949
3F3C9E9C289A3E31009A1357 /* TestCollector+Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F3C9E9B289A3E31009A1357 /* TestCollector+Constants.swift */; };
5050
3F758FD324F6C68200BBA2FC /* AnnouncementServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F758FD224F6C68200BBA2FC /* AnnouncementServiceRemote.swift */; };
51+
3F8308A729EE683500354497 /* ActivityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F8308A629EE683500354497 /* ActivityTests.swift */; };
5152
3FB8642C2888089F003A86BE /* BuildkiteTestCollector in Frameworks */ = {isa = PBXBuildFile; productRef = 3FB8642B2888089F003A86BE /* BuildkiteTestCollector */; };
5253
40247DFA2120D8E100AE1C3C /* AutomatedTransferService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40247DF92120D8E100AE1C3C /* AutomatedTransferService.swift */; };
5354
40247DFC2120E69600AE1C3C /* AutomatedTransferStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40247DFB2120E69600AE1C3C /* AutomatedTransferStatus.swift */; };
@@ -713,6 +714,7 @@
713714
3F3195AC266FF94B00397EE7 /* ZendeskMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZendeskMetadata.swift; sourceTree = "<group>"; };
714715
3F3C9E9B289A3E31009A1357 /* TestCollector+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TestCollector+Constants.swift"; sourceTree = "<group>"; };
715716
3F758FD224F6C68200BBA2FC /* AnnouncementServiceRemote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementServiceRemote.swift; sourceTree = "<group>"; };
717+
3F8308A629EE683500354497 /* ActivityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityTests.swift; sourceTree = "<group>"; };
716718
3FB8642D288813E9003A86BE /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnitTests.xctestplan; sourceTree = "<group>"; };
717719
40247DF92120D8E100AE1C3C /* AutomatedTransferService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomatedTransferService.swift; sourceTree = "<group>"; };
718720
40247DFB2120E69600AE1C3C /* AutomatedTransferStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomatedTransferStatus.swift; sourceTree = "<group>"; };
@@ -1644,6 +1646,7 @@
16441646
isa = PBXGroup;
16451647
children = (
16461648
826016FF1F9FD60A00533B6C /* ActivityServiceRemoteTests.swift */,
1649+
3F8308A629EE683500354497 /* ActivityTests.swift */,
16471650
);
16481651
name = Activity;
16491652
sourceTree = "<group>";
@@ -3298,6 +3301,7 @@
32983301
FACBDD3825ECB4480026705B /* ReaderPostServiceRemote+RelatedPostsTests.swift in Sources */,
32993302
74585B901F0D51F900E7E667 /* DomainsServiceRemoteRESTTests.swift in Sources */,
33003303
BAFA775624ADAB3C000F0D3A /* MockPluginDirectoryEntryProvider.swift in Sources */,
3304+
3F8308A729EE683500354497 /* ActivityTests.swift in Sources */,
33013305
9AB6D64A218727D60008F274 /* PostServiceRemoteRESTRevisionsTest.swift in Sources */,
33023306
7430C9BD1F192C0F0051B8E6 /* ReaderPostServiceRemoteTests.m in Sources */,
33033307
1DC837C229B9F04F009DCD4B /* RemoteVideoPressVideoTests.swift in Sources */,

WordPressKit/Activity.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public struct Activity: Decodable {
4848
let contentText = content["text"] as? String else {
4949
throw Error.missingContentText
5050
}
51-
guard let published = try container.decodeIfPresent(Date.self, forKey: .published) else {
51+
guard
52+
let publishedString = try container.decodeIfPresent(String.self, forKey: .published),
53+
let published = Date.dateWithISO8601WithMillisecondsString(publishedString) else {
5254
throw Error.missingPublishedDate
5355
}
5456

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
@testable import WordPressKit
2+
import XCTest
3+
4+
class ActivityTests: XCTestCase {
5+
6+
func testActivityDecoding() throws {
7+
let data = try XCTUnwrap(activityLogComment.data(using: .utf8))
8+
// This is part of the test in itself.
9+
// If Activity is not configured as expected to decode the JSON input, JSONDecode will throw.
10+
let activity = try JSONDecoder().decode(Activity.self, from: data)
11+
// Verify custom keys
12+
XCTAssertEqual(activity.activityID, "AWRNRTAUjEqjFGbx8DZj")
13+
XCTAssertFalse(activity.isRewindable)
14+
XCTAssertEqual(activity.rewindID, "1530304735.2771")
15+
}
16+
}
17+
18+
// See https://github.com/wordpress-mobile/WordPress-iOS/blob/16adc688f718136ea57c45d5d26c5c13de9d2b9f/WordPress/WordPressTest/Test%20Data/activity-log-comment.json
19+
private let activityLogComment: String = """
20+
{
21+
"summary": "Comment approved",
22+
"content": {
23+
"text": "Comment by aaaaaaaaaa on Hola Lima! 🇵🇪: Great post! True talent!",
24+
"ranges": [
25+
{
26+
"url": "https://wordpress.com/comment/137726971/7",
27+
"indices": [
28+
0,
29+
7
30+
],
31+
"site_id": 137726971,
32+
"root_id": 441,
33+
"section": "comment",
34+
"intent": "edit",
35+
"id": 7
36+
},
37+
{
38+
"url": "https://wordpress.com/edit/post/137726971/441",
39+
"indices": [
40+
25,
41+
40
42+
],
43+
"site_id": 137726971,
44+
"section": "post",
45+
"intent": "edit",
46+
"context": "single",
47+
"id": 441
48+
}
49+
]
50+
},
51+
"name": "comment__approved",
52+
"actor": {
53+
"type": "Person",
54+
"name": "etoledom",
55+
"external_user_id": 0,
56+
"wpcom_user_id": 129935412,
57+
"icon": {
58+
"type": "Image",
59+
"url": "https://secure.gravatar.com/avatar/8e06b8f61330e7bc0e5eb4e67aa68e0f?s=96&d=identicon&r=g",
60+
"width": 96,
61+
"height": 96
62+
},
63+
"role": "administrator"
64+
},
65+
"type": "Accept",
66+
"published": "2018-06-29T20:38:55.277+00:00",
67+
"generator": {
68+
"jetpack_version": 0,
69+
"blog_id": 137726971
70+
},
71+
"is_rewindable": false,
72+
"rewind_id": "1530304735.2771",
73+
"gridicon": "comment",
74+
"status": null,
75+
"activity_id": "AWRNRTAUjEqjFGbx8DZj",
76+
"object": {
77+
"type": "Comment",
78+
"object_id": 7
79+
},
80+
"target": {
81+
"type": "Article",
82+
"name": "Hola Lima! 🇵🇪",
83+
"post_id": 229,
84+
"post_type": "post",
85+
"post_status": "publish"
86+
},
87+
"is_discarded": false
88+
}
89+
"""

0 commit comments

Comments
 (0)