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

Send template updates to Apple Wallet passes (#6) #73

Merged
merged 45 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5762a0b
feat(apple): log a message (#72)
aahna-ashina Sep 5, 2022
e61226c
test(cypress): test /api/apple/v1/log (#72)
aahna-ashina Sep 6, 2022
9949666
test(cypress): test /api/apple/v1/log (#72)
aahna-ashina Sep 6, 2022
9b71e6e
feat: get the list of updatable passes (#6)
aahna-ashina Sep 6, 2022
80a62c0
feat: allow missing passesUpdatedSince parameter (#6)
aahna-ashina Sep 6, 2022
7a28c59
refactor: fetch template version from config (#6)
aahna-ashina Sep 6, 2022
6fab905
Merge branch 'main' into dw-58/send-template-updates-to
aahna-ashina Sep 6, 2022
aaa4090
test(cypress): update test data (#6)
aahna-ashina Sep 6, 2022
9683cee
Merge branch 'dw-58/send-template-updates-to' of https://github.com/a…
aahna-ashina Sep 6, 2022
f7d5e47
feat(apple): send an updated pass (#6)
aahna-ashina Sep 6, 2022
d6eadcb
Merge branch 'main' into dw-58/send-template-updates-to
aahna-ashina Sep 6, 2022
0b79dae
feat(apple): send an updated pass (#6)
aahna-ashina Sep 7, 2022
9f853c7
test(apple): send an updated pass (#6)
aahna-ashina Sep 7, 2022
61cf805
refactor: github workflows
aahna-ashina Sep 7, 2022
6e14a36
docs(metrics): add north star metric to pr template
aahna-ashina Sep 7, 2022
a05caf7
chore(deps): bump web3 from 1.7.3 to 1.7.5 in /server
aahna-ashina Sep 7, 2022
4a7b8b8
chore(deps): bump google-auth-library from 8.0.2 to 8.5.1 in /server
aahna-ashina Sep 7, 2022
ec05a78
docs: add test checklist
aahna-ashina Sep 7, 2022
ef9a065
refactor: rename templateFormatVersion (#6)
aahna-ashina Sep 7, 2022
e2854f4
refactor: rename from download to generate (#6)
aahna-ashina Sep 7, 2022
7746528
refactor: rename to issueDate (#6)
aahna-ashina Sep 7, 2022
5af5e57
test(apple): generatePass (#6)
aahna-ashina Sep 7, 2022
9dd6b5f
test: reduce coverage threshold to 80% (#6)
aahna-ashina Sep 7, 2022
659d80c
Update pull_request_template.md
aahna-ashina Sep 8, 2022
90afce2
feat(apple): store pass details during download (#6)
aahna-ashina Sep 8, 2022
beb8718
refactor (#6)
aahna-ashina Sep 8, 2022
97bcfa3
feat(apple): store template version during registration (#6)
aahna-ashina Sep 8, 2022
3feadd1
test: add codecov badge
aahna-ashina Sep 8, 2022
7e423d9
Merge branch 'main' into dw-58/send-template-updates-to
aahna-ashina Sep 8, 2022
a8f6f52
feat(apple): store template version during registration (#6)
aahna-ashina Sep 9, 2022
cbfb085
feat(apple): use templateVersion as passesUpdatedSince (#6)
aahna-ashina Sep 9, 2022
7e0beaf
feat(apple): get pass details from downloads table (#6)
aahna-ashina Sep 9, 2022
4991d07
feat(apple): add template v3 (#6)
aahna-ashina Sep 10, 2022
832c734
feat(apple): set latest nation3 update (#6)
aahna-ashina Sep 10, 2022
21032c2
feat(apple): store latest_updates in database (#6)
aahna-ashina Sep 11, 2022
ed3c128
feat(apple): set latest nation3 update (#6)
aahna-ashina Sep 11, 2022
42ef3cf
test: include webservice url for debugging (#6)
aahna-ashina Sep 11, 2022
f722672
feat(apple): return lastUpdated as string (#6)
aahna-ashina Sep 11, 2022
848304e
feat(apple): return http 200 when serial number is already registered…
aahna-ashina Sep 12, 2022
0943c3d
test(apple): apple template v3 (#6)
aahna-ashina Sep 12, 2022
50c28f3
test(apple): remove debugging from back field (#6)
aahna-ashina Sep 12, 2022
43ec3c4
refactor: update goerli domain
aahna-ashina Sep 12, 2022
2e04076
chore(apple): update goerli url (#6)
aahna-ashina Sep 12, 2022
6799a63
Merge remote-tracking branch 'upstream/main' into dw-58/send-template…
aahna-ashina Sep 12, 2022
1032a01
Merge pull request #71
aahna-ashina Sep 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

<!--- Please describe in detail how you tested your changes. -->

- [ ] Status checks pass
- [ ] Works on Goerli
- [ ] Works on Mainnet

## Are There Admin Tasks?

<!--- Please include any related admin tasks, like adding/changing environment variables in Vercel. -->
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and Lint

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

defaults:
run:
working-directory: server

strategy:
matrix:
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: server/package-lock.json
- run: npm install

- run: npm run build
- run: npm run lint
34 changes: 34 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Integration Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

defaults:
run:
working-directory: server

strategy:
matrix:
node-version: [16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: server/package-lock.json
- run: npm install

- run: cp .env.local.goerli .env.local
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably rename these files as .local is not usually checked into a repository, not a big deal though.

Copy link
Member Author

Choose a reason for hiding this comment

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

- run: npm run e2e:headless
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI
name: Unit Tests

on:
push:
Expand Down Expand Up @@ -32,10 +29,7 @@ jobs:
cache: 'npm'
cache-dependency-path: server/package-lock.json
- run: npm install
- run: npm run build
- run: npm run lint

- run: npm run test
- run: npm run test:coverage
- uses: codecov/codecov-action@v3
- run: cp .env.local.goerli .env.local
- run: npm run e2e:headless
9 changes: 9 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Run unit tests:
npm run test
```

## Code Coverage

[![codecov](https://codecov.io/gh/nation3/mobile-passport/branch/main/graph/badge.svg)](https://codecov.io/gh/nation3/mobile-passport)

Run code coverage:
```
npm run test:coverage
```

## Add the file with local environment variables

```
Expand Down
38 changes: 38 additions & 0 deletions server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe('Get the List of Updatable Passes', () => {

it('error when wrong request method (POST instead of GET)', () => {
cy.request({
method: 'POST',
url: '/api/apple/v1/devices/b33e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3',
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(400)
expect(JSON.stringify(response.body)).to.contain('Request Not Authorized: Wrong request method')
})
})

it('204 when unknown deviceLibraryIdentifier', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/devices/cypress_b00e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3',
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(204)
})
})

it('200 when existing deviceLibraryIdentifier', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/devices/cypress_b33e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3',
failOnStatusCode: false
}).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)
})
})
})

export {}
32 changes: 32 additions & 0 deletions server/cypress/e2e/api/apple/log.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe('Log a Message', () => {

it('error when wrong request method (GET instead of POST)', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/log',
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(401)
expect(JSON.stringify(response.body)).to.contain('Request Not Authorized: Wrong request method')
})
})

it('success when POST request', () => {
cy.request({
method: 'POST',
url: '/api/apple/v1/log',
body: {
logs: [
'[2022-09-06 09:14:07 +0800] Get serial #s task (for device b33e3a3dccb3030333e3333da33333a3, pass type pass.org.passport.nation3, last updated (null); with web service url https://passports.nation3.org/api/apple) encountered error: Unexpected response code 404',
'[2022-09-06 09:14:07 +0800] Get serial #s task (for device b33e3a3dccb3030333e3333da33333a3, pass type pass.org.passport.nation3, last updated (null); with web service url https://passports.nation3.org/api/apple) encountered error: Unexpected response code 404'
]
},
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(200)
expect(JSON.stringify(response.body)).to.contain('OK')
})
})
})

export {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import crypto from 'crypto'

describe('Send an Updated Pass', () => {

it('error when wrong request method (POST instead of GET)', () => {
cy.request({
method: 'POST',
url: '/api/apple/v1/passes/pass.org.passport.nation3/333',
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(401)
expect(JSON.stringify(response.body)).to.contain('Request Not Authorized: Wrong request method')
})
})

it('error when authentication token missing in header', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/passes/pass.org.passport.nation3/333',
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(401)
expect(JSON.stringify(response.body)).to.contain('Request Not Authorized: Missing/empty header: Authorization')
})
})

it('success when valid authentication token in header', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/passes/pass.org.passport.nation3/333',
headers: {
'Authorization': 'ApplePass 0x3fbeb3ae33af3fb33f3d33333303d333a333aff33f3133efbc3330333adb333a'
},
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(200)
expect(response.headers).to.include({
'content-type': 'application/vnd.apple.pkpass'
})
})
})
})

export {}
4 changes: 3 additions & 1 deletion server/cypress/e2e/api/downloadPass.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ describe('/api/downloadPass', () => {
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(200)
// expect(JSON.stringify(response.body)).to.contain('Invalid signature')
expect(response.headers).to.include({
'content-type': 'application/vnd.apple.pkpass'
})
})
})
})
Expand Down
11 changes: 11 additions & 0 deletions server/db-migrations/0.7.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create type platform as enum ('Apple', 'Google');
create table downloads (
id bigint generated by default as identity primary key,
time_of_download timestamp without time zone default now() not null,
platform platform not null,
template_version int not null,
passport_id bigint not null,
issue_date timestamp without time zone not null,
address text not null,
ens_name text
);
2 changes: 2 additions & 0 deletions server/db-migrations/0.8.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
delete from registrations;
alter table registrations add column template_version int not null;
2 changes: 1 addition & 1 deletion server/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export interface GooglePass extends Pass {

export enum Platform {
Apple,
Google,
Google
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a Prettier change?

Copy link
Member Author

@aahna-ashina aahna-ashina Sep 13, 2022

Choose a reason for hiding this comment

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

@johnmark13 No, haven't added Prettier config yet. Maybe we should? Added it to #76

}
2 changes: 1 addition & 1 deletion server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
testEnvironment: 'node',
coverageThreshold: {
global: {
lines: 18.55
lines: 80.00
Copy link
Contributor

Choose a reason for hiding this comment

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

💪

}
}
}
Loading