Skip to content

Commit

Permalink
Winter '19 Identity date format change
Browse files Browse the repository at this point in the history
  • Loading branch information
mike4aday authored Oct 11, 2018
1 parent 516cef5 commit f2aef7e
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Version 7.1.1 (Oct. 11, 2018)
Adapt to Winter '19 date format change in `identity` JSON response. See [release notes](https://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_security_auth_json_value_endpoints.htm).
Resolves issue [issue #91](https://github.com/mike4aday/SwiftlySalesforce/issues/91)

## Version 7.1.0 (Oct. 10, 2018)
Support OpenID Connect 'ID token.' Resolves issue [issue #92](https://github.com/mike4aday/SwiftlySalesforce/issues/92)

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SwiftlySalesforce.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Example/Pods/PromiseKit/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Example/Pods/Target Support Files/PromiseKit/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Example/SwiftlySalesforce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
EA3DA7E220E68F4C00648FE0 /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABD723F1DC0455C00790BCB /* DetailViewController.swift */; };
EA57EBF320D2B7E300374451 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA133DA91F91DC060055DC2F /* TestUtils.swift */; };
EA62C6781F196E7C00D6CF4E /* MockAccountMetadata.json in Resources */ = {isa = PBXBuildFile; fileRef = EA62C6621F196E6600D6CF4E /* MockAccountMetadata.json */; };
EA62C67E1F196E9500D6CF4E /* MockIdentity.json in Resources */ = {isa = PBXBuildFile; fileRef = EA62C6681F196E6600D6CF4E /* MockIdentity.json */; };
EA62C67E1F196E9500D6CF4E /* MockIdentityPreWinter19.json in Resources */ = {isa = PBXBuildFile; fileRef = EA62C6681F196E6600D6CF4E /* MockIdentityPreWinter19.json */; };
EA7BDBD920EFC5890026856B /* Salesforce_QueryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA8A687320D55528007622D7 /* Salesforce_QueryTests.swift */; };
EA7BDBDA20EFD41C0026856B /* AuthorizationStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA774E9B20CC61A50076D71C /* AuthorizationStoreTests.swift */; };
EA7BDBDB20EFD99D0026856B /* Salesforce_SearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA62132120EAD6AC009F1C52 /* Salesforce_SearchTests.swift */; };
EA7BDBDD20EFDA440026856B /* URL_QueryItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7BDBDC20EFDA440026856B /* URL_QueryItemTests.swift */; };
EA7BDBDF20EFDB5D0026856B /* UIResourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7BDBDE20EFDB5D0026856B /* UIResourceTests.swift */; };
EA7BDBE120EFFFDE0026856B /* Salesforce_UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7BDBE020EFFFDE0026856B /* Salesforce_UITests.swift */; };
EA99C045216F05F900FD8976 /* MockIdentityPostWinter19.json in Resources */ = {isa = PBXBuildFile; fileRef = EA99C043216F03E600FD8976 /* MockIdentityPostWinter19.json */; };
EAAAB52E20F0FCB60079B88B /* URLRequest_URLRequestConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAAAB52D20F0FCB60079B88B /* URLRequest_URLRequestConvertibleTests.swift */; };
EAAC9EB920D44F5500F0E16B /* Configuration.json in Resources */ = {isa = PBXBuildFile; fileRef = EAAC9EB820D44F5500F0E16B /* Configuration.json */; };
EAB7EDAD1F8AEC0B00788A20 /* MockLimits.json in Resources */ = {isa = PBXBuildFile; fileRef = EAB7EDAC1F8AEC0B00788A20 /* MockLimits.json */; };
Expand Down Expand Up @@ -79,7 +80,7 @@
EA62132120EAD6AC009F1C52 /* Salesforce_SearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Salesforce_SearchTests.swift; sourceTree = "<group>"; };
EA62132520EADA3F009F1C52 /* Salesforce_SObjectTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Salesforce_SObjectTests.swift; sourceTree = "<group>"; };
EA62C6621F196E6600D6CF4E /* MockAccountMetadata.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = MockAccountMetadata.json; sourceTree = "<group>"; };
EA62C6681F196E6600D6CF4E /* MockIdentity.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = MockIdentity.json; sourceTree = "<group>"; };
EA62C6681F196E6600D6CF4E /* MockIdentityPreWinter19.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = MockIdentityPreWinter19.json; sourceTree = "<group>"; };
EA774E9920CC2B560076D71C /* AuthorizationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorizationTests.swift; sourceTree = "<group>"; };
EA774E9B20CC61A50076D71C /* AuthorizationStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorizationStoreTests.swift; sourceTree = "<group>"; };
EA7BDBDC20EFDA440026856B /* URL_QueryItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URL_QueryItemTests.swift; sourceTree = "<group>"; };
Expand All @@ -88,6 +89,7 @@
EA846FC020DCBB16004F120E /* IdentityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentityTests.swift; sourceTree = "<group>"; };
EA87A4BD1F8DD2C100C16580 /* MockContactMetadata.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = MockContactMetadata.json; sourceTree = "<group>"; };
EA8A687320D55528007622D7 /* Salesforce_QueryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Salesforce_QueryTests.swift; sourceTree = "<group>"; };
EA99C043216F03E600FD8976 /* MockIdentityPostWinter19.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = MockIdentityPostWinter19.json; sourceTree = "<group>"; };
EAAAB52D20F0FCB60079B88B /* URLRequest_URLRequestConvertibleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLRequest_URLRequestConvertibleTests.swift; sourceTree = "<group>"; };
EAAC9E8120D2DC9500F0E16B /* DateFormatter_SalesforceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormatter_SalesforceTests.swift; sourceTree = "<group>"; };
EAAC9EB620D420AD00F0E16B /* Salesforce_OAuthTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Salesforce_OAuthTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -216,7 +218,8 @@
EAAC9EB820D44F5500F0E16B /* Configuration.json */,
EA62C6621F196E6600D6CF4E /* MockAccountMetadata.json */,
EA87A4BD1F8DD2C100C16580 /* MockContactMetadata.json */,
EA62C6681F196E6600D6CF4E /* MockIdentity.json */,
EA62C6681F196E6600D6CF4E /* MockIdentityPreWinter19.json */,
EA99C043216F03E600FD8976 /* MockIdentityPostWinter19.json */,
EAB7EDAC1F8AEC0B00788A20 /* MockLimits.json */,
607FACEA1AFB9204008FA782 /* Info.plist */,
);
Expand Down Expand Up @@ -359,8 +362,9 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EA99C045216F05F900FD8976 /* MockIdentityPostWinter19.json in Resources */,
EA62C6781F196E7C00D6CF4E /* MockAccountMetadata.json in Resources */,
EA62C67E1F196E9500D6CF4E /* MockIdentity.json in Resources */,
EA62C67E1F196E9500D6CF4E /* MockIdentityPreWinter19.json in Resources */,
EAAC9EB920D44F5500F0E16B /* Configuration.json in Resources */,
EA223AD91F8DD532003DC025 /* MockContactMetadata.json in Resources */,
);
Expand Down
23 changes: 21 additions & 2 deletions Example/Tests/IdentityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class IdentityTests: XCTestCase {
super.tearDown()
}

