Skip to content

Commit

Permalink
Improve APNS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Aug 20, 2024
1 parent a4e5312 commit 6584435
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
25 changes: 23 additions & 2 deletions Tests/OrdersTests/OrdersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ final class OrdersTests: XCTestCase {
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.sendPushNotifications(for: order, 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,
Expand All @@ -180,6 +180,27 @@ final class OrdersTests: XCTestCase {
XCTAssertEqual(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
XCTAssertEqual(res.status, .created)
}
)

try await app.test(
.POST,
"\(ordersURI)push/\(order.orderTypeIdentifier)/\(order.requireID())",
headers: ["X-Secret": "foo"],
afterResponse: { res async throws in
XCTAssertEqual(res.status, .internalServerError)
}
)
}

func testOrdersError() {
Expand Down
25 changes: 23 additions & 2 deletions Tests/PassesTests/PassesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ final class PassesTests: XCTestCase {
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.sendPushNotifications(for: pass, 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,
Expand All @@ -266,6 +266,27 @@ final class PassesTests: XCTestCase {
XCTAssertEqual(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
XCTAssertEqual(res.status, .created)
}
)

try await app.test(
.POST,
"\(passesURI)push/\(pass.passTypeIdentifier)/\(pass.requireID())",
headers: ["X-Secret": "foo"],
afterResponse: { res async throws in
XCTAssertEqual(res.status, .internalServerError)
}
)
}

func testPassesError() {
Expand Down

0 comments on commit 6584435

Please sign in to comment.