Skip to content

Commit

Permalink
add did generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Sep 9, 2024
1 parent a0c7285 commit 2c3358a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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 didWebGeneratorNock from './test-fixtures/nocks/did-web-generator.js'
import didKeyGeneratorNock from './test-fixtures/nocks/did-key-generator.js'


Check failure on line 15 in src/app.test.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

More than 1 blank line not allowed
import { build } from './app.js'

Expand Down Expand Up @@ -250,4 +253,42 @@ describe('api', () => {
expect(returnedList.proof.proofValue).to.equal('z4y3GawinQg1aCqbYqZM8dmDpbmtFa3kE6tFefdXvLi5iby25dvmVwLNZrfcFPyhpshrhCWB76pdSZchVve3K1Znr')
})
})

describe('/did-web-generator', () => {
it('returns a new did:web', async () => {
didWebGeneratorNock()
await request(app)
.post(`/did-web-generator`)

Check failure on line 261 in src/app.test.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Strings must use singlequote
.send({
url: 'https://raw.githubusercontent.com/jchartrand/didWebTest/main'
})
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.seed).to.exist

Check failure on line 267 in src/app.test.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Expected an assignment or function call and instead saw an expression
expect(res.body.didDocument.id).to.eql(
'did:web:raw.githubusercontent.com:jchartrand:didWebTest:main'
)
expect(res.body.did).to.eql(
'did:web:raw.githubusercontent.com:jchartrand:didWebTest:main'
)
})
.expect(200)
})
})

describe('/did-key-generator', () => {
it('returns a new did:key', async () => {
didKeyGeneratorNock()
await request(app)
.get(`/did-key-generator`)

Check failure on line 283 in src/app.test.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Strings must use singlequote
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.seed).to.exist

Check failure on line 286 in src/app.test.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Expected an assignment or function call and instead saw an expression
expect(res.body.didDocument.id).to.contain('did:key')
expect(res.body.did).to.contain('did:key')
})
.expect(200)
})
})

Check failure on line 292 in src/app.test.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Block must not be padded by blank lines

})
25 changes: 25 additions & 0 deletions src/test-fixtures/nocks/did-key-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import nock from 'nock'

export default () => {

Check failure on line 3 in src/test-fixtures/nocks/did-key-generator.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Block must not be padded by blank lines

Check failure on line 3 in src/test-fixtures/nocks/did-key-generator.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Trailing spaces not allowed

nock('http://localhost:4006', {"encodedQueryParams":true})

Check failure on line 5 in src/test-fixtures/nocks/did-key-generator.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

A space is required after '{'

Check failure on line 5 in src/test-fixtures/nocks/did-key-generator.js

View workflow job for this annotation

GitHub Actions / lint (16.x)

Unnecessarily quoted property 'encodedQueryParams' found
.get('/did-key-generator')
.reply(200, {"seed":"z1Ak67saZZnW6e41kw8dFNgWPQC7kb4MgmKrB5Saj9fTQtR","decodedSeed":{"0":204,"1":42,"2":201,"3":165,"4":122,"5":6,"6":144,"7":61,"8":229,"9":222,"10":134,"11":94,"12":219,"13":6,"14":191,"15":210,"16":103,"17":71,"18":241,"19":109,"20":215,"21":216,"22":2,"23":72,"24":19,"25":144,"26":20,"27":32,"28":178,"29":172,"30":81,"31":82},"did":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","didDocument":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/suites/ed25519-2020/v1","https://w3id.org/security/suites/x25519-2020/v1"],"id":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","verificationMethod":[{"id":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","type":"Ed25519VerificationKey2020","controller":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","publicKeyMultibase":"z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"}],"authentication":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"assertionMethod":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"capabilityDelegation":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"capabilityInvocation":["did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha"],"keyAgreement":[{"id":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha#z6LScqycbURGxJztJiSkK6MKZJhujV7PygbA2BHexuriMAdr","type":"X25519KeyAgreementKey2020","controller":"did:key:z6Mkq5Vr5kEEUF6M8U7AgSKBVppXyNQBoWnyb1vMqedzN3ha","publicKeyMultibase":"z6LScqycbURGxJztJiSkK6MKZJhujV7PygbA2BHexuriMAdr"}]}}, [
'X-Powered-By',
'Express',
'Access-Control-Allow-Origin',
'*',
'Content-Type',
'application/json; charset=utf-8',
'Content-Length',
'1776',
'ETag',
'W/"6f0-JdoCppKv4nbnXnQDbZJxlFrXG7o"',
'Date',
'Mon, 09 Sep 2024 18:06:31 GMT',
'Connection',
'keep-alive',
'Keep-Alive',
'timeout=5'
]);
}
25 changes: 25 additions & 0 deletions src/test-fixtures/nocks/did-web-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import nock from 'nock'

export default () => {

nock('http://localhost:4006', {"encodedQueryParams":true})
.post('/did-web-generator', {"url":"https://raw.githubusercontent.com/jchartrand/didWebTest/main"})
.reply(200, {"seed":"z1AhHNg9RSiUrjKAeTLXeYjJG5xE4fyZsxfFwKkXM4PhPMn","decodedSeed":{"0":162,"1":121,"2":218,"3":124,"4":128,"5":83,"6":6,"7":120,"8":155,"9":52,"10":67,"11":214,"12":9,"13":96,"14":98,"15":108,"16":249,"17":187,"18":45,"19":240,"20":184,"21":177,"22":120,"23":176,"24":189,"25":125,"26":247,"27":38,"28":7,"29":64,"30":91,"31":77},"did":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main","didDocument":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/suites/ed25519-2020/v1","https://w3id.org/security/suites/x25519-2020/v1"],"id":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main","assertionMethod":[{"id":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main#z6Mkoy5dFU7xajPV2QGEif1cz43To6go9Yhtf1T39TXCSMrS","type":"Ed25519VerificationKey2020","controller":"did:web:raw.githubusercontent.com:jchartrand:didWebTest:main","publicKeyMultibase":"z6Mkoy5dFU7xajPV2QGEif1cz43To6go9Yhtf1T39TXCSMrS"}]}}, [
'X-Powered-By',
'Express',
'Access-Control-Allow-Origin',
'*',
'Content-Type',
'application/json; charset=utf-8',
'Content-Length',
'957',
'ETag',
'W/"3bd-+yFc27zaIMTPRG+dm/pWiYDTumc"',
'Date',
'Mon, 09 Sep 2024 17:55:01 GMT',
'Connection',
'keep-alive',
'Keep-Alive',
'timeout=5'
]);
}

0 comments on commit 2c3358a

Please sign in to comment.