From 94521f6c4eda2103b9f90762672231d62443aaef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Zu=CC=81n=CC=83iga=20Lagunas?= Date: Fri, 31 May 2024 13:16:39 -0600 Subject: [PATCH] fixed comments and tests --- .../Commands/CreateProvisioningProfileCommand.swift | 9 ++++++--- .../Models/CreateProfileResponse.swift | 2 +- .../SignHereLibrary/Models/ProfileResponseData.swift | 2 +- Sources/SignHereLibrary/Models/ProfileType.swift | 2 +- .../Services/iTunesConnectService.swift | 2 +- .../CreateProvisioningProfileCommandTests.swift | 12 +++++++++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift b/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift index 24e22ce..0eb986f 100644 --- a/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift +++ b/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift @@ -307,9 +307,6 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { secretKey: try files.read(Path(itunesConnectKeyPath)) ) let deviceIDs: Set = try iTunesConnectService.fetchITCDeviceIDs(jsonWebToken: jsonWebToken) - if autoRegenerate, profileName == nil { - throw Error.profileNameMissing - } guard let profileName, let profile = try? fetchProvisioningProfile(jsonWebToken: jsonWebToken, name: profileName) else { try createProvisioningProfile(jsonWebToken: jsonWebToken, deviceIDs: deviceIDs) @@ -555,4 +552,10 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { } return shouldRegenerate } + + mutating internal func validate() throws { + if autoRegenerate, profileName == nil { + throw Error.profileNameMissing + } + } } diff --git a/Sources/SignHereLibrary/Models/CreateProfileResponse.swift b/Sources/SignHereLibrary/Models/CreateProfileResponse.swift index b49095d..279c92e 100644 --- a/Sources/SignHereLibrary/Models/CreateProfileResponse.swift +++ b/Sources/SignHereLibrary/Models/CreateProfileResponse.swift @@ -9,4 +9,4 @@ import Foundation internal struct CreateProfileResponse: Codable { var data: ProfileResponseData -} \ No newline at end of file +} diff --git a/Sources/SignHereLibrary/Models/ProfileResponseData.swift b/Sources/SignHereLibrary/Models/ProfileResponseData.swift index 114a9fe..48e2ce2 100644 --- a/Sources/SignHereLibrary/Models/ProfileResponseData.swift +++ b/Sources/SignHereLibrary/Models/ProfileResponseData.swift @@ -33,4 +33,4 @@ struct ProfileResponseData: Codable { var type: String var attributes: Attributes var relationships: Relationships -} \ No newline at end of file +} diff --git a/Sources/SignHereLibrary/Models/ProfileType.swift b/Sources/SignHereLibrary/Models/ProfileType.swift index 219fc02..abdd8fd 100644 --- a/Sources/SignHereLibrary/Models/ProfileType.swift +++ b/Sources/SignHereLibrary/Models/ProfileType.swift @@ -32,4 +32,4 @@ enum ProfileType { default: return true } } -} \ No newline at end of file +} diff --git a/Sources/SignHereLibrary/Services/iTunesConnectService.swift b/Sources/SignHereLibrary/Services/iTunesConnectService.swift index d2eed94..97def27 100644 --- a/Sources/SignHereLibrary/Services/iTunesConnectService.swift +++ b/Sources/SignHereLibrary/Services/iTunesConnectService.swift @@ -448,7 +448,7 @@ internal class iTunesConnectServiceImp: iTunesConnectService { jsonWebToken: String, name: String ) throws -> [ProfileResponseData] { - var urlComponents: URLComponents = .init() + var urlComponents: URLComponents = .init() urlComponents.scheme = Constants.httpsScheme urlComponents.host = Constants.itcHost urlComponents.path = "/v1/profiles" diff --git a/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift b/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift index 1f29849..b8c2cfb 100644 --- a/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift +++ b/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift @@ -289,6 +289,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { func test_execute_profileAlreadyExists() throws { // GIVEN var executeLaunchPaths: [ShellOutput] = [] + let responseObject = createCreateProfileResponse().data shell.executeLaunchPathHandler = { _, _, _, _ in XCTAssert(false, "Shouldn't be executed") @@ -313,9 +314,10 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { return self.createCreateProfileResponse() } iTunesConnectService.fetchProvisioningProfileHandler = { _, _ in - return [self.createCreateProfileResponse().data] + return [responseObject] } // WHEN + subject.profileName = responseObject.attributes.name try subject.run() // THEN @@ -334,6 +336,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { func test_execute_profileShouldRegenerateWithNewDevices() throws { // GIVEN var previousProfileWasDeleted = false + let responseObject = createCreateProfileResponse().data files.uniqueTemporaryPathHandler = { Path("/unique_temporary_path_\(self.files.uniqueTemporaryPathCallCount)") @@ -371,9 +374,10 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { previousProfileWasDeleted = true } iTunesConnectService.fetchProvisioningProfileHandler = { _, _ in - return [self.createCreateProfileResponse().data] + return [responseObject] } // WHEN + subject.profileName = responseObject.attributes.name subject.autoRegenerate = true try subject.run() @@ -395,6 +399,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { func test_execute_profileShouldNotRegenerateWithSameDevices() throws { // GIVEN var executeLaunchPaths: [ShellOutput] = [] + let responseObject = createCreateProfileResponse().data shell.executeLaunchPathHandler = { _, _, _, _ in XCTAssert(false, "Shouldn't be executed") @@ -419,9 +424,10 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { return self.createCreateProfileResponse() } iTunesConnectService.fetchProvisioningProfileHandler = { _, _ in - return [self.createCreateProfileResponse().data] + return [responseObject] } // WHEN + subject.profileName = responseObject.attributes.name subject.autoRegenerate = true try subject.run()