Skip to content

Commit

Permalink
feat: allow missing passesUpdatedSince parameter (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina committed Sep 6, 2022
1 parent 9b71e6e commit 80a62c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
17 changes: 3 additions & 14 deletions server/cypress/e2e/api/apple/[passTypeIdentifier].cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,10 @@ describe('Get the List of Updatable Passes', () => {
})
})

it('error when missing passesUpdatedSince parameter', () => {
cy.request({
method: 'GET',
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('Missing/empty parameter: passesUpdatedSince')
})
})

it('204 when unknown deviceLibraryIdentifier', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/devices/b00e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3?passesUpdatedSince={previousLastUpdated}',
url: '/api/apple/v1/devices/b00e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3',
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(204)
Expand All @@ -35,13 +24,13 @@ describe('Get the List of Updatable Passes', () => {
it('200 when existing deviceLibraryIdentifier', () => {
cy.request({
method: 'GET',
url: '/api/apple/v1/devices/b33e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3?passesUpdatedSince={previousLastUpdated}',
url: '/api/apple/v1/devices/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 values
// TODO: verify serial number value(s)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion server/cypress/e2e/api/apple/[serialNumber].cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Register a Pass for Update Notifications', () => {
})

it('success when deviceLibraryIdentifier is not already registered', () => {
const randomDeviceLibraryIdentifier : string = crypto.randomBytes(32).toString('hex')
const randomDeviceLibraryIdentifier : string = 'cypress_' + crypto.randomBytes(16).toString('hex')
cy.request({
method: 'POST',
url: '/api/apple/v1/devices/' + randomDeviceLibraryIdentifier + '/registrations/pass.org.passport.nation3/333',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
console.log('[passTypeIdentifier].ts')

// Expected URL format:
// /api/apple/v1/devices/[deviceLibraryIdentifier]/registrations/[passTypeIdentifier]?passesUpdatedSince=[passesUpdatedSince]
// /api/apple/v1/devices/b33e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3?passesUpdatedSince=0
// /api/apple/v1/devices/[deviceLibraryIdentifier]/registrations/[passTypeIdentifier]
// /api/apple/v1/devices/b33e3a3dccb3030333e3333da33333a3/registrations/pass.org.passport.nation3
console.log('req.url:', req.url)

try {
Expand All @@ -26,15 +26,11 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
console.log('deviceLibraryIdentifier:', deviceLibraryIdentifier)
console.log('passesUpdatedSince:', passesUpdatedSince)

// Validate the passesUpdatedSince parameter
if (!passesUpdatedSince || String(passesUpdatedSince).trim().length == 0) {
throw new Error('Missing/empty parameter: passesUpdatedSince')
}

// Lookup the serial numbers for the given device
supabase
.from('registrations')
.select('serial_number').eq('device_library_identifier', deviceLibraryIdentifier)
.select('serial_number')
.eq('device_library_identifier', deviceLibraryIdentifier)
.then((result: any) => {
console.log('result:', result)
if (result.error) {
Expand All @@ -57,7 +53,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
// Return matching passes (serial numbers)
res.status(200).json({
serialNumbers: serialNumbers,
lastUpdated: 0 // TODO
lastUpdated: 'TODO'
})
}
}
Expand Down

0 comments on commit 80a62c0

Please sign in to comment.