Skip to content

Commit

Permalink
fixed comments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omarzl committed May 31, 2024
1 parent d375a44 commit 94521f6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
secretKey: try files.read(Path(itunesConnectKeyPath))
)
let deviceIDs: Set<String> = 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)
Expand Down Expand Up @@ -555,4 +552,10 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
}
return shouldRegenerate
}

mutating internal func validate() throws {
if autoRegenerate, profileName == nil {
throw Error.profileNameMissing
}
}
}
2 changes: 1 addition & 1 deletion Sources/SignHereLibrary/Models/CreateProfileResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import Foundation

internal struct CreateProfileResponse: Codable {
var data: ProfileResponseData
}
}
2 changes: 1 addition & 1 deletion Sources/SignHereLibrary/Models/ProfileResponseData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ struct ProfileResponseData: Codable {
var type: String
var attributes: Attributes
var relationships: Relationships
}
}
2 changes: 1 addition & 1 deletion Sources/SignHereLibrary/Models/ProfileType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ enum ProfileType {
default: return true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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)")
Expand Down Expand Up @@ -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()

Expand All @@ -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")
Expand All @@ -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()

Expand Down

0 comments on commit 94521f6

Please sign in to comment.