Skip to content

Commit

Permalink
Fix DocC and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Jul 26, 2024
1 parent 52c2e9e commit 9651601
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Sources/Orders/Orders.docc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ final class OrderData: OrderDataModel, @unchecked Sendable {

struct CreateOrderData: AsyncMigration {
public func prepare(on database: Database) async throws {
try await database.schema(Self.schema)
try await database.schema(OrderData.schema)
.id()
.field("order_id", .uuid, .required, .references(Order.schema, .id, onDelete: .cascade))
.field("merchant_name", .string, .required)
.create()
}

public func revert(on database: Database) async throws {
try await database.schema(Self.schema).delete()
try await database.schema(OrderData.schema).delete()
}
}
```
Expand Down Expand Up @@ -157,7 +157,7 @@ final class OrderDelegate: OrdersDelegate {
### Initialize the Service

Next, initializes the ``OrdersService`` inside the `configure.swift` file.
Next, initialize the ``OrdersService`` inside the `configure.swift` file.
This will implement all of the routes that Apple Wallet expects to exist on your server.

```swift
Expand Down
4 changes: 2 additions & 2 deletions Sources/Passes/Passes.docc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class PassData: PassDataModel, @unchecked Sendable {

struct CreatePassData: AsyncMigration {
public func prepare(on database: Database) async throws {
try await database.schema(Self.schema)
try await database.schema(PassData.schema)
.id()
.field("pass_id", .uuid, .required, .references(PKPass.schema, .id, onDelete: .cascade))
.field("punches", .int, .required)
Expand All @@ -53,7 +53,7 @@ struct CreatePassData: AsyncMigration {
}

public func revert(on database: Database) async throws {
try await database.schema(Self.schema).delete()
try await database.schema(PassData.schema).delete()
}
}
```
Expand Down
16 changes: 8 additions & 8 deletions Tests/OrdersTests/OrderData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Orders
import Vapor

final class OrderData: OrderDataModel, @unchecked Sendable {
static let schema = OrderData.vddMMyyyy.schemaName
static let schema = OrderData.FieldKeys.schemaName

@ID(key: .id)
var id: UUID?

@Field(key: OrderData.vddMMyyyy.title)
@Field(key: OrderData.FieldKeys.title)
var title: String

@Parent(key: OrderData.vddMMyyyy.orderID)
@Parent(key: OrderData.FieldKeys.orderID)
var order: Order

init() { }
Expand Down Expand Up @@ -47,20 +47,20 @@ struct OrderDataDTO: Content {

struct CreateOrderData: AsyncMigration {
func prepare(on database: any Database) async throws {
try await database.schema(OrderData.vddMMyyyy.schemaName)
try await database.schema(OrderData.FieldKeys.schemaName)
.id()
.field(OrderData.vddMMyyyy.title, .string, .required)
.field(OrderData.vddMMyyyy.orderID, .uuid, .required, .references(Order.schema, .id, onDelete: .cascade))
.field(OrderData.FieldKeys.title, .string, .required)
.field(OrderData.FieldKeys.orderID, .uuid, .required, .references(Order.schema, .id, onDelete: .cascade))
.create()
}

func revert(on database: any Database) async throws {
try await database.schema(OrderData.vddMMyyyy.schemaName).delete()
try await database.schema(OrderData.FieldKeys.schemaName).delete()
}
}

extension OrderData {
enum vddMMyyyy {
enum FieldKeys {
static let schemaName = "order_data"
static let title = FieldKey(stringLiteral: "title")
static let orderID = FieldKey(stringLiteral: "order_id")
Expand Down
10 changes: 2 additions & 8 deletions Tests/OrdersTests/OrdersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ final class OrdersTests: XCTestCase {
app.databases.use(.sqlite(.memory), as: .sqlite)
OrdersService.register(migrations: app.migrations)
app.migrations.add(CreateOrderData())
let ordersService = try OrdersService(app: app, delegate: orderDelegate)
app.databases.middleware.use(OrderDataMiddleware(service: ordersService), on: .sqlite)
// let ordersService = try OrdersService(app: app, delegate: orderDelegate)
// app.databases.middleware.use(OrderDataMiddleware(service: ordersService), on: .sqlite)

try await app.autoMigrate()
}

override func tearDown() async throws {
try await app.autoRevert()
try await self.app.asyncShutdown()
self.app = nil
}
}
22 changes: 11 additions & 11 deletions Tests/PassesTests/PassData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import Passes
import Vapor

final class PassData: PassDataModel, @unchecked Sendable {
static let schema = PassData.vddMMyyyy.schemaName
static let schema = PassData.FieldKeys.schemaName

@ID(key: .id)
var id: UUID?

@Field(key: PassData.vddMMyyyy.title)
@Field(key: PassData.FieldKeys.title)
var title: String

@Parent(key: PassData.vddMMyyyy.passID)
@Parent(key: PassData.FieldKeys.passID)
var pass: PKPass

init() { }
Expand Down Expand Up @@ -47,20 +47,20 @@ struct PassDataDTO: Content {

struct CreatePassData: AsyncMigration {
func prepare(on database: any Database) async throws {
try await database.schema(PassData.vddMMyyyy.schemaName)
try await database.schema(PassData.FieldKeys.schemaName)
.id()
.field(PassData.vddMMyyyy.title, .string, .required)
.field(PassData.vddMMyyyy.passID, .uuid, .required, .references(PKPass.schema, .id, onDelete: .cascade))
.field(PassData.FieldKeys.title, .string, .required)
.field(PassData.FieldKeys.passID, .uuid, .required, .references(PKPass.schema, .id, onDelete: .cascade))
.create()
}

func revert(on database: any Database) async throws {
try await database.schema(PassData.vddMMyyyy.schemaName).delete()
try await database.schema(PassData.FieldKeys.schemaName).delete()
}
}

extension PassData {
enum vddMMyyyy {
enum FieldKeys {
static let schemaName = "pass_data"
static let title = FieldKey(stringLiteral: "title")
static let passID = FieldKey(stringLiteral: "pass_id")
Expand All @@ -71,13 +71,13 @@ struct PassJSONData: PassJSON.Properties {
let description: String
let formatVersion = PassJSON.FormatVersion.v1
let organizationName = "vapor-community"
let passTypeIdentifier = "pass.com.vapor-community.pass"
let passTypeIdentifier = "pass.com.vapor-community.PassKit"
let serialNumber: String
let teamIdentifier = "ABCD1234"

private let webServiceURL = "https://www.example.com/api/passes/"
private let authenticationToken: String
private let logoText = "Vapor"
private let logoText = "Vapor Community"
private let sharingProhibited = true
let backgroundColor = "rgb(207, 77, 243)"
let foregroundColor = "rgb(255, 255, 255)"
Expand Down Expand Up @@ -140,7 +140,7 @@ struct PassDataMiddleware: AsyncModelMiddleware {

func create(model: PassData, on db: any Database, next: any AnyAsyncModelResponder) async throws {
let pkPass = PKPass(
passTypeIdentifier: "pass.com.vapor-community.pass",
passTypeIdentifier: "pass.com.vapor-community.PassKit",
authenticationToken: Data([UInt8].random(count: 12)).base64EncodedString())
try await pkPass.save(on: db)
model.$pass.id = try pkPass.requireID()
Expand Down
10 changes: 2 additions & 8 deletions Tests/PassesTests/PassesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ final class PassesTests: XCTestCase {
app.databases.use(.sqlite(.memory), as: .sqlite)
PassesService.register(migrations: app.migrations)
app.migrations.add(CreatePassData())
let passesService = try PassesService(app: app, delegate: passDelegate)
app.databases.middleware.use(PassDataMiddleware(service: passesService), on: .sqlite)
// let passesService = try PassesService(app: app, delegate: passDelegate)
// app.databases.middleware.use(PassDataMiddleware(service: passesService), on: .sqlite)

try await app.autoMigrate()
}

override func tearDown() async throws {
try await app.autoRevert()
try await self.app.asyncShutdown()
self.app = nil
}
}

0 comments on commit 9651601

Please sign in to comment.