-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59cee89
commit 398127e
Showing
6 changed files
with
141 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,12 @@ final class PassesTests: XCTestCase { | |
|
||
PassesService.register(migrations: app.migrations) | ||
app.migrations.add(CreatePassData()) | ||
passesService = try PassesService(app: app, delegate: passDelegate, pushRoutesMiddleware: SecretMiddleware(secret: "foo")) | ||
passesService = try PassesService( | ||
app: app, | ||
delegate: passDelegate, | ||
pushRoutesMiddleware: SecretMiddleware(secret: "foo"), | ||
logger: app.logger | ||
) | ||
app.databases.middleware.use(PassDataMiddleware(service: passesService), on: .sqlite) | ||
|
||
try await app.autoMigrate() | ||
|
@@ -57,6 +62,67 @@ final class PassesTests: XCTestCase { | |
XCTAssertGreaterThan(dataPersonalize.count, data.count) | ||
} | ||
|
||
// Tests the API Apple Wallet calls to get passes | ||
func testGetPassFromAPI() async throws { | ||
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 app.test( | ||
.GET, | ||
"\(passesURI)passes/\(pass.passTypeIdentifier)/\(pass.requireID())", | ||
headers: ["Authorization": "ApplePass \(pass.authenticationToken)", "If-Modified-Since": "0"], | ||
afterResponse: { res async throws in | ||
XCTAssertEqual(res.status, .ok) | ||
XCTAssertNotNil(res.body) | ||
XCTAssertEqual(res.headers.contentType?.description, "application/vnd.apple.pkpass") | ||
XCTAssertNotNil(res.headers.lastModified) | ||
} | ||
) | ||
} | ||
|
||
func testPersonalizationAPI() async throws { | ||
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: "[email protected]", | ||
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 | ||
XCTAssertEqual(res.status, .ok) | ||
XCTAssertNotNil(res.body) | ||
XCTAssertEqual(res.headers.contentType?.description, "application/octet-stream") | ||
} | ||
) | ||
|
||
let personalizationQuery = try await UserPersonalization.query(on: app.db).all() | ||
XCTAssertEqual(personalizationQuery.count, 1) | ||
XCTAssertEqual(personalizationQuery[0].emailAddress, personalizationDict.requiredPersonalizationInfo.emailAddress) | ||
XCTAssertEqual(personalizationQuery[0].familyName, personalizationDict.requiredPersonalizationInfo.familyName) | ||
XCTAssertEqual(personalizationQuery[0].fullName, personalizationDict.requiredPersonalizationInfo.fullName) | ||
XCTAssertEqual(personalizationQuery[0].givenName, personalizationDict.requiredPersonalizationInfo.givenName) | ||
XCTAssertEqual(personalizationQuery[0].ISOCountryCode, personalizationDict.requiredPersonalizationInfo.ISOCountryCode) | ||
XCTAssertEqual(personalizationQuery[0].phoneNumber, personalizationDict.requiredPersonalizationInfo.phoneNumber) | ||
XCTAssertEqual(personalizationQuery[0].postalCode, personalizationDict.requiredPersonalizationInfo.postalCode) | ||
} | ||
|
||
func testAPIDeviceRegistration() async throws { | ||
let passData = PassData(title: "Test Pass") | ||
try await passData.create(on: app.db) | ||
|
@@ -72,7 +138,6 @@ final class PassesTests: XCTestCase { | |
try req.content.encode(RegistrationDTO(pushToken: pushToken)) | ||
}, | ||
afterResponse: { res async throws in | ||
XCTAssertNotEqual(res.status, .unauthorized) | ||
XCTAssertEqual(res.status, .created) | ||
} | ||
) | ||
|
@@ -85,7 +150,6 @@ final class PassesTests: XCTestCase { | |
try req.content.encode(RegistrationDTO(pushToken: pushToken)) | ||
}, | ||
afterResponse: { res async throws in | ||
XCTAssertNotEqual(res.status, .unauthorized) | ||
XCTAssertEqual(res.status, .ok) | ||
} | ||
) | ||
|
@@ -118,7 +182,6 @@ final class PassesTests: XCTestCase { | |
"\(passesURI)devices/\(deviceLibraryIdentifier)/registrations/\(pass.passTypeIdentifier)/\(pass.requireID())", | ||
headers: ["Authorization": "ApplePass \(pass.authenticationToken)"], | ||
afterResponse: { res async throws in | ||
XCTAssertNotEqual(res.status, .unauthorized) | ||
XCTAssertEqual(res.status, .ok) | ||
} | ||
) | ||
|
@@ -151,5 +214,14 @@ final class PassesTests: XCTestCase { | |
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 app.test( | ||
.POST, | ||
"\(passesURI)push/\(pass.passTypeIdentifier)/\(pass.requireID())", | ||
headers: ["X-Secret": "foo"], | ||
afterResponse: { res async throws in | ||
XCTAssertEqual(res.status, .noContent) | ||
} | ||
) | ||
} | ||
} |