Skip to content

Commit dc97f44

Browse files
committed
Remove AppTestCase and move pieces into individual files
1 parent b32d42b commit dc97f44

File tree

5 files changed

+193
-196
lines changed

5 files changed

+193
-196
lines changed

Tests/AppTests/ApiTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Dependencies
1818
import PackageCollectionsSigning
1919
import SnapshotTesting
2020
import Testing
21-
import Vapor
21+
import XCTVapor
2222

2323

2424
@Suite struct ApiTests {

Tests/AppTests/AppTestCase.swift

Lines changed: 0 additions & 192 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
@testable import App
18+
19+
import Fluent
20+
import SQLKit
21+
22+
23+
// FIXME: Check if we can just create a PostgresDB object from scratch rather than using withApp and app.db for this at the call site (i.e. check if these need to be extensions on Database). That does a whole migration + reset just to render the SQL needlessly.
24+
extension Database {
25+
func renderSQL(_ builder: SQLSelectBuilder) -> String {
26+
renderSQL(builder.query)
27+
}
28+
29+
func renderSQL(_ query: SQLExpression) -> String {
30+
var serializer = SQLSerializer(database: self as! SQLDatabase)
31+
query.serialize(to: &serializer)
32+
return serializer.sql
33+
}
34+
35+
func binds(_ builder: SQLSelectBuilder?) -> [String] {
36+
binds(builder?.query)
37+
}
38+
39+
func binds(_ query: SQLExpression?) -> [String] {
40+
var serializer = SQLSerializer(database: self as! SQLDatabase)
41+
query?.serialize(to: &serializer)
42+
return serializer.binds.reduce(into: []) { result, bind in
43+
switch bind {
44+
case let bind as Date:
45+
result.append(DateFormatter.filterParseFormatter.string(from: bind))
46+
case let bind as Set<Package.PlatformCompatibility>:
47+
let s = bind.map(\.rawValue).sorted().joined(separator: ",")
48+
result.append("{\(s)}")
49+
case let bind as Set<ProductTypeSearchFilter.ProductType>:
50+
let s = bind.map(\.rawValue).sorted().joined(separator: ",")
51+
result.append("{\(s)}")
52+
default:
53+
result.append("\(bind)")
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)