Skip to content

Commit 2439452

Browse files
authored
Merge pull request #26 from cybozu/equatable-testing
Improved testing using Equatable.
2 parents 7313c59 + 682b13e commit 2439452

File tree

79 files changed

+1573
-1187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1573
-1187
lines changed

Example/Example/FetchRecords/RecordFieldView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct RecordFieldView: View {
7676
EntityView(entity: entity)
7777
}
7878

79-
case let .subTable(subtableValueArray):
79+
case let .subtable(subtableValueArray):
8080
ArrayValueView(subtableValueArray.indices, id: \.self) { i in
8181
VStack(alignment: .leading, spacing: 4) {
8282
Text("ID: \(subtableValueArray[i].id)")

Sources/KintoneAPI/Codable/NumberPrecision.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct NumberPrecision: Codable, Sendable {
8+
public struct NumberPrecision: Codable, Sendable, Equatable {
99
public var digits: Int
1010
public var decimalPlaces: Int
1111
public var roundingMode: RoundingMode
@@ -29,4 +29,14 @@ public struct NumberPrecision: Codable, Sendable {
2929
try container.encode(decimalPlaces.description, forKey: .decimalPlaces)
3030
try container.encode(roundingMode, forKey: .roundingMode)
3131
}
32+
33+
init(
34+
digits: Int,
35+
decimalPlaces: Int,
36+
roundingMode: RoundingMode
37+
) {
38+
self.digits = digits
39+
self.decimalPlaces = decimalPlaces
40+
self.roundingMode = roundingMode
41+
}
3242
}

Sources/KintoneAPI/Decodable/AppSettings/AppIcon+Read.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
extension AppIcon {
9-
public enum Read: Decodable, Sendable {
9+
public enum Read: Decodable, Sendable, Equatable {
1010
case preset(String)
1111
case file(File.Read)
1212

Sources/KintoneAPI/Decodable/AppSettings/TitleField.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/02/04.
66
//
77

8-
public struct TitleField: Decodable, Sendable {
8+
public struct TitleField: Decodable, Sendable, Equatable {
99
public var selectionMode: TitleFieldSelectionMode
1010
public var code: String
1111
}

Sources/KintoneAPI/Decodable/AppStatus/Assignee.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct Assignee: Decodable, Sendable {
8+
public struct Assignee: Decodable, Sendable, Equatable {
99
public var type: AssigneeType
1010
public var entities: [AssigneeEntity]
1111
}

Sources/KintoneAPI/Decodable/AppStatus/AssigneeEntity.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct AssigneeEntity: Decodable, Sendable {
8+
public struct AssigneeEntity: Decodable, Sendable, Equatable {
99
public var type: EntityType
1010
public var code: String?
1111
public var includeSubs: Bool
@@ -24,4 +24,14 @@ public struct AssigneeEntity: Decodable, Sendable {
2424
code = try entityContainer.decodeIfPresent(String.self, forKey: .code)
2525
includeSubs = try container.decode(Bool.self, forKey: .includeSubs)
2626
}
27+
28+
init(
29+
type: EntityType,
30+
code: String?,
31+
includeSubs: Bool
32+
) {
33+
self.type = type
34+
self.code = code
35+
self.includeSubs = includeSubs
36+
}
2737
}

Sources/KintoneAPI/Decodable/AppStatus/RecordState.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct RecordState: Decodable, Sendable {
8+
public struct RecordState: Decodable, Sendable, Equatable {
99
public var name: String
1010
public var index: Int
1111
public var assignee: Assignee
@@ -22,4 +22,14 @@ public struct RecordState: Decodable, Sendable {
2222
index = try container.customDecode(String.self, forKey: .index) { Int($0) }
2323
assignee = try container.decode(Assignee.self, forKey: .assignee)
2424
}
25+
26+
init(
27+
name: String,
28+
index: Int,
29+
assignee: Assignee
30+
) {
31+
self.name = name
32+
self.index = index
33+
self.assignee = assignee
34+
}
2535
}

Sources/KintoneAPI/Decodable/AppStatus/StatusAction.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct StatusAction: Decodable, Sendable {
8+
public struct StatusAction: Decodable, Sendable, Equatable {
99
public var name: String
1010
public var from: String
1111
public var to: String

Sources/KintoneAPI/Decodable/Comment/RecordComment.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
extension RecordComment {
11-
public struct Read: Decodable, Sendable {
11+
public struct Read: Decodable, Sendable, Equatable {
1212
public var id: Int
1313
public var text: String
1414
public var createdAt: Date
@@ -35,5 +35,19 @@ extension RecordComment {
3535
}
3636
mentions = try container.decode([Entity.Read].self, forKey: .mentions)
3737
}
38+
39+
init(
40+
id: Int,
41+
text: String,
42+
createdAt: Date,
43+
creator: Entity.Read,
44+
mentions: [Entity.Read]
45+
) {
46+
self.id = id
47+
self.text = text
48+
self.createdAt = createdAt
49+
self.creator = creator
50+
self.mentions = mentions
51+
}
3852
}
3953
}

Sources/KintoneAPI/Decodable/Common/Entity+Read.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
extension Entity {
9-
public struct Read: Decodable, Sendable {
9+
public struct Read: Decodable, Sendable, Equatable {
1010
public var type: EntityType
1111
public var code: String
1212
public var name: String?

Sources/KintoneAPI/Decodable/Common/File+Read.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
extension File {
9-
public struct Read: Decodable, Sendable {
9+
public struct Read: Decodable, Sendable, Equatable {
1010
public var fileKey: String
1111
public var mimeType: String
1212
public var fileName: String
@@ -26,5 +26,17 @@ extension File {
2626
fileName = try container.decode(String.self, forKey: .fileName)
2727
fileSize = try container.decode(String.self, forKey: .fileSize)
2828
}
29+
30+
init(
31+
fileKey: String,
32+
mimeType: String,
33+
fileName: String,
34+
fileSize: String
35+
) {
36+
self.fileKey = fileKey
37+
self.mimeType = mimeType
38+
self.fileName = fileName
39+
self.fileSize = fileSize
40+
}
2941
}
3042
}

Sources/KintoneAPI/Decodable/FetchAppSettingsResponse.swift

+31-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct FetchAppSettingsResponse: Decodable, Sendable {
8+
public struct FetchAppSettingsResponse: Decodable, Sendable, Equatable {
99
public var name: String
1010
public var description: String
1111
public var icon: AppIcon.Read
@@ -52,4 +52,34 @@ public struct FetchAppSettingsResponse: Decodable, Sendable {
5252
firstMonthOfFiscalYear = try container.customDecode(String.self, forKey: .firstMonthOfFiscalYear) { Int($0) }
5353
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
5454
}
55+
56+
init(
57+
name: String,
58+
description: String,
59+
icon: AppIcon.Read,
60+
theme: AppThemeType,
61+
titleField: TitleField,
62+
enableThumbnails: Bool,
63+
enableBulkDeletion: Bool,
64+
enableComments: Bool,
65+
enableDuplicateRecord: Bool,
66+
enableInlineRecordEditing: Bool,
67+
numberPrecision: NumberPrecision,
68+
firstMonthOfFiscalYear: Int,
69+
revision: Int
70+
) {
71+
self.name = name
72+
self.description = description
73+
self.icon = icon
74+
self.theme = theme
75+
self.titleField = titleField
76+
self.enableThumbnails = enableThumbnails
77+
self.enableBulkDeletion = enableBulkDeletion
78+
self.enableComments = enableComments
79+
self.enableDuplicateRecord = enableDuplicateRecord
80+
self.enableInlineRecordEditing = enableInlineRecordEditing
81+
self.numberPrecision = numberPrecision
82+
self.firstMonthOfFiscalYear = firstMonthOfFiscalYear
83+
self.revision = revision
84+
}
5585
}

Sources/KintoneAPI/Decodable/FetchAppStatusSettingsResponse.swift

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8-
public struct FetchAppStatusSettingsResponse: Decodable, Sendable {
8+
import Foundation
9+
10+
public struct FetchAppStatusSettingsResponse: Decodable, Sendable, Equatable {
911
public var enable: Bool
1012
public var states: [RecordState]
1113
public var actions: [StatusAction]
@@ -28,8 +30,21 @@ public struct FetchAppStatusSettingsResponse: Decodable, Sendable {
2830
states = try statesContainer.allKeys.map { key in
2931
try statesContainer.decode(RecordState.self, forKey: DynamicCodingKey(stringValue: key.stringValue)!)
3032
}
33+
.sorted(using: KeyPathComparator(\.index))
3134
}
3235
actions = try container.decodeIfPresent([StatusAction].self, forKey: .actions) ?? []
3336
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
3437
}
38+
39+
init(
40+
enable: Bool,
41+
states: [RecordState],
42+
actions: [StatusAction],
43+
revision: Int
44+
) {
45+
self.enable = enable
46+
self.states = states
47+
self.actions = actions
48+
self.revision = revision
49+
}
3550
}

Sources/KintoneAPI/Decodable/FetchAppsResponse.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// Created by ky0me22 on 2024/12/06.
66
//
77

8-
public struct FetchAppsResponse: Decodable, Sendable {
8+
public struct FetchAppsResponse: Decodable, Sendable, Equatable {
99
public var apps: [KintoneApp]
1010
}

Sources/KintoneAPI/Decodable/FetchFieldsResponse.swift

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// Created by ky0me22 on 2024/12/04.
66
//
77

8-
public struct FetchFieldsResponse: Decodable, Sendable {
8+
import Foundation
9+
10+
public struct FetchFieldsResponse: Decodable, Sendable, Equatable {
911
public var fields: [Field]
1012
public var revision: Int
1113

@@ -17,9 +19,18 @@ public struct FetchFieldsResponse: Decodable, Sendable {
1719
public init(from decoder: any Decoder) throws {
1820
let container = try decoder.container(keyedBy: CodingKeys.self)
1921
let fieldsContainer = try container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .fields)
20-
fields = try fieldsContainer.allKeys.map { key in
21-
try fieldsContainer.decode(Field.self, forKey: DynamicCodingKey(stringValue: key.stringValue)!)
22+
fields = try fieldsContainer.allKeys.map {
23+
try fieldsContainer.decode(Field.self, forKey: DynamicCodingKey(stringValue: $0.stringValue)!)
2224
}
25+
.sorted(using: KeyPathComparator(\.code))
2326
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
2427
}
28+
29+
init(
30+
fields: [Field],
31+
revision: Int
32+
) {
33+
self.fields = fields
34+
self.revision = revision
35+
}
2536
}

Sources/KintoneAPI/Decodable/FetchFormLayoutResponse.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2024/12/04.
66
//
77

8-
public struct FetchFormLayoutResponse: Decodable, Sendable {
8+
public struct FetchFormLayoutResponse: Decodable, Sendable, Equatable {
99
public var layoutChunks: [FormLayoutChunk]
1010
public var revision: Int
1111

@@ -19,4 +19,12 @@ public struct FetchFormLayoutResponse: Decodable, Sendable {
1919
layoutChunks = try container.decode([FormLayoutChunk].self, forKey: .layoutChunks)
2020
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
2121
}
22+
23+
init(
24+
layoutChunks: [FormLayoutChunk],
25+
revision: Int
26+
) {
27+
self.layoutChunks = layoutChunks
28+
self.revision = revision
29+
}
2230
}

Sources/KintoneAPI/Decodable/FetchRecordCommentsResponse.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/02/19.
66
//
77

8-
public struct FetchRecordCommentsResponse: Decodable, Sendable {
8+
public struct FetchRecordCommentsResponse: Decodable, Sendable, Equatable {
99
public var comments: [RecordComment.Read]
1010
public var older: Bool
1111
public var newer: Bool

Sources/KintoneAPI/Decodable/FetchRecordsResponse.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2025/01/22.
66
//
77

8-
public struct FetchRecordsResponse: Decodable, Sendable {
8+
public struct FetchRecordsResponse: Decodable, Sendable, Equatable {
99
public var records: [Record.Read]
1010
public var totalCount: Int?
1111
}

Sources/KintoneAPI/Decodable/Field/Field.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2024/12/07.
66
//
77

8-
public struct Field: Decodable, Sendable {
8+
public struct Field: Decodable, Sendable, Equatable {
99
public var code: String
1010
public var label: String
1111
public var type: FieldType
@@ -86,4 +86,16 @@ public struct Field: Decodable, Sendable {
8686
}
8787
}
8888
}
89+
90+
init(
91+
code: String,
92+
label: String,
93+
type: FieldType,
94+
attribute: FieldAttribute
95+
) {
96+
self.code = code
97+
self.label = label
98+
self.type = type
99+
self.attribute = attribute
100+
}
89101
}

Sources/KintoneAPI/Decodable/Field/FieldAttribute.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by ky0me22 on 2024/12/06.
66
//
77

8-
public enum FieldAttribute: Sendable {
8+
public enum FieldAttribute: Sendable, Equatable {
99
case calc(CalcAttribute)
1010
case category(CategoryAttribute)
1111
case checkBox(CheckBoxAttribute)

0 commit comments

Comments
 (0)