func testThatItInits() {
func testThatItInitsWithPreWinter19Data() {

let data = TestUtils.shared.read(fileName: "MockIdentity", ofType: "json")!
let data = TestUtils.shared.read(fileName: "MockIdentityPreWinter19", ofType: "json")!
let identity = try! decoder.decode(Identity.self, from: data)

XCTAssertEqual(identity.displayName, "Martin Van Nostrand")
Expand All @@ -37,4 +37,23 @@ class IdentityTests: XCTestCase {
XCTAssertEqual(identity.locale!, "en_US")
XCTAssertEqual(identity.thumbnailURL!, URL(string: "https://c.na85.content.force.com/profilephoto/005/T"))
}

// Date format for 'lastModifiedDate' changed in Winter '19
// See: https://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_security_auth_json_value_endpoints.htm
func testThatItInitsWithPostWinter19Data() {

let data = TestUtils.shared.read(fileName: "MockIdentityPostWinter19", ofType: "json")!
let identity = try! decoder.decode(Identity.self, from: data)

XCTAssertEqual(identity.displayName, "Martin Van Nostrand")
XCTAssertNil(identity.mobilePhone)
XCTAssertEqual(identity.username, "martin@vandelayindustries.com")
XCTAssertEqual(identity.userID, "005B00000088yOcIAI")
XCTAssertEqual(identity.orgID, "00DB0000008w8cfMAA")
XCTAssertEqual(identity.userType, "STANDARD")
XCTAssertEqual(identity.language!, "en_US")
XCTAssertEqual(identity.lastModifiedDate, DateFormatter.salesforceDateTimeFormatter.date(from: "2018-10-09T13:47:02.000+0000"))
XCTAssertEqual(identity.locale!, "en_US")
XCTAssertEqual(identity.thumbnailURL!, URL(string: "https://c.na85.content.force.com/profilephoto/005/T"))
}
}
55 changes: 55 additions & 0 deletions Example/Tests/MockIdentityPostWinter19.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"id" : "https://login.salesforce.com/id/00DB0000008w8cfMAA/005B00000088yOcIAI",
"asserted_user" : true,
"user_id" : "005B00000088yOcIAI",
"organization_id" : "00DB0000008w8cfMAA",
"username" : "martin@vandelayindustries.com",
"nick_name" : "mepstein-xvcf1.5390926328443926E12",
"display_name" : "Martin Van Nostrand",
"email" : "martin@vandelayindustries.com",
"email_verified" : true,
"first_name" : "Martin",
"last_name" : "Van Nostrand",
"timezone" : "America/Los_Angeles",
"photos" : {
"picture" : "https://c.na85.content.force.com/profilephoto/005/F",
"thumbnail" : "https://c.na85.content.force.com/profilephoto/005/T"
},
"addr_street" : null,
"addr_city" : null,
"addr_state" : null,
"addr_country" : "US",
"addr_zip" : null,
"mobile_phone" : null,
"mobile_phone_verified" : false,
"is_lightning_login_user" : false,
"status" : {
"created_date" : null,
"body" : null
},
"urls" : {
"enterprise" : "https://na85.salesforce.com/services/Soap/c/{version}/00Di0000000bcK3",
"metadata" : "https://na85.salesforce.com/services/Soap/m/{version}/00Di0000000bcK3",
"partner" : "https://na85.salesforce.com/services/Soap/u/{version}/00Di0000000bcK3",
"rest" : "https://na85.salesforce.com/services/data/v{version}/",
"sobjects" : "https://na85.salesforce.com/services/data/v{version}/sobjects/",
"search" : "https://na85.salesforce.com/services/data/v{version}/search/",
"query" : "https://na85.salesforce.com/services/data/v{version}/query/",
"recent" : "https://na85.salesforce.com/services/data/v{version}/recent/",
"tooling_soap" : "https://na85.salesforce.com/services/Soap/T/{version}/00Di0000000bcK3",
"tooling_rest" : "https://na85.salesforce.com/services/data/v{version}/tooling/",
"profile" : "https://na85.salesforce.com/005i00000016PdaAAE",
"feeds" : "https://na85.salesforce.com/services/data/v{version}/chatter/feeds",
"groups" : "https://na85.salesforce.com/services/data/v{version}/chatter/groups",
"users" : "https://na85.salesforce.com/services/data/v{version}/chatter/users",
"feed_items" : "https://na85.salesforce.com/services/data/v{version}/chatter/feed-items",
"feed_elements" : "https://na85.salesforce.com/services/data/v{version}/chatter/feed-elements"
},
"active" : true,
"user_type" : "STANDARD",
"language" : "en_US",
"locale" : "en_US",
"utcOffset" : -28800000,
"last_modified_date" : "2018-10-09T13:47:02Z",
"is_app_installed" : true
}
File renamed without changes.
6 changes: 3 additions & 3 deletions Example/Tests/RefreshTokenResultTests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// RefreshTokenResultTests.swift
// SwiftlySalesforce_Tests
// SwiftlySalesforce
//
// Created by Michael Epstein on 10/9/18.
// Copyright © 2018 CocoaPods. All rights reserved.
// For license & details see: https://www.github.com/mike4aday/SwiftlySalesforce
// Copyright (c) 2018. All rights reserved.
//

