Skip to content

Commit

Permalink
test(cypress): test /api/apple/v1/log (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahna-ashina committed Sep 6, 2022
1 parent 5762a0b commit e61226c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
30 changes: 30 additions & 0 deletions server/cypress/e2e/api/apple/log.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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')
})
})
})
3 changes: 1 addition & 2 deletions server/pages/api/apple/v1/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
throw new Error('Wrong request method: ' + req.method)
}

// Extract log entries from the request body (application/json)
// Display the log entries in the request body (application/json)
console.log('req.body:', req.body)
// TODO

res.status(200).json({
message: 'OK'
Expand Down

0 comments on commit e61226c

Please sign in to comment.