Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple Wallet: Implement support for the lastUpdated tag (#75) #86

Merged

Conversation

aahna-ashina
Copy link
Member

@aahna-ashina aahna-ashina commented Sep 29, 2022

Updates code to match the Response Codes at https://developer.apple.com/documentation/walletpasses/get_the_list_of_updatable_passes

200 Return Matching Passes
204 No Matching Passes

This prevents unnecessary downloads of unchanged data.

Dework Task

https://app.dework.xyz/nation3/passport-services-p?taskId=b479bb3a-cf2b-4322-b3fe-0eb720da8ad7

Related GitHub Issue

closes #75

How Has This Been Tested?

  • c5cb32f add lastUpdated to integration test
  • npm run cy:headless
  • Status checks pass
  • Tested pass updates (/api/pushLastUpdate) while observing Vercel logs, ensuring that no error message is received from Apple.

Integration Tests

npm run cy:headless
====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  index.cy.ts                              00:01        1        1        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  downloadPass.cy.ts                       00:09        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  pushLastUpdate.cy.ts                     515ms        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  [passTypeIdentifier].cy.ts               00:01        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  [serialNumber].cy.ts                     00:01        6        6        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  log.cy.ts                                499ms        2        2        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  [serialNumber].cy.ts                     00:01        5        5        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:16       28       28        -        -        -  

Are There Admin Tasks?

When the passesUpdatedSince parameter is not included, expect all serial numbers for the device to be returned.
@vercel
Copy link

vercel bot commented Sep 29, 2022

@aahna-ashina is attempting to deploy a commit to the Nation3 Team on Vercel.

A member of the Team first needs to authorize it.

@aahna-ashina aahna-ashina changed the title feat(apple): add lastUpdated to integration test (#75) Apple Wallet: Implement support for the lastUpdated tag (#75) Sep 29, 2022
@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2022

Codecov Report

Merging #86 (3435901) into main (7fa1eff) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main      #86   +/-   ##
=======================================
  Coverage   80.69%   80.69%           
=======================================
  Files           5        5           
  Lines         202      202           
  Branches       22       22           
=======================================
  Hits          163      163           
  Misses         38       38           
  Partials        1        1           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@aahna-ashina aahna-ashina marked this pull request as ready for review September 29, 2022 12:34
Expect HTTP 204 No Content when the passesUpdatedSince value is equal to or greather than the timestamp of the most recent update in the `latest_updates` database table.
} else {
res.status(204).end()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give the same feedback as ever, for me there are too many branches of code in here, and too many different return paths that make it tricky for the reader to follow what the code is doing. I would pull out some methods with names making it clear on the purpose and havea simple helper for the / 1000 and * 1000 code to avoid tripping up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmark13 Good feedback, thank you. Will fix 😀

Copy link
Member Author

@aahna-ashina aahna-ashina Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmark13 Just to get the functional solution deployed, I'm merging this PR. And I added your refactoring suggestions to #76. I'm working on those now, in a separate branch/PR.

@@ -65,12 +65,33 @@ 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
// Convert from ISO string to Date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up above you use .single and .limit(1) I do not think you need both, single will blow up if there is not 1 result, and will only return 1 result.

Copy link
Member Author

@aahna-ashina aahna-ashina Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmark13 Yes, I agree this seems redundant. However, without including .limit(1), it fails:

'Results contain 12 rows, application/vnd.pgrst.object+json requires 1 row'

I followed the code example in the documentation at https://supabase.com/docs/reference/javascript/single

@aahna-ashina aahna-ashina mentioned this pull request Oct 13, 2022
6 tasks
@aahna-ashina aahna-ashina merged commit ec77b14 into nation3:main Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apple Wallet: Implement support for the lastUpdated tag
4 participants