Skip to content

Commit

Permalink
Feature/cloudagent connection sync (#64)
Browse files Browse the repository at this point in the history
Sync cloudagent connection state with db
  • Loading branch information
mattdean-digicatapult authored Jun 20, 2024
1 parent b6c8043 commit 39f3b1c
Show file tree
Hide file tree
Showing 26 changed files with 1,316 additions and 72 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ services:
build:
context: .
dockerfile: Dockerfile
restart: no
restart: always
depends_on:
- postgres-veritable-ui-bob
- veritable-cloudagent-bob
Expand All @@ -90,6 +90,7 @@ services:
- DB_NAME=veritable-ui
- PUBLIC_URL=http://localhost:3001
- CLOUDAGENT_ADMIN_ORIGIN=http://veritable-cloudagent-bob:3000
- CLOUDAGENT_ADMIN_WS_ORIGIN=ws://veritable-cloudagent-bob:3000
- COOKIE_SESSION_KEYS=secret
- DB_PASSWORD=postgres
- DB_USERNAME=postgres
Expand Down
51 changes: 46 additions & 5 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "veritable-ui",
"version": "0.4.7",
"version": "0.5.0",
"description": "UI for Veritable",
"main": "src/index.ts",
"type": "module",
Expand Down Expand Up @@ -50,6 +50,7 @@
"swagger-ui-express": "^5.0.1",
"tsoa": "^6.3.1",
"tsyringe": "^4.8.0",
"ws": "^8.17.1",
"zod": "^3.23.8"
},
"devDependencies": {
Expand All @@ -65,12 +66,13 @@
"@types/sinon": "^17.0.3",
"@types/supertest": "^6.0.2",
"@types/swagger-ui-express": "^4.1.6",
"@types/ws": "^8.5.10",
"chai": "^5.1.1",
"chai-jest-snapshot": "^2.0.0",
"depcheck": "^1.4.7",
"mocha": "^10.4.0",
"prettier": "^3.3.2",
"pino-colada": "^2.2.2",
"prettier": "^3.3.2",
"prettier-plugin-organize-imports": "^3.2.4",
"sinon": "^18.0.0",
"supertest": "^7.0.0",
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/connection/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export const withNewConnectionMocks = () => {
const mockCloudagent = {
createOutOfBandInvite: ({ companyName }: { companyName: string }) => {
return {
invitation: {
id: `id-${companyName}`,
},
outOfBandRecord: { id: `id-${companyName}` },
invitationUrl: `url-${companyName}`,
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/connection/newConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class NewConnectionController extends HTMLController {
])

// insert the connection
const dbResult = await this.insertNewConnection(company, pinHash, invite.invitation.id, null)
const dbResult = await this.insertNewConnection(company, pinHash, invite.outOfBandRecord.id, null)
if (dbResult.type === 'error') {
return this.newInviteErrorHtml(dbResult.error, body.email, company.company_number)
}
Expand Down
1 change: 1 addition & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const envConfig = {
EMAIL_FROM_ADDRESS: envalid.email({ default: '[email protected]' }),
EMAIL_ADMIN_ADDRESS: envalid.email({ default: '[email protected]' }),
CLOUDAGENT_ADMIN_ORIGIN: envalid.url({ devDefault: 'http://localhost:3100' }),
CLOUDAGENT_ADMIN_WS_ORIGIN: envalid.url({ devDefault: 'ws://localhost:3100' }),
INVITATION_PIN_SECRET: envalid.str({ devDefault: 'secret' }),
INVITATION_FROM_COMPANY_NUMBER: envalid.str({ devDefault: '07964699' }),
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'reflect-metadata'

import { Express } from 'express'
import { container } from 'tsyringe'

import { Env } from './env.js'
import Server from './server.js'

import { logger } from './logger.js'
;(async () => {
const app: Express = await Server()
const { app } = await Server()

const env = container.resolve(Env)

app.listen(env.get('PORT'), () => {
Expand Down
23 changes: 13 additions & 10 deletions src/models/__tests__/fixtures/cloudagentFixtures.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
export const createInviteSuccessResponse = {
invitationUrl: 'example.com',
invitation: {
'@id': 'example-id',
},
}
import { pino } from 'pino'

export const createInviteSuccessResponseTransformed = {
export const createInviteSuccessResponse = {
invitationUrl: 'example.com',
invitation: {
id: 'example-id',
},
outOfBandRecord: { id: 'example-id' },
}

export const receiveInviteSuccessResponse = {
Expand All @@ -21,4 +14,14 @@ export const receiveInviteSuccessResponse = {
},
}

export const getConnectionsSuccessResponse = [
{
id: 'connection-id',
state: 'completed',
outOfBandId: 'oob-id',
},
]

export const invalidResponse = {}

export const mockLogger = pino({ level: 'silent' })
4 changes: 2 additions & 2 deletions src/models/__tests__/helpers/mockCloudagent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Env } from '../../../env.js'

const env = container.resolve(Env)

export function withCloudagentMock(path: string, code: number, responseBody: any) {
export function withCloudagentMock(method: 'GET' | 'POST' | 'DELETE', path: string, code: number, responseBody: any) {
let originalDispatcher: Dispatcher
let agent: MockAgent
beforeEach(function () {
Expand All @@ -17,7 +17,7 @@ export function withCloudagentMock(path: string, code: number, responseBody: any
client
.intercept({
path,
method: 'POST',
method,
})
.reply(code, responseBody)
})
Expand Down
Loading

0 comments on commit 39f3b1c

Please sign in to comment.