Skip to content

Commit

Permalink
Remove force unwraps for data
Browse files Browse the repository at this point in the history
  • Loading branch information
AvdLee committed Jun 14, 2023
1 parent e896739 commit 8d820fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class ChangelogItemsFactoryTests: XCTestCase {

/// It should return the pull request only if no referencing issues are found.
func testCreatingItems() {
let pullRequest = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first!
let pullRequest = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).first!
let factory = ChangelogItemsFactory(octoKit: octoKit, pullRequests: [pullRequest], project: project)
let items = factory.items(using: urlSession)
XCTAssertEqual(items.count, 1)
Expand All @@ -41,8 +41,8 @@ final class ChangelogItemsFactoryTests: XCTestCase {

/// It should return the referencing issue with the pull request.
func testReferencingIssue() {
let pullRequest = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).last!
let issue = IssueJSON.data(using: .utf8)!.mapJSON(to: Issue.self)
let pullRequest = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).last!
let issue = Data(IssueJSON.utf8).mapJSON(to: Issue.self)
let factory = ChangelogItemsFactory(octoKit: octoKit, pullRequests: [pullRequest], project: project)
Mocker.mockForIssueNumber(39)
let items = factory.items(using: urlSession)
Expand Down
4 changes: 2 additions & 2 deletions Tests/GitBuddyTests/Models/ChangelogItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ final class ChangelogItemTests: XCTestCase {

/// It should show the user if possible.
func testUser() {
let input = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first!
let input = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).first!
input.htmlURL = nil
let item = ChangelogItem(input: input, closedBy: input)
XCTAssertEqual(item.title, "Add charset utf-8 to html head via [@AvdLee](https://github.com/AvdLee)")
}

/// It should fallback to the assignee if the user is nil for Pull Requests.
func testAssigneeFallback() {
let input = PullRequestsJSON.data(using: .utf8)!.mapJSON(to: [PullRequest].self).first!
let input = Data(PullRequestsJSON.utf8).mapJSON(to: [PullRequest].self).first!
input.user = nil
input.htmlURL = nil
let item = ChangelogItem(input: input, closedBy: input)
Expand Down
14 changes: 7 additions & 7 deletions Tests/GitBuddyTests/TestHelpers/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension Mocker {
URLQueryItem(name: "state", value: "closed")
]

let pullRequestJSONData = PullRequestsJSON.data(using: .utf8)!
let pullRequestJSONData = Data(PullRequestsJSON.utf8)
let mock = Mock(url: urlComponents.url!, dataType: .json, statusCode: 200, data: [.get: pullRequestJSONData])
mock.register()
}
Expand All @@ -101,19 +101,19 @@ extension Mocker {
URLQueryItem(name: "state", value: "closed")
]

let data = IssuesJSON.data(using: .utf8)!
let data = Data(IssuesJSON.utf8)
let mock = Mock(url: urlComponents.url!, dataType: .json, statusCode: 200, data: [.get: data])
mock.register()
}

static func mockForIssueNumber(_ issueNumber: Int) {
let urlComponents = URLComponents(string: "https://api.github.com/repos/WeTransfer/Diagnostics/issues/\(issueNumber)")!
let issueJSONData = IssueJSON.data(using: .utf8)!
let issueJSONData = Data(IssueJSON.utf8)
Mock(url: urlComponents.url!, dataType: .json, statusCode: 200, data: [.get: issueJSONData]).register()
}

@discardableResult static func mockRelease() -> Mock {
let releaseJSONData = ReleaseJSON.data(using: .utf8)!
let releaseJSONData = Data(ReleaseJSON.utf8)
let mock = Mock(
url: URL(string: "https://api.github.com/repos/WeTransfer/Diagnostics/releases")!,
dataType: .json,
Expand All @@ -125,7 +125,7 @@ extension Mocker {
}

@discardableResult static func mockReleaseNotes() -> Mock {
let releaseNotesJSONData = ReleaseNotesJSON.data(using: .utf8)!
let releaseNotesJSONData = Data(ReleaseNotesJSON.utf8)
let mock = Mock(
url: URL(string: "https://api.github.com/repos/WeTransfer/Diagnostics/releases/generate-notes")!,
dataType: .json,
Expand All @@ -137,7 +137,7 @@ extension Mocker {
}

@discardableResult static func mockListReleases() -> Mock {
let releaseJSONData = ListReleasesJSON.data(using: .utf8)!
let releaseJSONData = Data(ListReleasesJSON.utf8)
let mock = Mock(
url: URL(string: "https://api.github.com/repos/WeTransfer/Diagnostics/releases?per_page=100")!,
dataType: .json,
Expand Down Expand Up @@ -172,7 +172,7 @@ extension Mocker {

static func mockForCommentingOn(issueNumber: Int) -> Mock {
let urlComponents = URLComponents(string: "https://api.github.com/repos/WeTransfer/Diagnostics/issues/\(issueNumber)/comments")!
let commentJSONData = CommentJSON.data(using: .utf8)!
let commentJSONData = Data(CommentJSON.utf8)
return Mock(url: urlComponents.url!, dataType: .json, statusCode: 201, data: [.post: commentJSONData])
}
}
Expand Down

0 comments on commit 8d820fa

Please sign in to comment.