From f722672ab9b161eefbdfe2ee68e4fcaf8a8fa454 Mon Sep 17 00:00:00 2001 From: aahna-ashina <95955389+aahna-ashina@users.noreply.github.com> Date: Sun, 11 Sep 2022 18:47:46 +0800 Subject: [PATCH] feat(apple): return lastUpdated as string (#6) Return `lastUpdated` as string instead of number, adhering to the Apple documentation: https://developer.apple.com/documentation/walletpasses/serialnumbers --- server/TEMPLATE_UPDATE.md | 2 +- server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts | 4 ++-- .../registrations/[passTypeIdentifier].ts | 5 ++--- .../apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts | 2 +- server/pages/api/downloadPass.ts | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/server/TEMPLATE_UPDATE.md b/server/TEMPLATE_UPDATE.md index c6218f9..9aefce7 100644 --- a/server/TEMPLATE_UPDATE.md +++ b/server/TEMPLATE_UPDATE.md @@ -8,7 +8,7 @@ This document explains, step-by-step, how to update the template of a pass. 1. Commit the changes 1. Make your changes in the new folder 1. Commit the changes -1. Change the `appleTemplateVersion` in `utils/Config.ts` +1. Increase the `appleTemplateVersion` in `utils/Config.ts` 1. Test that the new pass is successfully generated by making a `[GET]` request to `http://localhost:3000/api/downloadPass` (see full request example in `cypress/e2e/api/apple/downloadPass.cy.ts`) 1. Test that it works to open the generated `.pkpass` file on an iOS device 1. Commit the changes diff --git a/server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts b/server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts index dcf4e9d..dfe6e53 100644 --- a/server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts +++ b/server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts @@ -29,8 +29,8 @@ describe('Get the List of Updatable Passes', () => { }).then((response) => { expect(response.status).to.eq(200) expect(JSON.stringify(response.body)).to.contain('serialNumbers') - expect(JSON.stringify(response.body)).to.contain('lastUpdated') // TODO: verify serial number value(s) + expect(JSON.stringify(response.body)).to.contain('lastUpdated') }) }) @@ -42,8 +42,8 @@ describe('Get the List of Updatable Passes', () => { }).then((response) => { expect(response.status).to.eq(200) expect(JSON.stringify(response.body)).to.contain('serialNumbers') - expect(JSON.stringify(response.body)).to.contain('lastUpdated') // TODO: verify serial number value(s) + expect(JSON.stringify(response.body)).to.contain('lastUpdated') }) }) }) diff --git a/server/pages/api/apple/v1/devices/[deviceLibraryIdentifier]/registrations/[passTypeIdentifier].ts b/server/pages/api/apple/v1/devices/[deviceLibraryIdentifier]/registrations/[passTypeIdentifier].ts index 3196582..6249894 100644 --- a/server/pages/api/apple/v1/devices/[deviceLibraryIdentifier]/registrations/[passTypeIdentifier].ts +++ b/server/pages/api/apple/v1/devices/[deviceLibraryIdentifier]/registrations/[passTypeIdentifier].ts @@ -65,12 +65,11 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { error: 'Internal Server Error: ' + latest_updates_result.error.message }) } else { + // Return matching passes (serial numbers) and their modification time const latestUpdateDate: Date = new Date(latest_updates_result.data['time']) - - // Return matching passes (serial numbers) res.status(200).json({ serialNumbers: serialNumbers, - lastUpdated: Math.round(latestUpdateDate.getTime() / 1000) + lastUpdated: String(Math.round(latestUpdateDate.getTime() / 1000)) }) } }) diff --git a/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts b/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts index 0de2225..efa3289 100644 --- a/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts +++ b/server/pages/api/apple/v1/passes/[passTypeIdentifier]/[serialNumber].ts @@ -76,7 +76,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { } else { const latestUpdateDate: Date = new Date(latest_updates_result.data['time']) const latestUpdateTitle: string = latest_updates_result.data['title'] - const latestUpdateContent: string = latest_updates_result.data['content'] + '\r\n\r\n' + config.appleWebServiceUrl + const latestUpdateContent: string = latest_updates_result.data['content'] + '\r\n\r\nwebServiceURL: ' + config.appleWebServiceUrl // Populate the pass template const platform: Platform = Platform.Apple diff --git a/server/pages/api/downloadPass.ts b/server/pages/api/downloadPass.ts index b9997d3..43e863f 100644 --- a/server/pages/api/downloadPass.ts +++ b/server/pages/api/downloadPass.ts @@ -135,7 +135,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) { } else { const latestUpdateDate: Date = new Date(latest_updates_result.data['time']) const latestUpdateTitle: string = latest_updates_result.data['title'] - const latestUpdateContent: string = latest_updates_result.data['content'] + '\r\n\r\n' + config.appleWebServiceUrl + const latestUpdateContent: string = latest_updates_result.data['content'] + '\r\n\r\nwebServiceURL: ' + config.appleWebServiceUrl // Populate the pass template const filePath: string = Passes.generatePass(