Skip to content

Commit

Permalink
Merge pull request #76 from yumemi-inc/feature/edit_camel_case
Browse files Browse the repository at this point in the history
API Guidelineに準拠(アッパーキャメルケースをロワーキャメルケースに変更)
  • Loading branch information
es-kumagai authored May 23, 2024
2 parents 55bdcfb + bf45efc commit 13643d8
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 124 deletions.
8 changes: 4 additions & 4 deletions Sources/YumemiWeather/YumemiWeather.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final public class YumemiWeather {
/// API に請求する JSON 文字列の例:
///
/// {
/// "area": "tokyo",
/// "area": "Tokyo",
/// "date": "2020-04-01T12:00:00+09:00"
/// }
///
Expand Down Expand Up @@ -107,7 +107,7 @@ final public class YumemiWeather {
/// API に請求する JSON 文字列の例:
///
/// {
/// "area": "tokyo",
/// "area": "Tokyo",
/// "date": "2020-04-01T12:00:00+09:00"
/// }
///
Expand Down Expand Up @@ -136,7 +136,7 @@ final public class YumemiWeather {
/// API に請求する JSON 文字列の例:
///
/// {
/// "area": "tokyo",
/// "area": "Tokyo",
/// "date": "2020-04-01T12:00:00+09:00"
/// }
///
Expand Down Expand Up @@ -176,7 +176,7 @@ final public class YumemiWeather {
/// API に請求する JSON 文字列の例:
///
/// {
/// "area": "tokyo",
/// "area": "Tokyo",
/// "date": "2020-04-01T12:00:00+09:00"
/// }
///
Expand Down
24 changes: 12 additions & 12 deletions Sources/YumemiWeather/YumemiWeatherList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ struct AreaResponse: Codable {
}

public enum Area: String, CaseIterable, Codable {
case Sapporo
case Sendai
case Niigata
case Kanazawa
case Tokyo
case Nagoya
case Osaka
case Hiroshima
case Kochi
case Fukuoka
case Kagoshima
case Naha
case sapporo = "Sapporo"
case sendai = "Sendai"
case niigata = "Niigata"
case kanazawa = "Kanazawa"
case tokyo = "Tokyo"
case nagoya = "Nagoya"
case osaka = "Osaka"
case hiroshima = "Hiroshima"
case kochi = "Kochi"
case fukuoka = "Fukuoka"
case kagoshima = "Kagoshima"
case naha = "Naha"
}

public extension YumemiWeather {
Expand Down
160 changes: 96 additions & 64 deletions Tests/YumemiWeatherTests/YumemiWeatherListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,81 +48,113 @@ final class YumemiWeatherListTests: XCTestCase {

func test_fetchWeatherList_jsonString() throws {
let parameter = """
{
"areas": [],
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, Area.allCases.count)
{
"areas": [],
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, Area.allCases.count)
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}
}

func test_fetchWeatherList_jsonString_one() throws {
let parameter = """
{
"areas": ["Tokyo"],
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, 1)
let tokyo = response.first
XCTAssertEqual(tokyo?.area, .Tokyo)

let responseJSON2 = try YumemiWeather.fetchWeatherList(parameter)
let response2 = try decoder.decode([AreaResponse].self, from: Data(responseJSON2.utf8))
let tokyo2 = response2.first
XCTAssertEqual(tokyo?.info, tokyo2?.info)
{
"areas": ["Tokyo"],
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, 1)
let tokyo = response.first
XCTAssertEqual(tokyo?.area, .tokyo)

let responseJSON2 = try YumemiWeather.fetchWeatherList(parameter)
let response2 = try decoder.decode([AreaResponse].self, from: Data(responseJSON2.utf8))
let tokyo2 = response2.first
XCTAssertEqual(tokyo?.info, tokyo2?.info)
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}
}

func test_fetchWeatherList_jsonString_two() throws {
let parameter = """
{
"areas": ["Tokyo", "Nagoya"],
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, 2)
let tokyo = response.first(where: { $0.area == .Tokyo })
XCTAssertNotNil(tokyo)
let nagoya = response.first(where: { $0.area == .Nagoya })
XCTAssertNotNil(nagoya)
XCTAssertNotEqual(tokyo?.info, nagoya?.info)
{
"areas": ["Tokyo", "Nagoya"],
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, 2)
let tokyo = response.first(where: { $0.area == .tokyo })
XCTAssertNotNil(tokyo)
let nagoya = response.first(where: { $0.area == .nagoya })
XCTAssertNotNil(nagoya)
XCTAssertNotEqual(tokyo?.info, nagoya?.info)
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}
}

func test_fetchWeatherList_jsonString_none() throws {
let parameter = """
{
"areas": ["LosAngeles"],
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, 0)
{
"areas": ["LosAngeles"],
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try YumemiWeather.fetchWeatherList(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
let response = try decoder.decode([AreaResponse].self, from: Data(responseJSON.utf8))
XCTAssertEqual(response.count, 0)
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}
}
}
120 changes: 76 additions & 44 deletions Tests/YumemiWeatherTests/YumemiWeatherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,77 @@ final class YumemiWeatherTests: XCTestCase {
XCTAssertNotNil(WeatherCondition(rawValue: str))
}

func test_fetchWeather_at() throws {
let str = try YumemiWeather.fetchWeatherCondition(at: "tokyo")
XCTAssertNotNil(WeatherCondition(rawValue: str))
func test_fetchWeather_at() {
do {
let str = try YumemiWeather.fetchWeatherCondition(at: "Tokyo")
XCTAssertNotNil(WeatherCondition(rawValue: str))
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}
}

func test_fetchWeather_jsonString() throws {
let parameter = """
{
"area": "tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try YumemiWeather.fetchWeather(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
_ = try decoder.decode(Response.self, from: Data(responseJSON.utf8))
{
"area": "Tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try YumemiWeather.fetchWeather(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
_ = try decoder.decode(Response.self, from: Data(responseJSON.utf8))
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}
}

func test_fetchWeather_jsonString_sync() throws {
let beginDate = Date()
let parameter = """
{
"area": "tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try YumemiWeather.syncFetchWeather(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
_ = try decoder.decode(Response.self, from: Data(responseJSON.utf8))
{
"area": "Tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try YumemiWeather.syncFetchWeather(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
_ = try decoder.decode(Response.self, from: Data(responseJSON.utf8))
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}

XCTAssertGreaterThanOrEqual(Date().timeIntervalSince(beginDate), YumemiWeather.apiDuration)
}

func test_fetchWeather_jsonString_callback() {
let parameter = """
{
"area": "tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
{
"area": "Tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
let exp = expectation(description: #function)
YumemiWeather.callbackFetchWeather(parameter) { result in
exp.fulfill()
Expand All @@ -122,18 +146,26 @@ final class YumemiWeatherTests: XCTestCase {
func test_fetchWeather_jsonString_async() async throws {
let beginDate = Date()
let parameter = """
{
"area": "tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
let responseJSON = try await YumemiWeather.asyncFetchWeather(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
_ = try decoder.decode(Response.self, from: Data(responseJSON.utf8))
{
"area": "Tokyo",
"date": "2020-04-01T12:00:00+09:00"
}
"""
do {
let responseJSON = try await YumemiWeather.asyncFetchWeather(parameter)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .formatted(dateFormatter)
_ = try decoder.decode(Response.self, from: Data(responseJSON.utf8))
}
catch let error as YumemiWeatherError {
XCTAssertEqual(error, YumemiWeatherError.unknownError)
}
catch {
XCTFail()
}

XCTAssertGreaterThanOrEqual(Date().timeIntervalSince(beginDate), YumemiWeather.apiDuration)
}
Expand Down

0 comments on commit 13643d8

Please sign in to comment.