Skip to content

Commit 8a0d67c

Browse files
committed
add testEnumArray
1 parent abb95c0 commit 8a0d67c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/FluentPostgreSQLTests/FluentPostgreSQLTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,33 @@ class FluentPostgreSQLTests: XCTestCase {
379379
XCTAssertEqual(c?.name, "Earth")
380380
}
381381

382+
func testEnumArray() throws {
383+
enum A: Int16, Codable, CaseIterable, ReflectionDecodable {
384+
static var allCases: [A] = [.a, .b, .c]
385+
case a, b, c
386+
}
387+
struct B: PostgreSQLModel, PostgreSQLMigration {
388+
var id: Int?
389+
var a: [A]
390+
391+
static func prepare(on conn: PostgreSQLConnection) -> Future<Void> {
392+
return PostgreSQLDatabase.create(B.self, on: conn) { builder in
393+
builder.field(for: \.id, isIdentifier: true)
394+
builder.field(for: \.a, type: .array(.int2), .notNull)
395+
}
396+
}
397+
}
398+
399+
let conn = try benchmarker.pool.requestConnection().wait()
400+
conn.logger = DatabaseLogger(database: .psql, handler: PrintLogHandler())
401+
defer { benchmarker.pool.releaseConnection(conn) }
402+
defer { try? B.revert(on: conn).wait() }
403+
try B.prepare(on: conn).wait()
404+
405+
let b = try B(id: nil, a: [.a, .b, .c]).save(on: conn).wait()
406+
XCTAssertEqual(b.id, 1)
407+
}
408+
382409
static let allTests = [
383410
("testBenchmark", testBenchmark),
384411
("testNestedStruct", testNestedStruct),
@@ -394,6 +421,7 @@ class FluentPostgreSQLTests: XCTestCase {
394421
("testSort", testSort),
395422
("testCustomFilter", testCustomFilter),
396423
("testCreateOrUpdate", testCreateOrUpdate),
424+
("testEnumArray", testEnumArray),
397425
]
398426
}
399427

0 commit comments

Comments
 (0)