Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved testing using Equatable. #26

Merged
merged 14 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/Example/FetchRecords/RecordFieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct RecordFieldView: View {
EntityView(entity: entity)
}

case let .subTable(subtableValueArray):
case let .subtable(subtableValueArray):
ArrayValueView(subtableValueArray.indices, id: \.self) { i in
VStack(alignment: .leading, spacing: 4) {
Text("ID: \(subtableValueArray[i].id)")
Expand Down
12 changes: 11 additions & 1 deletion Sources/KintoneAPI/Codable/NumberPrecision.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/31.
//

public struct NumberPrecision: Codable, Sendable {
public struct NumberPrecision: Codable, Sendable, Equatable {
public var digits: Int
public var decimalPlaces: Int
public var roundingMode: RoundingMode
Expand All @@ -29,4 +29,14 @@ public struct NumberPrecision: Codable, Sendable {
try container.encode(decimalPlaces.description, forKey: .decimalPlaces)
try container.encode(roundingMode, forKey: .roundingMode)
}

init(
digits: Int,
decimalPlaces: Int,
roundingMode: RoundingMode
) {
self.digits = digits
self.decimalPlaces = decimalPlaces
self.roundingMode = roundingMode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

extension AppIcon {
public enum Read: Decodable, Sendable {
public enum Read: Decodable, Sendable, Equatable {
case preset(String)
case file(File.Read)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/02/04.
//

public struct TitleField: Decodable, Sendable {
public struct TitleField: Decodable, Sendable, Equatable {
public var selectionMode: TitleFieldSelectionMode
public var code: String
}
2 changes: 1 addition & 1 deletion Sources/KintoneAPI/Decodable/AppStatus/Assignee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/31.
//

public struct Assignee: Decodable, Sendable {
public struct Assignee: Decodable, Sendable, Equatable {
public var type: AssigneeType
public var entities: [AssigneeEntity]
}
12 changes: 11 additions & 1 deletion Sources/KintoneAPI/Decodable/AppStatus/AssigneeEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/31.
//

public struct AssigneeEntity: Decodable, Sendable {
public struct AssigneeEntity: Decodable, Sendable, Equatable {
public var type: EntityType
public var code: String?
public var includeSubs: Bool
Expand All @@ -24,4 +24,14 @@ public struct AssigneeEntity: Decodable, Sendable {
code = try entityContainer.decodeIfPresent(String.self, forKey: .code)
includeSubs = try container.decode(Bool.self, forKey: .includeSubs)
}

init(
type: EntityType,
code: String?,
includeSubs: Bool
) {
self.type = type
self.code = code
self.includeSubs = includeSubs
}
}
12 changes: 11 additions & 1 deletion Sources/KintoneAPI/Decodable/AppStatus/RecordState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/31.
//

public struct RecordState: Decodable, Sendable {
public struct RecordState: Decodable, Sendable, Equatable {
public var name: String
public var index: Int
public var assignee: Assignee
Expand All @@ -22,4 +22,14 @@ public struct RecordState: Decodable, Sendable {
index = try container.customDecode(String.self, forKey: .index) { Int($0) }
assignee = try container.decode(Assignee.self, forKey: .assignee)
}

init(
name: String,
index: Int,
assignee: Assignee
) {
self.name = name
self.index = index
self.assignee = assignee
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/31.
//

public struct StatusAction: Decodable, Sendable {
public struct StatusAction: Decodable, Sendable, Equatable {
public var name: String
public var from: String
public var to: String
Expand Down
16 changes: 15 additions & 1 deletion Sources/KintoneAPI/Decodable/Comment/RecordComment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension RecordComment {
public struct Read: Decodable, Sendable {
public struct Read: Decodable, Sendable, Equatable {
public var id: Int
public var text: String
public var createdAt: Date
Expand All @@ -35,5 +35,19 @@ extension RecordComment {
}
mentions = try container.decode([Entity.Read].self, forKey: .mentions)
}

init(
id: Int,
text: String,
createdAt: Date,
creator: Entity.Read,
mentions: [Entity.Read]
) {
self.id = id
self.text = text
self.createdAt = createdAt
self.creator = creator
self.mentions = mentions
}
}
}
2 changes: 1 addition & 1 deletion Sources/KintoneAPI/Decodable/Common/Entity+Read.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

extension Entity {
public struct Read: Decodable, Sendable {
public struct Read: Decodable, Sendable, Equatable {
public var type: EntityType
public var code: String
public var name: String?
Expand Down
14 changes: 13 additions & 1 deletion Sources/KintoneAPI/Decodable/Common/File+Read.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

extension File {
public struct Read: Decodable, Sendable {
public struct Read: Decodable, Sendable, Equatable {
public var fileKey: String
public var mimeType: String
public var fileName: String
Expand All @@ -26,5 +26,17 @@ extension File {
fileName = try container.decode(String.self, forKey: .fileName)
fileSize = try container.decode(String.self, forKey: .fileSize)
}

init(
fileKey: String,
mimeType: String,
fileName: String,
fileSize: String
) {
self.fileKey = fileKey
self.mimeType = mimeType
self.fileName = fileName
self.fileSize = fileSize
}
}
}
32 changes: 31 additions & 1 deletion Sources/KintoneAPI/Decodable/FetchAppSettingsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/31.
//

public struct FetchAppSettingsResponse: Decodable, Sendable {
public struct FetchAppSettingsResponse: Decodable, Sendable, Equatable {
public var name: String
public var description: String
public var icon: AppIcon.Read
Expand Down Expand Up @@ -52,4 +52,34 @@ public struct FetchAppSettingsResponse: Decodable, Sendable {
firstMonthOfFiscalYear = try container.customDecode(String.self, forKey: .firstMonthOfFiscalYear) { Int($0) }
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
}

init(
name: String,
description: String,
icon: AppIcon.Read,
theme: AppThemeType,
titleField: TitleField,
enableThumbnails: Bool,
enableBulkDeletion: Bool,
enableComments: Bool,
enableDuplicateRecord: Bool,
enableInlineRecordEditing: Bool,
numberPrecision: NumberPrecision,
firstMonthOfFiscalYear: Int,
revision: Int
) {
self.name = name
self.description = description
self.icon = icon
self.theme = theme
self.titleField = titleField
self.enableThumbnails = enableThumbnails
self.enableBulkDeletion = enableBulkDeletion
self.enableComments = enableComments
self.enableDuplicateRecord = enableDuplicateRecord
self.enableInlineRecordEditing = enableInlineRecordEditing
self.numberPrecision = numberPrecision
self.firstMonthOfFiscalYear = firstMonthOfFiscalYear
self.revision = revision
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Created by ky0me22 on 2025/01/31.
//

public struct FetchAppStatusSettingsResponse: Decodable, Sendable {
import Foundation

public struct FetchAppStatusSettingsResponse: Decodable, Sendable, Equatable {
public var enable: Bool
public var states: [RecordState]
public var actions: [StatusAction]
Expand All @@ -28,8 +30,21 @@ public struct FetchAppStatusSettingsResponse: Decodable, Sendable {
states = try statesContainer.allKeys.map { key in
try statesContainer.decode(RecordState.self, forKey: DynamicCodingKey(stringValue: key.stringValue)!)
}
.sorted(using: KeyPathComparator(\.index))
}
actions = try container.decodeIfPresent([StatusAction].self, forKey: .actions) ?? []
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
}

init(
enable: Bool,
states: [RecordState],
actions: [StatusAction],
revision: Int
) {
self.enable = enable
self.states = states
self.actions = actions
self.revision = revision
}
}
2 changes: 1 addition & 1 deletion Sources/KintoneAPI/Decodable/FetchAppsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// Created by ky0me22 on 2024/12/06.
//

public struct FetchAppsResponse: Decodable, Sendable {
public struct FetchAppsResponse: Decodable, Sendable, Equatable {
public var apps: [KintoneApp]
}
17 changes: 14 additions & 3 deletions Sources/KintoneAPI/Decodable/FetchFieldsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Created by ky0me22 on 2024/12/04.
//

public struct FetchFieldsResponse: Decodable, Sendable {
import Foundation

public struct FetchFieldsResponse: Decodable, Sendable, Equatable {
public var fields: [Field]
public var revision: Int

Expand All @@ -17,9 +19,18 @@ public struct FetchFieldsResponse: Decodable, Sendable {
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let fieldsContainer = try container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .fields)
fields = try fieldsContainer.allKeys.map { key in
try fieldsContainer.decode(Field.self, forKey: DynamicCodingKey(stringValue: key.stringValue)!)
fields = try fieldsContainer.allKeys.map {
try fieldsContainer.decode(Field.self, forKey: DynamicCodingKey(stringValue: $0.stringValue)!)
}
.sorted(using: KeyPathComparator(\.code))
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
}

init(
fields: [Field],
revision: Int
) {
self.fields = fields
self.revision = revision
}
}
10 changes: 9 additions & 1 deletion Sources/KintoneAPI/Decodable/FetchFormLayoutResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2024/12/04.
//

public struct FetchFormLayoutResponse: Decodable, Sendable {
public struct FetchFormLayoutResponse: Decodable, Sendable, Equatable {
public var layoutChunks: [FormLayoutChunk]
public var revision: Int

Expand All @@ -19,4 +19,12 @@ public struct FetchFormLayoutResponse: Decodable, Sendable {
layoutChunks = try container.decode([FormLayoutChunk].self, forKey: .layoutChunks)
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
}

init(
layoutChunks: [FormLayoutChunk],
revision: Int
) {
self.layoutChunks = layoutChunks
self.revision = revision
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/02/19.
//

public struct FetchRecordCommentsResponse: Decodable, Sendable {
public struct FetchRecordCommentsResponse: Decodable, Sendable, Equatable {
public var comments: [RecordComment.Read]
public var older: Bool
public var newer: Bool
Expand Down
2 changes: 1 addition & 1 deletion Sources/KintoneAPI/Decodable/FetchRecordsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2025/01/22.
//

public struct FetchRecordsResponse: Decodable, Sendable {
public struct FetchRecordsResponse: Decodable, Sendable, Equatable {
public var records: [Record.Read]
public var totalCount: Int?
}
14 changes: 13 additions & 1 deletion Sources/KintoneAPI/Decodable/Field/Field.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2024/12/07.
//

public struct Field: Decodable, Sendable {
public struct Field: Decodable, Sendable, Equatable {
public var code: String
public var label: String
public var type: FieldType
Expand Down Expand Up @@ -86,4 +86,16 @@ public struct Field: Decodable, Sendable {
}
}
}

init(
code: String,
label: String,
type: FieldType,
attribute: FieldAttribute
) {
self.code = code
self.label = label
self.type = type
self.attribute = attribute
}
}
2 changes: 1 addition & 1 deletion Sources/KintoneAPI/Decodable/Field/FieldAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by ky0me22 on 2024/12/06.
//

public enum FieldAttribute: Sendable {
public enum FieldAttribute: Sendable, Equatable {
case calc(CalcAttribute)
case category(CategoryAttribute)
case checkBox(CheckBoxAttribute)
Expand Down
Loading
Loading