import XCTest
Expand Down
2 changes: 2 additions & 0 deletions Example/Tests/Salesforce_RESTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Salesforce_RESTTests: XCTestCase {
salesforce.identity()
}.done { identity in
debugPrint("User ID: \(identity.userID)")
debugPrint("User Name: \(identity.username)")
debugPrint("Last Modified Date: \(identity.lastModifiedDate)")
}.catch {
XCTFail($0.localizedDescription)
}.finally {
Expand Down
2 changes: 1 addition & 1 deletion SwiftlySalesforce.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SwiftlySalesforce"
s.version = "7.1.0"
s.version = "7.1.1"
s.summary = "An easy-to-use Swift framework for building iOS apps that integrate with the Salesforce Platform"

s.description = <<-DESC
Expand Down
16 changes: 15 additions & 1 deletion SwiftlySalesforce/Sources/Models/Identity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,21 @@ extension Identity: Decodable {
// Set properties
self.displayName = try container.decode(String.self, forKey: .displayName)
self.language = try container.decodeIfPresent(String.self, forKey: .language)
self.lastModifiedDate = try container.decode(Date.self, forKey: .lastModifiedDate)
self.lastModifiedDate = try {
// In Winter '19, date format changed for this field so we need to try both
// formats until Winter '19 is deployed in all orgs, then only new format.
// See: https://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_security_auth_json_value_endpoints.htm
//TODO: more comprehensive solution that could handle all formats in decoder?
if let date = try? container.decode(Date.self, forKey: .lastModifiedDate) {
return date
}
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
guard let string = try? container.decode(String.self, forKey: .lastModifiedDate), let date = formatter.date(from: string) else {
throw DecodingError.dataCorruptedError(forKey: .lastModifiedDate, in: container, debugDescription: "Unable to decode last modified date.")
}
return date
}()
self.locale = try container.decodeIfPresent(String.self, forKey: .locale)
self.mobilePhone = try container.decodeIfPresent(String.self, forKey: .mobilePhone)
self.orgID = try container.decode(String.self, forKey: .orgID)
Expand Down

0 comments on commit f2aef7e

Please sign in to comment.