Files
iOS/Tests/Shared/Database/DatabaseTableProtocol.test.swift
Bruno Pantaleão Gonçalves 45e05e6666 Add confirmation dialog before executing tag (#4617)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->
Before forwarding unknown tags to Home Assistant, present a confirmation
dialog.

Android implementation:
https://github.com/home-assistant/android/pull/6814

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->
<img width="966" height="1004" alt="CleanShot 2026-05-07 at 15 56 54@2x"
src="https://github.com/user-attachments/assets/b7411e42-c2ec-473b-8241-c3280531737f"
/>


## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
2026-05-08 10:55:40 +02:00

190 lines
8.9 KiB
Swift

import GRDB
@testable import Shared
import Testing
@Suite("Database Table Protocol Tests")
struct DatabaseTableProtocolTests {
@Test("HAppEntityTable conforms to DatabaseTableProtocol")
func hAppEntityTableConformance() throws {
let table = HAppEntityTable()
#expect(table.tableName == GRDBDatabaseTable.HAAppEntity.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
// Verify definedColumns match DatabaseTables enum
let expectedColumns = DatabaseTables.AppEntity.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("WatchConfigTable conforms to DatabaseTableProtocol")
func watchConfigTableConformance() throws {
let table = WatchConfigTable()
#expect(table.tableName == GRDBDatabaseTable.watchConfig.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.WatchConfig.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("CarPlayConfigTable conforms to DatabaseTableProtocol")
func carPlayConfigTableConformance() throws {
let table = CarPlayConfigTable()
#expect(table.tableName == GRDBDatabaseTable.carPlayConfig.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.CarPlayConfig.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AppIconShortcutConfigTable conforms to DatabaseTableProtocol")
func appIconShortcutConfigTableConformance() throws {
let table = AppIconShortcutConfigTable()
#expect(table.tableName == GRDBDatabaseTable.appIconShortcutConfig.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AppIconShortcutConfig.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AssistPipelinesTable conforms to DatabaseTableProtocol")
func assistPipelinesTableConformance() throws {
let table = AssistPipelinesTable()
#expect(table.tableName == GRDBDatabaseTable.assistPipelines.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AssistPipelines.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AppEntityRegistryListForDisplayTable conforms to DatabaseTableProtocol")
func appEntityRegistryListForDisplayTableConformance() throws {
let table = AppEntityRegistryListForDisplayTable()
#expect(table.tableName == GRDBDatabaseTable.appEntityRegistryListForDisplay.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AppEntityRegistryListForDisplay.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AppEntityRegistryTable conforms to DatabaseTableProtocol")
func appEntityRegistryTableConformance() throws {
let table = AppEntityRegistryTable()
#expect(table.tableName == GRDBDatabaseTable.entityRegistry.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
// Note: AppEntityRegistryTable filters out .id from definedColumns
let expectedColumns = DatabaseTables.EntityRegistry.allCases
.filter { $0 != .id }
.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
#expect(!table.definedColumns.contains("id"), "definedColumns should not contain 'id'")
}
@Test("AppDeviceRegistryTable conforms to DatabaseTableProtocol")
func appDeviceRegistryTableConformance() throws {
let table = AppDeviceRegistryTable()
#expect(table.tableName == GRDBDatabaseTable.deviceRegistry.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
// Note: AppDeviceRegistryTable filters out .id from definedColumns
let expectedColumns = DatabaseTables.DeviceRegistry.allCases
.filter { $0 != .id }
.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
#expect(!table.definedColumns.contains("id"), "definedColumns should not contain 'id'")
}
@Test("AppPanelTable conforms to DatabaseTableProtocol")
func appPanelTableConformance() throws {
let table = AppPanelTable()
#expect(table.tableName == GRDBDatabaseTable.appPanel.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AppPanel.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("CustomWidgetTable conforms to DatabaseTableProtocol")
func customWidgetTableConformance() throws {
let table = CustomWidgetTable()
#expect(table.tableName == GRDBDatabaseTable.customWidget.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.CustomWidget.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AppAreaTable conforms to DatabaseTableProtocol")
func appAreaTableConformance() throws {
let table = AppAreaTable()
#expect(table.tableName == GRDBDatabaseTable.appArea.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AppArea.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("HomeViewConfigurationTable conforms to DatabaseTableProtocol")
func homeViewConfigurationTableConformance() throws {
let table = HomeViewConfigurationTable()
#expect(table.tableName == GRDBDatabaseTable.homeViewConfiguration.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.HomeViewConfiguration.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("CameraListConfigurationTable conforms to DatabaseTableProtocol")
func cameraListConfigurationTableConformance() throws {
let table = CameraListConfigurationTable()
#expect(table.tableName == GRDBDatabaseTable.cameraListConfiguration.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.CameraListConfiguration.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AssistConfigurationTable conforms to DatabaseTableProtocol")
func assistConfigurationTableConformance() throws {
let table = AssistConfigurationTable()
#expect(table.tableName == GRDBDatabaseTable.assistConfiguration.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AssistConfiguration.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("ServerInfoMirrorTable conforms to DatabaseTableProtocol")
func serverInfoMirrorTableConformance() throws {
let table = ServerInfoMirrorTable()
#expect(table.tableName == GRDBDatabaseTable.serverInfoMirror.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.ServerInfoMirror.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("AllowedTagTable conforms to DatabaseTableProtocol")
func allowedTagTableConformance() throws {
let table = AllowedTagTable()
#expect(table.tableName == GRDBDatabaseTable.allowedTags.rawValue)
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty")
let expectedColumns = DatabaseTables.AllowedTag.allCases.map(\.rawValue)
#expect(Set(table.definedColumns) == Set(expectedColumns))
}
@Test("All 17 tables conform to DatabaseTableProtocol")
func allTablesConformToProtocol() throws {
let tables = DatabaseQueue.tables()
#expect(tables.count == 17, "Should have exactly 17 tables")
for table in tables {
// Verify each table has a non-empty tableName
#expect(!table.tableName.isEmpty, "Table name should not be empty")
// Verify each table has at least one defined column
#expect(!table.definedColumns.isEmpty, "definedColumns should not be empty for \(table.tableName)")
}
}
}