Skip to content

Commit

Permalink
add status list tests and fix 404
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Sep 6, 2024
1 parent bf6f348 commit 4305f62
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ export async function build (opts = {}) {
})

app.get('/status/:statusCredentialId', async function (req, res, next) {
if (!enableStatusService) return res.status(405).send('The status service has not been enabled.')
if (!enableStatusService) next({ code: 405, message: 'The status service has not been enabled.' })
const statusCredentialId = req.params.statusCredentialId
try {
const { data: statusCredential } = await axios.get(`http://${statusService}/${statusCredentialId}`)
return res.status(200).json(statusCredential)
} catch (error) {
next({
message: error.message,
code: error.code
})
if (error.response.status === 404) {
next({ code: 404, message: 'No status credential found for that id.' })
} else {
next(error)
}
}
return res.status(500).send({ message: 'Server error.' })
})
Expand Down
23 changes: 23 additions & 0 deletions src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import protectedNock from './test-fixtures/nocks/protected_status_signing.js'
import unprotectedStatusUpdateNock from './test-fixtures/nocks/unprotected_status_update.js'
import unknownStatusIdNock from './test-fixtures/nocks/unknown_status_id_nock.js'
import protectedStatusUpdateNock from './test-fixtures/nocks/protected_status_update.js'
import unknownStatusListNock from './test-fixtures/nocks/unknown_status_list_nock.js'
import statusListNock from './test-fixtures/nocks/status_list_nock.js'

import { build } from './app.js'

Expand Down Expand Up @@ -227,4 +229,25 @@ describe('api', () => {
expect(response.status).to.equal(200)
})
})

describe('GET /status/:statusCredentialId', () => {
it('returns 404 for unknown status credential id', async () => {
unknownStatusListNock()
const response = await request(app)
.get('/status/9898u')
expect(response.header['content-type']).to.have.string('json')
expect(response.status).to.equal(404)
})

it('returns credential status list from status service', async () => {
statusListNock()
const response = await request(app)
.get('/status/slAwJe6GGR6mBojlGW5U')
expect(response.header['content-type']).to.have.string('json')
expect(response.status).to.equal(200)
const returnedList = JSON.parse(JSON.stringify(response.body))
// this proof value comes from the nock:
expect(returnedList.proof.proofValue).to.equal('z4y3GawinQg1aCqbYqZM8dmDpbmtFa3kE6tFefdXvLi5iby25dvmVwLNZrfcFPyhpshrhCWB76pdSZchVve3K1Znr')
})
})
})
34 changes: 34 additions & 0 deletions src/test-fixtures/nocks/status_list_nock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import nock from 'nock'

const theList = `{
"@context": [
"https://www.w3.org/ns/credentials/v2",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "https://sincere-bonefish-currently.ngrok-free.app/slAwJe6GGR6mBojlGW5U",
"type": [
"VerifiableCredential",
"BitstringStatusListCredential"
],
"credentialSubject": {
"id": "https://sincere-bonefish-currently.ngrok-free.app/slAwJe6GGR6mBojlGW5U#list",
"type": "BitstringStatusList",
"encodedList": "uH4sIAAAAAAAAA-3BIQEAAAACICf4f60vTEADAAAAAAAAAAAAAADwN_wEBkHUMAAA",
"statusPurpose": "revocation"
},
"issuer": "did:key:z6Mkg165pEHaUPxkY4NxToor7suxzawEmdT1DEWq3e1Nr2VR",
"validFrom": "2024-09-03T15:24:19.685Z",
"proof": {
"type": "Ed25519Signature2020",
"created": "2024-09-03T15:24:19Z",
"verificationMethod": "did:key:z6Mkg165pEHaUPxkY4NxToor7suxzawEmdT1DEWq3e1Nr2VR#z6Mkg165pEHaUPxkY4NxToor7suxzawEmdT1DEWq3e1Nr2VR",
"proofPurpose": "assertionMethod",
"proofValue": "z4y3GawinQg1aCqbYqZM8dmDpbmtFa3kE6tFefdXvLi5iby25dvmVwLNZrfcFPyhpshrhCWB76pdSZchVve3K1Znr"
}
}`

export default () => {
nock('http://localhost:4008')
.get('/slAwJe6GGR6mBojlGW5U')
.reply(200, theList)
}
7 changes: 7 additions & 0 deletions src/test-fixtures/nocks/unknown_status_list_nock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import nock from 'nock'

export default () => {
nock('http://localhost:4008')
.get('/9898u')
.reply(404, { code: 404, message: 'No status credential found for that id.' })
}

0 comments on commit 4305f62

Please sign in to comment.