Skip to content

Commit f27c0a6

Browse files
committed
Convert SQLKitExtensionTests
1 parent 3ab938d commit f27c0a6

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Tests/AppTests/AppTestCase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ extension AppTestCase {
182182
}
183183

184184

185-
// FIXME: Move this once AppTestCase can be removed. These are helpers created during the transition to Swift Testing.
185+
// FIXME: Move this once AppTestCase can be removed. These are helpers created during the transition to Swift Testing. Also check if we can just create a PostgresDB object from scratch rather than using withApp and app.db for this at the call site. That does a whole migration + reset just to render the SQL needlessly.
186186
extension Database {
187187
func renderSQL(_ builder: SQLSelectBuilder) -> String {
188188
renderSQL(builder.query)

Tests/AppTests/SQLKitExtensionTests.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,30 @@
1515
@testable import App
1616

1717
import SQLKit
18-
import XCTest
18+
import Testing
1919

2020

21-
class SQLKitExtensionTests: AppTestCase {
21+
@Suite struct SQLKitExtensionTests {
2222

23-
func test_OrderByGroup() throws {
24-
let b = SQLOrderBy(SQLIdentifier("id"), .ascending)
25-
.then(SQLIdentifier("foo"), .descending)
26-
XCTAssertEqual(renderSQL(b), #""id" ASC, "foo" DESC"#)
23+
@Test func OrderByGroup() async throws {
24+
try await withApp { app in
25+
let b = SQLOrderBy(SQLIdentifier("id"), .ascending)
26+
.then(SQLIdentifier("foo"), .descending)
27+
#expect(app.db.renderSQL(b) == #""id" ASC, "foo" DESC"#)
28+
}
2729
}
2830

29-
func test_OrderByGroup_complex() throws {
30-
let packageName = SQLIdentifier("package_name")
31-
let mergedTerms = SQLBind("a b")
32-
let score = SQLIdentifier("score")
33-
34-
let orderBy = SQLOrderBy(eq(lower(packageName), mergedTerms), .descending)
35-
.then(score, .descending)
36-
.then(packageName, .ascending)
37-
XCTAssertEqual(renderSQL(orderBy),
38-
#"LOWER("package_name") = $1 DESC, "score" DESC, "package_name" ASC"#)
31+
@Test func OrderByGroup_complex() async throws {
32+
try await withApp { app in
33+
let packageName = SQLIdentifier("package_name")
34+
let mergedTerms = SQLBind("a b")
35+
let score = SQLIdentifier("score")
36+
37+
let orderBy = SQLOrderBy(eq(lower(packageName), mergedTerms), .descending)
38+
.then(score, .descending)
39+
.then(packageName, .ascending)
40+
#expect(app.db.renderSQL(orderBy) == #"LOWER("package_name") = $1 DESC, "score" DESC, "package_name" ASC"#)
41+
}
3942
}
4043

4144
}

0 commit comments

Comments
 (0)