diff --git a/Tests/OrdersTests/EncryptedOrdersDelegate.swift b/Tests/OrdersTests/EncryptedOrdersDelegate.swift deleted file mode 100644 index 0db2b01..0000000 --- a/Tests/OrdersTests/EncryptedOrdersDelegate.swift +++ /dev/null @@ -1,31 +0,0 @@ -import FluentKit -import Orders -import Vapor - -final class EncryptedOrdersDelegate: OrdersDelegate { - func encode( - order: O, db: any Database, encoder: JSONEncoder - ) async throws -> Data { - guard - let orderData = try await OrderData.query(on: db) - .filter(\.$order.$id == order.requireID()) - .with(\.$order) - .first() - else { - throw Abort(.internalServerError) - } - guard let data = try? encoder.encode(OrderJSONData(data: orderData, order: orderData.order)) - else { - throw Abort(.internalServerError) - } - return data - } - - func template(for: O, db: any Database) async throws -> URL { - URL( - fileURLWithPath: - "\(FileManager.default.currentDirectoryPath)/Tests/OrdersTests/Templates/", - isDirectory: true - ) - } -} diff --git a/Tests/OrdersTests/EncryptedOrdersTests.swift b/Tests/OrdersTests/EncryptedOrdersTests.swift deleted file mode 100644 index 368b7dc..0000000 --- a/Tests/OrdersTests/EncryptedOrdersTests.swift +++ /dev/null @@ -1,92 +0,0 @@ -import FluentKit -import PassKit -import Testing -import XCTVapor -import Zip - -@testable import Orders - -@Suite("Orders Tests with Encrypted PEM Key") -struct EncryptedOrdersTests { - let delegate = EncryptedOrdersDelegate() - let ordersURI = "/api/orders/v1/" - - @Test("Order Generation") - func orderGeneration() async throws { - try await withApp(delegate: delegate) { app, ordersService in - let orderData = OrderData(title: "Test Order") - try await orderData.create(on: app.db) - let order = try await orderData.$order.get(on: app.db) - let data = try await ordersService.generateOrderContent(for: order, on: app.db) - let orderURL = FileManager.default.temporaryDirectory.appendingPathComponent("test.order") - try data.write(to: orderURL) - let orderFolder = try Zip.quickUnzipFile(orderURL) - - #expect(FileManager.default.fileExists(atPath: orderFolder.path.appending("/signature"))) - - let passJSONData = try String(contentsOfFile: orderFolder.path.appending("/order.json")).data(using: .utf8) - let passJSON = try JSONSerialization.jsonObject(with: passJSONData!) as! [String: Any] - #expect(passJSON["authenticationToken"] as? String == order.authenticationToken) - let orderID = try order.requireID().uuidString - #expect(passJSON["orderIdentifier"] as? String == orderID) - - let manifestJSONData = try String(contentsOfFile: orderFolder.path.appending("/manifest.json")).data(using: .utf8) - let manifestJSON = try JSONSerialization.jsonObject(with: manifestJSONData!) as! [String: Any] - let iconData = try Data(contentsOf: orderFolder.appendingPathComponent("/icon.png")) - let iconHash = Array(SHA256.hash(data: iconData)).hex - #expect(manifestJSON["icon.png"] as? String == iconHash) - } - } - - @Test("APNS Client") - func apnsClient() async throws { - try await withApp(delegate: delegate) { app, ordersService in - #expect(app.apns.client(.init(string: "orders")) != nil) - - let orderData = OrderData(title: "Test Order") - try await orderData.create(on: app.db) - let order = try await orderData._$order.get(on: app.db) - - try await ordersService.sendPushNotificationsForOrder(id: order.requireID(), of: order.orderTypeIdentifier, on: app.db) - - let deviceLibraryIdentifier = "abcdefg" - let pushToken = "1234567890" - - try await app.test( - .POST, - "\(ordersURI)push/\(order.orderTypeIdentifier)/\(order.requireID())", - headers: ["X-Secret": "foo"], - afterResponse: { res async throws in - #expect(res.status == .noContent) - } - ) - - try await app.test( - .POST, - "\(ordersURI)devices/\(deviceLibraryIdentifier)/registrations/\(order.orderTypeIdentifier)/\(order.requireID())", - headers: ["Authorization": "AppleOrder \(order.authenticationToken)"], - beforeRequest: { req async throws in - try req.content.encode(RegistrationDTO(pushToken: pushToken)) - }, - afterResponse: { res async throws in - #expect(res.status == .created) - } - ) - - try await app.test( - .POST, - "\(ordersURI)push/\(order.orderTypeIdentifier)/\(order.requireID())", - headers: ["X-Secret": "foo"], - afterResponse: { res async throws in - #expect(res.status == .internalServerError) - } - ) - - // Test `OrderDataMiddleware` update method - orderData.title = "Test Order 2" - do { - try await orderData.update(on: app.db) - } catch {} - } - } -} diff --git a/Tests/OrdersTests/OrderData.swift b/Tests/OrdersTests/OrderData.swift index 6733174..d51c128 100644 --- a/Tests/OrdersTests/OrderData.swift +++ b/Tests/OrdersTests/OrderData.swift @@ -89,7 +89,8 @@ struct OrderDataMiddleware: AsyncModelMiddleware { func create(model: OrderData, on db: any Database, next: any AnyAsyncModelResponder) async throws { let order = Order( orderTypeIdentifier: "order.com.example.pet-store", - authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString()) + authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString() + ) try await order.save(on: db) model.$order.id = try order.requireID() try await next.create(model, on: db) diff --git a/Tests/OrdersTests/OrdersTests.swift b/Tests/OrdersTests/OrdersTests.swift index 98a5317..fc8cad1 100644 --- a/Tests/OrdersTests/OrdersTests.swift +++ b/Tests/OrdersTests/OrdersTests.swift @@ -8,12 +8,11 @@ import Zip @Suite("Orders Tests") struct OrdersTests { - let delegate = TestOrdersDelegate() let ordersURI = "/api/orders/v1/" - @Test("Order Generation") - func orderGeneration() async throws { - try await withApp(delegate: delegate) { app, ordersService in + @Test("Order Generation", arguments: [true, false]) + func orderGeneration(useEncryptedKey: Bool) async throws { + try await withApp(useEncryptedKey: useEncryptedKey) { app, ordersService in let orderData = OrderData(title: "Test Order") try await orderData.create(on: app.db) let order = try await orderData.$order.get(on: app.db) @@ -41,7 +40,7 @@ struct OrdersTests { @Test("Getting Order from Apple Wallet API") func getOrderFromAPI() async throws { - try await withApp(delegate: delegate) { app, ordersService in + try await withApp { app, ordersService in let orderData = OrderData(title: "Test Order") try await orderData.create(on: app.db) let order = try await orderData.$order.get(on: app.db) @@ -117,7 +116,7 @@ struct OrdersTests { @Test("Device Registration API") func apiDeviceRegistration() async throws { - try await withApp(delegate: delegate) { app, ordersService in + try await withApp { app, ordersService in let orderData = OrderData(title: "Test Order") try await orderData.create(on: app.db) let order = try await orderData.$order.get(on: app.db) @@ -270,7 +269,7 @@ struct OrdersTests { @Test("Error Logging") func errorLog() async throws { - try await withApp(delegate: delegate) { app, ordersService in + try await withApp { app, ordersService in let log1 = "Error 1" let log2 = "Error 2" @@ -313,9 +312,9 @@ struct OrdersTests { } } - @Test("APNS Client") - func apnsClient() async throws { - try await withApp(delegate: delegate) { app, ordersService in + @Test("APNS Client", arguments: [true, false]) + func apnsClient(useEncryptedKey: Bool) async throws { + try await withApp(useEncryptedKey: useEncryptedKey) { app, ordersService in #expect(app.apns.client(.init(string: "orders")) != nil) let orderData = OrderData(title: "Test Order") @@ -397,16 +396,15 @@ struct OrdersTests { @Test("Default OrdersDelegate Properties") func defaultDelegate() { - #expect(!DefaultOrdersDelegate().generateSignatureFile(in: URL(fileURLWithPath: ""))) - } -} + final class DefaultOrdersDelegate: OrdersDelegate { + func template(for order: O, db: any Database) async throws -> URL { + URL(fileURLWithPath: "") + } + func encode(order: O, db: any Database, encoder: JSONEncoder) async throws -> Data { + Data() + } + } -final class DefaultOrdersDelegate: OrdersDelegate { - let sslSigningFilesDirectory = URL(fileURLWithPath: "", isDirectory: true) - func template(for order: O, db: any Database) async throws -> URL { - URL(fileURLWithPath: "") - } - func encode(order: O, db: any Database, encoder: JSONEncoder) async throws -> Data { - Data() + #expect(!DefaultOrdersDelegate().generateSignatureFile(in: URL(fileURLWithPath: ""))) } } diff --git a/Tests/OrdersTests/TestOrdersDelegate.swift b/Tests/OrdersTests/TestOrdersDelegate.swift index d6fa266..7fa2485 100644 --- a/Tests/OrdersTests/TestOrdersDelegate.swift +++ b/Tests/OrdersTests/TestOrdersDelegate.swift @@ -3,9 +3,7 @@ import Orders import Vapor final class TestOrdersDelegate: OrdersDelegate { - func encode( - order: O, db: any Database, encoder: JSONEncoder - ) async throws -> Data { + func encode(order: O, db: any Database, encoder: JSONEncoder) async throws -> Data { guard let orderData = try await OrderData.query(on: db) .filter(\.$order.$id == order.requireID()) @@ -14,18 +12,13 @@ final class TestOrdersDelegate: OrdersDelegate { else { throw Abort(.internalServerError) } - guard let data = try? encoder.encode(OrderJSONData(data: orderData, order: orderData.order)) - else { + guard let data = try? encoder.encode(OrderJSONData(data: orderData, order: orderData.order)) else { throw Abort(.internalServerError) } return data } func template(for: O, db: any Database) async throws -> URL { - URL( - fileURLWithPath: - "\(FileManager.default.currentDirectoryPath)/Tests/OrdersTests/Templates/", - isDirectory: true - ) + URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)/Tests/OrdersTests/Templates/", isDirectory: true) } } diff --git a/Tests/OrdersTests/withApp.swift b/Tests/OrdersTests/withApp.swift index 0185293..7f89cc2 100644 --- a/Tests/OrdersTests/withApp.swift +++ b/Tests/OrdersTests/withApp.swift @@ -7,7 +7,6 @@ import Vapor import Zip func withApp( - delegate: some OrdersDelegate, useEncryptedKey: Bool = false, _ body: (Application, OrdersService) async throws -> Void ) async throws { @@ -17,6 +16,8 @@ func withApp( app.databases.use(.sqlite(.memory), as: .sqlite) + let delegate = TestOrdersDelegate() + OrdersService.register(migrations: app.migrations) app.migrations.add(CreateOrderData()) let ordersService = try OrdersService( diff --git a/Tests/PassesTests/EncryptedPassesDelegate.swift b/Tests/PassesTests/EncryptedPassesDelegate.swift deleted file mode 100644 index 89b1365..0000000 --- a/Tests/PassesTests/EncryptedPassesDelegate.swift +++ /dev/null @@ -1,49 +0,0 @@ -import FluentKit -import Passes -import Vapor - -final class EncryptedPassesDelegate: PassesDelegate { - func encode( - pass: P, db: any Database, encoder: JSONEncoder - ) async throws -> Data { - guard - let passData = try await PassData.query(on: db) - .filter(\.$pass.$id == pass.requireID()) - .with(\.$pass) - .first() - else { - throw Abort(.internalServerError) - } - guard let data = try? encoder.encode(PassJSONData(data: passData, pass: passData.pass)) - else { - throw Abort(.internalServerError) - } - return data - } - - func personalizationJSON(for pass: P, db: any Database) async throws -> PersonalizationJSON? { - guard - let passData = try await PassData.query(on: db) - .filter(\.$pass.$id == pass.id!) - .with(\.$pass) - .first() - else { - throw Abort(.internalServerError) - } - - if passData.title != "Personalize" { return nil } - - if try await passData.pass.$userPersonalization.get(on: db) == nil { - return PersonalizationJSON( - requiredPersonalizationFields: [.name, .postalCode, .emailAddress, .phoneNumber], - description: "Hello, World!" - ) - } else { - return nil - } - } - - func template(for pass: P, db: any Database) async throws -> URL { - URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)/Tests/PassesTests/Templates/", isDirectory: true) - } -} diff --git a/Tests/PassesTests/EncryptedPassesTests.swift b/Tests/PassesTests/EncryptedPassesTests.swift deleted file mode 100644 index 8dea8c9..0000000 --- a/Tests/PassesTests/EncryptedPassesTests.swift +++ /dev/null @@ -1,139 +0,0 @@ -import PassKit -import Testing -import XCTVapor -import Zip - -@testable import Passes - -@Suite("Passes Tests with Encrypted PEM Key") -struct EncryptedPassesTests { - let delegate = EncryptedPassesDelegate() - let passesURI = "/api/passes/v1/" - - @Test("Pass Generation") - func passGeneration() async throws { - try await withApp(delegate: delegate, useEncryptedKey: true) { app, passesService in - let passData = PassData(title: "Test Pass") - try await passData.create(on: app.db) - let pass = try await passData.$pass.get(on: app.db) - let data = try await passesService.generatePassContent(for: pass, on: app.db) - let passURL = FileManager.default.temporaryDirectory.appendingPathComponent("test.pkpass") - try data.write(to: passURL) - let passFolder = try Zip.quickUnzipFile(passURL) - - #expect(FileManager.default.fileExists(atPath: passFolder.path.appending("/signature"))) - - let passJSONData = try String(contentsOfFile: passFolder.path.appending("/pass.json")).data(using: .utf8) - let passJSON = try JSONSerialization.jsonObject(with: passJSONData!) as! [String: Any] - #expect(passJSON["authenticationToken"] as? String == pass.authenticationToken) - let passID = try pass.requireID().uuidString - #expect(passJSON["serialNumber"] as? String == passID) - #expect(passJSON["description"] as? String == passData.title) - - let manifestJSONData = try String(contentsOfFile: passFolder.path.appending("/manifest.json")).data(using: .utf8) - let manifestJSON = try JSONSerialization.jsonObject(with: manifestJSONData!) as! [String: Any] - let iconData = try Data(contentsOf: passFolder.appendingPathComponent("/icon.png")) - let iconHash = Array(Insecure.SHA1.hash(data: iconData)).hex - #expect(manifestJSON["icon.png"] as? String == iconHash) - } - } - - @Test("Personalizable Pass Apple Wallet API") - func personalizationAPI() async throws { - try await withApp(delegate: delegate, useEncryptedKey: true) { app, passesService in - let passData = PassData(title: "Personalize") - try await passData.create(on: app.db) - let pass = try await passData.$pass.get(on: app.db) - let personalizationDict = PersonalizationDictionaryDTO( - personalizationToken: "1234567890", - requiredPersonalizationInfo: .init( - emailAddress: "test@example.com", - familyName: "Doe", - fullName: "John Doe", - givenName: "John", - isoCountryCode: "US", - phoneNumber: "1234567890", - postalCode: "12345" - ) - ) - - try await app.test( - .POST, - "\(passesURI)passes/\(pass.passTypeIdentifier)/\(pass.requireID())/personalize", - headers: ["Authorization": "ApplePass \(pass.authenticationToken)"], - beforeRequest: { req async throws in - try req.content.encode(personalizationDict) - }, - afterResponse: { res async throws in - #expect(res.status == .ok) - #expect(res.body != nil) - #expect(res.headers.contentType?.description == "application/octet-stream") - } - ) - - let personalizationQuery = try await UserPersonalization.query(on: app.db).all() - #expect(personalizationQuery.count == 1) - let passPersonalizationID = try await Pass.query(on: app.db).first()?._$userPersonalization.get(on: app.db)?.requireID() - #expect(personalizationQuery[0]._$id.value == passPersonalizationID) - #expect(personalizationQuery[0]._$emailAddress.value == personalizationDict.requiredPersonalizationInfo.emailAddress) - #expect(personalizationQuery[0]._$familyName.value == personalizationDict.requiredPersonalizationInfo.familyName) - #expect(personalizationQuery[0]._$fullName.value == personalizationDict.requiredPersonalizationInfo.fullName) - #expect(personalizationQuery[0]._$givenName.value == personalizationDict.requiredPersonalizationInfo.givenName) - #expect(personalizationQuery[0]._$isoCountryCode.value == personalizationDict.requiredPersonalizationInfo.isoCountryCode) - #expect(personalizationQuery[0]._$phoneNumber.value == personalizationDict.requiredPersonalizationInfo.phoneNumber) - #expect(personalizationQuery[0]._$postalCode.value == personalizationDict.requiredPersonalizationInfo.postalCode) - } - } - - @Test("APNS Client") - func apnsClient() async throws { - try await withApp(delegate: delegate, useEncryptedKey: true) { app, passesService in - #expect(app.apns.client(.init(string: "passes")) != nil) - - let passData = PassData(title: "Test Pass") - try await passData.create(on: app.db) - let pass = try await passData._$pass.get(on: app.db) - - try await passesService.sendPushNotificationsForPass(id: pass.requireID(), of: pass.passTypeIdentifier, on: app.db) - - let deviceLibraryIdentifier = "abcdefg" - let pushToken = "1234567890" - - try await app.test( - .POST, - "\(passesURI)push/\(pass.passTypeIdentifier)/\(pass.requireID())", - headers: ["X-Secret": "foo"], - afterResponse: { res async throws in - #expect(res.status == .noContent) - } - ) - - try await app.test( - .POST, - "\(passesURI)devices/\(deviceLibraryIdentifier)/registrations/\(pass.passTypeIdentifier)/\(pass.requireID())", - headers: ["Authorization": "ApplePass \(pass.authenticationToken)"], - beforeRequest: { req async throws in - try req.content.encode(RegistrationDTO(pushToken: pushToken)) - }, - afterResponse: { res async throws in - #expect(res.status == .created) - } - ) - - try await app.test( - .POST, - "\(passesURI)push/\(pass.passTypeIdentifier)/\(pass.requireID())", - headers: ["X-Secret": "foo"], - afterResponse: { res async throws in - #expect(res.status == .internalServerError) - } - ) - - // Test `PassDataMiddleware` update method - passData.title = "Test Pass 2" - do { - try await passData.update(on: app.db) - } catch {} - } - } -} diff --git a/Tests/PassesTests/PassData.swift b/Tests/PassesTests/PassData.swift index c2e4ff4..313d479 100644 --- a/Tests/PassesTests/PassData.swift +++ b/Tests/PassesTests/PassData.swift @@ -110,7 +110,8 @@ struct PassDataMiddleware: AsyncModelMiddleware { func create(model: PassData, on db: any Database, next: any AnyAsyncModelResponder) async throws { let pass = Pass( passTypeIdentifier: "pass.com.vapor-community.PassKit", - authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString()) + authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString() + ) try await pass.save(on: db) model.$pass.id = try pass.requireID() try await next.create(model, on: db) diff --git a/Tests/PassesTests/PassesTests.swift b/Tests/PassesTests/PassesTests.swift index 4717ace..c50921c 100644 --- a/Tests/PassesTests/PassesTests.swift +++ b/Tests/PassesTests/PassesTests.swift @@ -8,12 +8,11 @@ import Zip @Suite("Passes Tests") struct PassesTests { - let delegate = TestPassesDelegate() let passesURI = "/api/passes/v1/" - @Test("Pass Generation") - func passGeneration() async throws { - try await withApp(delegate: delegate) { app, passesService in + @Test("Pass Generation", arguments: [true, false]) + func passGeneration(useEncryptedKey: Bool) async throws { + try await withApp(useEncryptedKey: useEncryptedKey) { app, passesService in let passData = PassData(title: "Test Pass") try await passData.create(on: app.db) let pass = try await passData.$pass.get(on: app.db) @@ -43,7 +42,7 @@ struct PassesTests { @Test("Generating Multiple Passes") func passesGeneration() async throws { - try await withApp(delegate: delegate) { app, passesService in + try await withApp { app, passesService in let passData1 = PassData(title: "Test Pass 1") try await passData1.create(on: app.db) let pass1 = try await passData1.$pass.get(on: app.db) @@ -66,7 +65,7 @@ struct PassesTests { @Test("Personalizable Passes") func personalization() async throws { - try await withApp(delegate: delegate) { app, passesService in + try await withApp { app, passesService in let passData = PassData(title: "Personalize") try await passData.create(on: app.db) let pass = try await passData.$pass.get(on: app.db) @@ -96,7 +95,7 @@ struct PassesTests { @Test("Getting Pass from Apple Wallet API") func getPassFromAPI() async throws { - try await withApp(delegate: delegate) { app, passesService in + try await withApp { app, passesService in let passData = PassData(title: "Test Pass") try await passData.create(on: app.db) let pass = try await passData.$pass.get(on: app.db) @@ -170,9 +169,9 @@ struct PassesTests { } } - @Test("Personalizable Pass Apple Wallet API") - func personalizationAPI() async throws { - try await withApp(delegate: delegate) { app, passesService in + @Test("Personalizable Pass Apple Wallet API", arguments: [true, false]) + func personalizationAPI(useEncryptedKey: Bool) async throws { + try await withApp(useEncryptedKey: useEncryptedKey) { app, passesService in let passData = PassData(title: "Personalize") try await passData.create(on: app.db) let pass = try await passData.$pass.get(on: app.db) @@ -242,7 +241,7 @@ struct PassesTests { @Test("Device Registration API") func apiDeviceRegistration() async throws { - try await withApp(delegate: delegate) { app, passesService in + try await withApp { app, passesService in let passData = PassData(title: "Test Pass") try await passData.create(on: app.db) let pass = try await passData.$pass.get(on: app.db) @@ -395,7 +394,7 @@ struct PassesTests { @Test("Error Logging") func errorLog() async throws { - try await withApp(delegate: delegate) { app, passesService in + try await withApp { app, passesService in let log1 = "Error 1" let log2 = "Error 2" @@ -438,9 +437,9 @@ struct PassesTests { } } - @Test("APNS Client") - func apnsClient() async throws { - try await withApp(delegate: delegate) { app, passesService in + @Test("APNS Client", arguments: [true, false]) + func apnsClient(useEncryptedKey: Bool) async throws { + try await withApp(useEncryptedKey: useEncryptedKey) { app, passesService in #expect(app.apns.client(.init(string: "passes")) != nil) let passData = PassData(title: "Test Pass") @@ -523,10 +522,20 @@ struct PassesTests { @Test("Default PassesDelegate Properties") func defaultDelegate() async throws { + final class DefaultPassesDelegate: PassesDelegate { + let sslSigningFilesDirectory = URL(fileURLWithPath: "", isDirectory: true) + func template(for pass: P, db: any Database) async throws -> URL { + URL(fileURLWithPath: "") + } + func encode(pass: P, db: any Database, encoder: JSONEncoder) async throws -> Data { + Data() + } + } + let defaultDelegate = DefaultPassesDelegate() #expect(!defaultDelegate.generateSignatureFile(in: URL(fileURLWithPath: ""))) - try await withApp(delegate: delegate) { app, passesService in + try await withApp { app, passesService in let passData = PassData(title: "Test Pass") try await passData.create(on: app.db) let pass = try await passData.$pass.get(on: app.db) @@ -535,13 +544,3 @@ struct PassesTests { } } } - -final class DefaultPassesDelegate: PassesDelegate { - let sslSigningFilesDirectory = URL(fileURLWithPath: "", isDirectory: true) - func template(for pass: P, db: any Database) async throws -> URL { - URL(fileURLWithPath: "") - } - func encode(pass: P, db: any Database, encoder: JSONEncoder) async throws -> Data { - Data() - } -} diff --git a/Tests/PassesTests/TestPassesDelegate.swift b/Tests/PassesTests/TestPassesDelegate.swift index cd2af50..2d556bf 100644 --- a/Tests/PassesTests/TestPassesDelegate.swift +++ b/Tests/PassesTests/TestPassesDelegate.swift @@ -3,9 +3,7 @@ import Passes import Vapor final class TestPassesDelegate: PassesDelegate { - func encode( - pass: P, db: any Database, encoder: JSONEncoder - ) async throws -> Data { + func encode(pass: P, db: any Database, encoder: JSONEncoder) async throws -> Data { guard let passData = try await PassData.query(on: db) .filter(\.$pass.$id == pass.requireID()) @@ -14,8 +12,7 @@ final class TestPassesDelegate: PassesDelegate { else { throw Abort(.internalServerError) } - guard let data = try? encoder.encode(PassJSONData(data: passData, pass: passData.pass)) - else { + guard let data = try? encoder.encode(PassJSONData(data: passData, pass: passData.pass)) else { throw Abort(.internalServerError) } return data diff --git a/Tests/PassesTests/withApp.swift b/Tests/PassesTests/withApp.swift index 86e1a58..bb48255 100644 --- a/Tests/PassesTests/withApp.swift +++ b/Tests/PassesTests/withApp.swift @@ -7,7 +7,6 @@ import Vapor import Zip func withApp( - delegate: some PassesDelegate, useEncryptedKey: Bool = false, _ body: (Application, PassesService) async throws -> Void ) async throws { @@ -17,6 +16,8 @@ func withApp( app.databases.use(.sqlite(.memory), as: .sqlite) + let delegate = TestPassesDelegate() + PassesService.register(migrations: app.migrations) app.migrations.add(CreatePassData()) let passesService = try PassesService(