Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellenn-A committed Dec 18, 2023
1 parent 68079d7 commit e4f55df
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/veritable-cloudagent",
"version": "0.4.5",
"version": "0.4.6",
"main": "build/index",
"types": "build/index",
"files": [
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/credentials/CredentialController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AcceptCredentialOfferOptions,
CreateOfferOptions,
} from '../types'
import { option } from 'yargs'

Check warning on line 17 in src/controllers/credentials/CredentialController.ts

View workflow job for this annotation

GitHub Actions / Run lint

'option' is defined but never used

@Tags('Credentials')
@Route('/credentials')
Expand Down Expand Up @@ -198,12 +199,17 @@ export class CredentialController extends Controller {
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
try {
//check connection exists
const connection = await this.agent.connections.findById(options.connectionId)
if (!connection)
return notFoundError(404, { reason: `connection with connection id "${options.connectionId}" not found.` })

const credential = await this.agent.credentials.offerCredential(options)
return credential.toJSON()
} catch (error) {
if (error instanceof RecordNotFoundError) {
return notFoundError(404, {
reason: `connection with connection record id "${options.connectionId}" not found.`,
reason: `the credential definition id "${options.credentialFormats.anoncreds?.credentialDefinitionId}" not found.`,
})
}
return internalServerError(500, { message: `something went wrong: ${error}` })
Expand Down
2 changes: 1 addition & 1 deletion src/routes/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@
},
"info": {
"title": "@digicatapult/veritable-cloudagent",
"version": "0.4.5",
"version": "0.4.6",
"description": "Rest endpoint wrapper for using your agent over HTTP",
"license": {
"name": "Apache-2.0"
Expand Down
16 changes: 14 additions & 2 deletions tests/credential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect, use as chaiUse, Assertion as assertion } from 'chai'
import chaiAssertionsCount from 'chai-assertions-count'
import { stub, restore as sinonRestore } from 'sinon'

import type { Agent, CredentialStateChangedEvent, OutOfBandRecord } from '@aries-framework/core'
import type { Agent, ConnectionRecord, CredentialStateChangedEvent, OutOfBandRecord } from '@aries-framework/core'
import type { Server } from 'net'

import {
Expand All @@ -22,7 +22,14 @@ import WebSocket from 'ws'

import { startServer } from '../src'

import { objectToJson, getTestCredential, getTestAgent, getTestOffer, getTestOutOfBandRecord } from './utils/helpers'
import {
objectToJson,
getTestCredential,
getTestAgent,
getTestOffer,
getTestOutOfBandRecord,
getTestConnection,
} from './utils/helpers'

chaiUse(chaiAssertionsCount)

Expand All @@ -36,6 +43,7 @@ describe('CredentialController', () => {
credentialRecord: CredentialExchangeRecord
}
let outOfBandRecord: OutOfBandRecord
let connection: ConnectionRecord

before(async () => {
aliceAgent = await getTestAgent('Credential REST Agent Test Alice', 3022)
Expand All @@ -45,6 +53,7 @@ describe('CredentialController', () => {
testCredential = getTestCredential() as CredentialExchangeRecord
testOffer = getTestOffer()
outOfBandRecord = getTestOutOfBandRecord()
connection = getTestConnection()
})

beforeEach(() => {
Expand Down Expand Up @@ -527,8 +536,11 @@ describe('CredentialController', () => {
}

test('should return credential record', async () => {
const findByIdStub = stub(bobAgent.connections, 'findById')
findByIdStub.resolves(connection)
const offerCredentialStub = stub(bobAgent.credentials, 'offerCredential')
offerCredentialStub.resolves(testCredential)

const getResult = (): Promise<CredentialExchangeRecord> => offerCredentialStub.firstCall.returnValue

const response = await request(app).post(`/credentials/offer-credential`).send(offerRequest)
Expand Down

0 comments on commit e4f55df

Please sign in to comment.