Skip to content

Commit

Permalink
Add more tests for auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Aug 20, 2024
1 parent 6684b88 commit acd12dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Tests/OrdersTests/OrdersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ final class OrdersTests: XCTestCase {
let deviceLibraryIdentifier = "abcdefg"
let pushToken = "1234567890"

// Test registration without authentication token
try await app.test(
.POST,
"\(ordersURI)devices/\(deviceLibraryIdentifier)/registrations/\(order.orderTypeIdentifier)/\(order.requireID())",
beforeRequest: { req async throws in
try req.content.encode(RegistrationDTO(pushToken: pushToken))
},
afterResponse: { res async throws in
XCTAssertEqual(res.status, .unauthorized)
}
)

try await app.test(
.POST,
"\(ordersURI)devices/\(deviceLibraryIdentifier)/registrations/\(order.orderTypeIdentifier)/\(order.requireID())",
Expand All @@ -98,6 +110,7 @@ final class OrdersTests: XCTestCase {
}
)

// Test registration of an already registered device
try await app.test(
.POST,
"\(ordersURI)devices/\(deviceLibraryIdentifier)/registrations/\(order.orderTypeIdentifier)/\(order.requireID())",
Expand Down Expand Up @@ -169,6 +182,9 @@ 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.sendPushNotificationsForOrder(id: order.requireID(), of: order.orderTypeIdentifier, on: app.db)

let deviceLibraryIdentifier = "abcdefg"
let pushToken = "1234567890"

Expand Down
16 changes: 16 additions & 0 deletions Tests/PassesTests/PassesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ final class PassesTests: XCTestCase {
let deviceLibraryIdentifier = "abcdefg"
let pushToken = "1234567890"

// Test registration without authentication token
try await app.test(
.POST,
"\(passesURI)devices/\(deviceLibraryIdentifier)/registrations/\(pass.passTypeIdentifier)/\(pass.requireID())",
beforeRequest: { req async throws in
try req.content.encode(RegistrationDTO(pushToken: pushToken))
},
afterResponse: { res async throws in
XCTAssertEqual(res.status, .unauthorized)
}
)

try await app.test(
.POST,
"\(passesURI)devices/\(deviceLibraryIdentifier)/registrations/\(pass.passTypeIdentifier)/\(pass.requireID())",
Expand All @@ -184,6 +196,7 @@ final class PassesTests: XCTestCase {
}
)

// Test registration of an already registered device
try await app.test(
.POST,
"\(passesURI)devices/\(deviceLibraryIdentifier)/registrations/\(pass.passTypeIdentifier)/\(pass.requireID())",
Expand Down Expand Up @@ -255,6 +268,9 @@ 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.sendPushNotificationsForPass(id: pass.requireID(), of: pass.passTypeIdentifier, on: app.db)

let deviceLibraryIdentifier = "abcdefg"
let pushToken = "1234567890"

Expand Down

0 comments on commit acd12dc

Please sign in to comment.