• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

digitalcredentials / transaction-service / 9286441376

29 May 2024 12:52PM UTC coverage: 85.61%. First build
9286441376

Pull #7

github

jchartrand
write lcov file; update actions
Pull Request #7: add healthz endpoint

36 of 48 branches covered (75.0%)

Branch coverage included in aggregate %.

191 of 243 new or added lines in 5 files covered. (78.6%)

434 of 501 relevant lines covered (86.63%)

2.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.03
/src/app.js
1
import express from 'express'
1✔
2
import logger from 'morgan'
1✔
3
import cors from 'cors'
1✔
4
import axios from 'axios'
1✔
5
import {
1✔
6
  initializeTransactionManager,
1✔
7
  setupExchange,
1✔
8
  retrieveStoredData,
1✔
9
  getVPR
1✔
10
} from './transactionManager.js'
1✔
11
import { getDataForExchangeSetupPost } from './test-fixtures/testData.js'
1✔
12
import { getSignedDIDAuth } from './didAuth.js'
1✔
13
import TransactionException from './TransactionException.js'
1✔
14

1✔
15
export async function build() {
1✔
16
  await initializeTransactionManager()
7✔
17

7✔
18
  var app = express()
7✔
19

7✔
20
  app.use(logger('dev'))
7✔
21
  app.use(express.json())
7✔
22
  app.use(express.urlencoded({ extended: false }))
7✔
23
  app.use(cors())
7✔
24

7✔
25
  app.get('/', function (req, res) {
7✔
26
    res.send({ message: 'transaction-service server status: ok.' })
1✔
27
  })
7✔
28

7✔
29
  app.get('/healthz', async function (req, res) {
7✔
30
    const baseURL = `${req.protocol}://${req.headers.host}`
2✔
31
    const testData = getDataForExchangeSetupPost('test', baseURL)
2✔
32
    const exchangeURL = `${baseURL}/exchange`
2✔
33
    try {
2✔
34
      const response = await axios.post(exchangeURL, testData)
2✔
35
      const { data: walletQuerys } = response
1✔
36
      const walletQuery = walletQuerys.find((q) => q.retrievalId === 'someId')
1✔
37
      const parsedDeepLink = new URL(walletQuery.directDeepLink)
1✔
38
      const requestURI = parsedDeepLink.searchParams.get('vc_request_url')
1✔
39
      const challenge = parsedDeepLink.searchParams.get('challenge')
1✔
40
      const didAuth = await getSignedDIDAuth('did:ex:223234', challenge)
1✔
41
      const { data } = await axios.post(requestURI, didAuth)
1✔
42
      const { tenantName, vc: unSignedVC } = data
1✔
43
      if (
1✔
44
        !tenantName === 'test' ||
1✔
45
        !unSignedVC.name === 'A Simply Wonderful Course'
1✔
46
      ) {
2!
NEW
47
        throw new TransactionException(
×
NEW
48
          503,
×
NEW
49
          'transaction-service healthz failed'
×
NEW
50
        )
×
NEW
51
      }
×
52
    } catch (e) {
2✔
53
      console.log(`exception in healthz: ${JSON.stringify(e)}`)
1✔
54
      return res.status(503).json({
1✔
55
        error: `transaction-service healthz check failed with error: ${e}`,
1✔
56
        healthy: false
1✔
57
      })
1✔
58
    }
1✔
59
    res.send({
1✔
60
      message: 'transaction-service server status: ok.',
1✔
61
      healthy: true
1✔
62
    })
1✔
63
  })
7✔
64

7✔
65
  /*
7✔
66
    This is step 1 in an exchange.
7✔
67
    Creates a new exchange and stores the provided data
7✔
68
    for later use in the exchange, in particular the subject data
7✔
69
    with which to later construct the VC.
7✔
70
    Returns a walletQuery object with both deeplinks
7✔
71
    with which to trigger wallet selection that in turn
7✔
72
    will trigger the exchange when the wallet opens.
7✔
73
    */
7✔
74
  app.post('/exchange', async (req, res) => {
7✔
75
    try {
4✔
76
      const data = req.body
4✔
77
      if (!data || !Object.keys(data).length)
4✔
78
        return res
4✔
79
          .status(400)
1✔
80
          .send({ code: 400, message: 'No data was provided in the body.' })
1✔
81
      const walletQuerys = await setupExchange(data)
3✔
82
      return res.json(walletQuerys)
2✔
83
    } catch (error) {
4✔
84
      console.log(error)
1✔
85
      return res.status(error.code || 500).json(error)
1✔
86
    }
1✔
87
  })
7✔
88

7✔
89
  /*
7✔
90
     This is step 2 in an exchange, where the wallet
7✔
91
     has asked to initiate the exchange, and we reply
7✔
92
     here with a Verifiable Presentation Request, asking
7✔
93
     for a DIDAuth. Note that in some scenarios the wallet
7✔
94
     may skip this step and directly present the DIDAuth.
7✔
95
    */
7✔
96
  app.post('/exchange/:exchangeId', async (req, res) => {
7✔
NEW
97
    try {
×
NEW
98
      const vpr = await getVPR(req.params.exchangeId)
×
NEW
99
      return res.json(vpr)
×
NEW
100
    } catch (error) {
×
NEW
101
      console.log(error)
×
NEW
102
      return res.status(error.code || 500).json(error)
×
NEW
103
    }
×
104
  })
7✔
105

7✔
106
  /*
7✔
107
   This is step 3 in an exchange, where we verify the
7✔
108
   supplied DIDAuth, and if verified we return the previously 
7✔
109
   stored data for the exchange.
7✔
110
   */
7✔
111
  app.post('/exchange/:exchangeId/:transactionId', async (req, res) => {
7✔
112
    try {
1✔
113
      const didAuth = req.body
1✔
114
      const data = await retrieveStoredData(
1✔
115
        req.params.exchangeId,
1✔
116
        req.params.transactionId,
1✔
117
        didAuth
1✔
118
      )
1✔
119
      return res.json(data)
1✔
120
    } catch (error) {
1!
NEW
121
      console.log(error)
×
NEW
122
      return res.status(error.code || 500).json(error)
×
NEW
123
    }
×
124
  })
7✔
125

7✔
126
  return app
7✔
127
}
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc