-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refactor Apple Wallet code (#76) #91
Merged
aahna-ashina
merged 24 commits into
nation3:main
from
aahna-ashina:dw-724/refactor-apple-wallet-code
Oct 31, 2022
Merged
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
df21a4d
refactor(apple): converting to/from milliseconds (#76)
aahna-ashina 293fc43
refactor(apple): add dateutils class (#76)
aahna-ashina f7d00b5
refactor(apple): add dateutils class (#76)
aahna-ashina e55ff6b
Merge branch 'main' into dw-724/refactor-apple-wallet-code
aahna-ashina ecf3d0c
refactor(apple):reduce the number of branches of code in [passTypeIde…
aahna-ashina 36f5e8d
refactor(apple): use await instead of asynchronous (#76)
aahna-ashina 68711f2
Merge branch 'main' into dw-724/refactor-apple-wallet-code
aahna-ashina 88aa387
refactor(apple): fix type error (#76)
aahna-ashina 4f66809
Merge remote-tracking branch 'upstream/main' into dw-724/refactor-app…
aahna-ashina 2ceb307
Merge branch 'dw-724/refactor-apple-wallet-code' of https://github.co…
aahna-ashina eaa5568
test(apple): lower coverage threshold (#76)
aahna-ashina ff8cd3b
Merge branch 'pr/93' into pr/91
aahna-ashina 2b1dada
Revert "Merge branch 'pr/93' into pr/91"
aahna-ashina ad068c0
docs(apple): update confirmation json
aahna-ashina 09ab583
chore(apple): add template version 4 (#76)
aahna-ashina 55ebf85
Merge branch 'main' into dw-724/refactor-apple-wallet-code
aahna-ashina 8f8b829
refactor(apple): separate apn provider code (#76)
aahna-ashina 2ac3a80
add missing template files
aahna-ashina 11faaae
Update jest.config.js
aahna-ashina faad5e6
Update Config.ts
aahna-ashina 59c28e6
test(apple): add unit test for v4 of the template
aahna-ashina bbfa591
refactor(apple): separate apn provider code (#76)
aahna-ashina 138492a
test(apple): mock apn provider during unit tests (#76)
aahna-ashina a62f5a1
Merge branch 'main' into dw-724/refactor-apple-wallet-code
aahna-ashina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ module.exports = { | |
testEnvironment: 'node', | ||
coverageThreshold: { | ||
global: { | ||
lines: 80.00 | ||
lines: 85.00 | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import apn, { Responses } from 'apn' | ||
import { config } from './Config' | ||
|
||
/** | ||
* Apple Push Notification (APN) provider. | ||
*/ | ||
export class APNProvider { | ||
|
||
static async sendNotification(pushToken: string): Promise<Responses> { | ||
console.info('[APNProvider.ts] sendNotification') | ||
|
||
const apnProvider: apn.Provider = new apn.Provider({ | ||
cert: `-----BEGIN CERTIFICATE-----\n${config.appleCertificatePEM}\n-----END CERTIFICATE-----`, | ||
key: `-----BEGIN RSA PRIVATE KEY-----\n${config.appleCertificateKey}\n-----END RSA PRIVATE KEY-----`, | ||
production: true | ||
}) | ||
const notification: apn.Notification = new apn.Notification(); | ||
notification.topic = 'pass.org.passport.nation3' | ||
console.info('[APNProvider.ts] Sending notification...') | ||
return await apnProvider.send(notification, pushToken) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import { DateUtils } from './DateUtils' | ||
|
||
describe('getTimeInSeconds', () => { | ||
test('getTimeInSeconds - 2022-09-30T04:12:17Z', () => { | ||
const date: Date = new Date('2022-09-30T04:12:17Z') | ||
console.log('date:', date) | ||
expect(DateUtils.getTimeInSeconds(date)).toBe(1664511137) | ||
}) | ||
|
||
test('getTimeInSeconds - 2022-09-30T04:12:17.000Z', () => { | ||
const date: Date = new Date('2022-09-30T04:12:17.000Z') | ||
console.log('date:', date) | ||
expect(DateUtils.getTimeInSeconds(date)).toBe(1664511137) | ||
}) | ||
|
||
test('getTimeInSeconds - 2022-09-30T04:12:17.499Z', () => { | ||
const date: Date = new Date('2022-09-30T04:12:17.499Z') | ||
console.log('date:', date) | ||
expect(DateUtils.getTimeInSeconds(date)).toBe(1664511137) | ||
}) | ||
|
||
test('getTimeInSeconds - 2022-09-30T04:12:17.500Z', () => { | ||
const date: Date = new Date('2022-09-30T04:12:17.500Z') | ||
console.log('date:', date) | ||
expect(DateUtils.getTimeInSeconds(date)).toBe(1664511138) | ||
}) | ||
}) | ||
|
||
describe('getDate', () => { | ||
test('getDate - 1662889385', () => { | ||
const date: Date = DateUtils.getDate(1662889385) | ||
console.log('date:', date) | ||
expect(date.toISOString()).toBe('2022-09-11T09:43:05.000Z') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export class DateUtils { | ||
|
||
/** | ||
* Calculates a Date's epoch timestamp in seconds. Rounds to the nearest integer to avoid decimals. | ||
*/ | ||
static getTimeInSeconds(date: Date): number { | ||
console.log('getTimeInSeconds') | ||
const timeInMilliseconds: number = date.getTime() | ||
const timeInSeconds: number = timeInMilliseconds / 1000 | ||
const timeInSecondsRoundedToNearestInteger: number = Math.round(timeInSeconds) | ||
return timeInSecondsRoundedToNearestInteger | ||
} | ||
|
||
/** | ||
* Converts from an epoch timestamp (e.g. 1662889385) to Date. | ||
* | ||
* @param timeInSeconds The UNIX timestamp in seconds, e.g. 1662889385. | ||
*/ | ||
static getDate(timeInSeconds: number): Date { | ||
console.log('getDate') | ||
const timeInMilliseconds: number = timeInSeconds * 1000 | ||
const date: Date = new Date(timeInMilliseconds) | ||
return date | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💪