Skip to content

Commit

Permalink
Bugfix/vr 252 (#201)
Browse files Browse the repository at this point in the history
* VR-252: after testing aggregation of partial query.

* VR-252: working e2e (partial query).

* VR-252: before pushing unit tests.

* VR-252: updating existing unit tests.

* VR-252: adding new status to query table [forwarded].

* VR-252: adding forwarded status and test update.

* VR-252: include forwarded (branch switch).

* VR-252: queries controller update.

* VR-252: sanity check on queries controller.

* VR-252 xss-scan escaping html.

* VR-252: version bump.

* VR-252: failing test.

* VR-252: snapshot update.

* VR-252: a few deduplications.{

* VR-252: clean up of queries controller after deduplications.

* VR-252: logging.

* VR-252: a few typos from a saga of queries controller.

* VR-252: deconstruction of payload.

* VR-252: addressing github comments.

* VR-252: unit tests.

* VR-252: forgotten check for POST /stage.

* VR-252: linting.

* VR-258: check if all child queries have responded before responding to parent.

* VR-252: pushing integration test in the current state.

* VR-252: tmp skip failing test.

* Update docker-compose.yml

Co-authored-by: David Blane <[email protected]>

* VR-252: syntax.

* VR-252: calculating allChilds.reduce for total emissions.

* VR-252: integration tests for partial query include charlie (3rd persona)

* VR-252: some unstagged changes from integration test.

* VR-252: typo.

* VR-252: expand on queries unit test.

* VR-252: added a couple of unit tests for DRPC and partial.

* VR-252: removing and adding new comments.:

* VR-252: accidentally stagged types.d.ts which should not be included (was a test).

---------

Co-authored-by: David Blane <[email protected]>
  • Loading branch information
n3op2 and dblane-digicatapult authored Oct 22, 2024
1 parent c75d22f commit 5add30b
Show file tree
Hide file tree
Showing 22 changed files with 958 additions and 298 deletions.
15 changes: 9 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ services:
- DB_NAME=veritable-ui
- API_SWAGGER_TITLE=Bob
- API_SWAGGER_BG_COLOR=#ff3131
- PUBLIC_URL=${VERITABLE_BOB_PUBLIC_URL:-http://localhost:3001}
- PUBLIC_URL=${VERITABLE_BOB_PUBLIC_URL:-http://localhost:3000}
- CLOUDAGENT_ADMIN_ORIGIN=http://veritable-cloudagent-bob:3000
- CLOUDAGENT_ADMIN_WS_ORIGIN=ws://veritable-cloudagent-bob:3000
- COMPANY_HOUSE_API_URL=https://api.company-information.service.gov.uk
Expand Down Expand Up @@ -219,20 +219,20 @@ services:
npm start | pino-colada"
environment:
- NODE_ENV=production
- LOG_LEVEL=trace
- LOG_LEVEL=debug
- DB_HOST=postgres-veritable-ui-charlie
- DB_NAME=veritable-ui
- API_SWAGGER_TITLE=Charlie
- API_SWAGGER_BG_COLOR=#ffbd59
- PUBLIC_URL=http://localhost:3002
- PUBLIC_URL=${VERITABLE_CHARLIE_PUBLIC_URL:-http://localhost:3000}
- CLOUDAGENT_ADMIN_ORIGIN=http://veritable-cloudagent-charlie:3000
- CLOUDAGENT_ADMIN_WS_ORIGIN=ws://veritable-cloudagent-charlie:3000
- COMPANY_HOUSE_API_URL=https://api.company-information.service.gov.uk
- COOKIE_SESSION_KEYS=secret
- DB_PASSWORD=postgres
- DB_USERNAME=postgres
- IDP_CLIENT_ID=veritable-ui
- IDP_PUBLIC_URL_PREFIX=http://localhost:3080/realms/veritable/protocol/openid-connect
- IDP_PUBLIC_URL_PREFIX=${VERITABLE_IDP_PUBLIC_URL_PREFIX:-http://localhost:3080/realms/veritable/protocol/openid-connect}
- IDP_INTERNAL_URL_PREFIX=http://keycloak:8080/realms/veritable/protocol/openid-connect
- INVITATION_FROM_COMPANY_NUMBER=10016023
- INVITATION_PIN_SECRET=secret
Expand All @@ -241,10 +241,13 @@ services:
- ISSUANCE_CRED_DEF_POLICY=EXISTING_OR_NEW
- DEMO_MODE=true
- SMTP_HOST=smtp4dev
- SMTP_PASS=
- SMTP_PASS=password
- SMTP_PORT=25
- SMTP_USER=
- SMTP_USER=username
- EMAIL_TRANSPORT=SMTP_EMAIL
- SMTP_SECURE=false
- COMPANY_PROFILE_API_KEY=${VERITABLE_COMPANY_PROFILE_API_KEY:-API_KEY}

postgres-veritable-ui-charlie:
image: postgres:17.0-alpine
container_name: postgres-veritable-ui-charlie
Expand Down
1 change: 1 addition & 0 deletions docker/e2e.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VERITABLE_ALICE_PUBLIC_URL=http://veritable-ui-alice:3000
VERITABLE_BOB_PUBLIC_URL=http://veritable-ui-bob:3000
VERITABLE_CHARLIE_PUBLIC_URL=http://veritable-ui-charlie:3000
VERITABLE_IDP_PUBLIC_URL_PREFIX=http://keycloak:8080/realms/veritable/protocol/openid-connect
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": "veritable-ui",
"version": "0.11.12",
"version": "0.12.0",
"description": "UI for Veritable",
"main": "src/index.ts",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/queries/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import QueryListTemplates from '../../../views/queries/queriesList.js'
import Scope3CarbonConsumptionTemplates from '../../../views/queries/requestCo2scope3.js'
import Scope3CarbonConsumptionResponseTemplates, { Scope3FormProps } from '../../../views/queries/responseCo2scope3.js'

type QueryStatus = 'resolved' | 'pending_your_input' | 'pending_their_input'
type QueryStatus = 'resolved' | 'pending_your_input' | 'pending_their_input' | 'forwarded'

interface Query {
company_name: string
Expand Down
103 changes: 88 additions & 15 deletions src/controllers/queries/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('QueriesController', () => {
})

it('should call page with stage success as expected', async () => {
const { args } = withQueriesMocks()
const { dbMock, args } = withQueriesMocks()
const controller = new QueriesController(...args)
const result = await controller
.scope3CarbonConsumptionStage(req, {
Expand All @@ -82,7 +82,22 @@ describe('QueriesController', () => {
})
.then(toHTMLString)

expect(result).to.equal('scope3_success_scope3')
expect(dbMock.insert.getCall(0).args).to.deep.equal([
'query',
{
connection_id: 'cccccccc-0001-0000-0000-d8ae0805059e',
details: {
productId: 'SomeID',
quantity: 111,
},
query_response: null,
query_type: 'Scope 3 Carbon Consumption',
response_id: null,
role: 'requester',
status: 'pending_their_input',
},
])
expect(result).to.equal('queriesResponse_template')
})

it('should call page with stage error if rpc fails', async () => {
Expand All @@ -103,8 +118,8 @@ describe('QueriesController', () => {
})

it('should call page with stage error if rpc succeeds without response', async () => {
const { args, cloudagentMock } = withQueriesMocks()
cloudagentMock.submitDrpcRequest = sinon.stub().resolves(undefined)
const { dbMock, args, cloudagentMock } = withQueriesMocks()
cloudagentMock.submitDrpcRequest = sinon.stub().resolves(null)

const controller = new QueriesController(...args)
const result = await controller
Expand All @@ -115,12 +130,16 @@ describe('QueriesController', () => {
quantity: 111,
})
.then(toHTMLString)

expect(dbMock.update.getCall(0).args).to.deep.equal([
'query',
{ id: 'ccaaaaaa-0000-0000-0000-d8ae0805059e' },
{ status: 'errored' },
])
expect(result).to.equal('scope3_error_scope3')
})

it('should call page with stage error if rpc succeeds with error', async () => {
const { args, cloudagentMock } = withQueriesMocks()
const { dbMock, args, cloudagentMock } = withQueriesMocks()
cloudagentMock.submitDrpcRequest = sinon.stub().resolves({
error: new Error('error'),
id: 'request-id',
Expand All @@ -135,6 +154,11 @@ describe('QueriesController', () => {
quantity: 111,
})
.then(toHTMLString)
expect(dbMock.update.getCall(0).args).to.deep.equal([
'query',
{ id: 'ccaaaaaa-0000-0000-0000-d8ae0805059e' },
{ status: 'errored' },
])

expect(result).to.equal('scope3_error_scope3')
})
Expand Down Expand Up @@ -216,18 +240,18 @@ describe('QueriesController', () => {
})
})

it('creates a new query and renders a response view', async () => {
it('creates a child query and renders a response view', async () => {
const { args, dbMock } = withQueriesMocks()
const controller = new QueriesController(...args)
const result = await controller
.scope3CarbonConsumptionResponseSubmit(req, 'query-partial-id-test', {
companyId: 'some-company-id',
action: 'success',
partialQuery: ['on'],
emissions: '10',
connectionIds: ['conn-id-1', 'conn-id-2'],
productIds: ['product-1', 'product-2'],
quantities: ['10', '20'],
emissions: '1',
})
.then(toHTMLString)

Expand All @@ -238,7 +262,32 @@ describe('QueriesController', () => {
query_type: 'Scope 3 Carbon Consumption',
status: 'pending_their_input',
parent_id: '5390af91-c551-4d74-b394-d8ae0805059a',
details: { quantity: 10, productId: 'product-1', emissions: '1' },
details: {
quantity: 10,
productId: 'product-1',
emissions: '10',
query: 'Scope 3 Carbon Consumption',
queryIdForResponse: 'ccaaaaaa-0000-0000-0000-d8ae0805059e',
},
response_id: null,
query_response: null,
role: 'requester',
},
])
expect(dbMock.insert.getCall(1).args).to.deep.equal([
'query',
{
connection_id: 'cccccccc-0001-0000-0000-d8ae0805059e',
parent_id: '5390af91-c551-4d74-b394-d8ae0805059a',
query_type: 'Scope 3 Carbon Consumption',
status: 'pending_their_input',
details: {
query: 'Scope 3 Carbon Consumption',
quantity: 20,
productId: 'product-2',
emissions: '10',
queryIdForResponse: 'ccaaaaaa-0000-0000-0000-d8ae0805059e',
},
response_id: null,
query_response: null,
role: 'requester',
Expand Down Expand Up @@ -283,8 +332,8 @@ describe('QueriesController', () => {
expect(result).to.equal('queriesResponse_template')
})

it('should call page with stage error if rpc succeeds without response', async () => {
const { args, cloudagentMock } = withQueriesMocks()
it('sets query status to error if rpc succeeds without response', async () => {
const { dbMock, args, cloudagentMock } = withQueriesMocks()
cloudagentMock.submitDrpcRequest = sinon.stub().resolves(undefined)

const controller = new QueriesController(...args)
Expand All @@ -298,11 +347,16 @@ describe('QueriesController', () => {
.then(toHTMLString)

expect(result).to.equal('scope3_error_scope3')
expect(dbMock.update.getCall(0).args).to.deep.equal([
'query',
{ id: '5390af91-c551-4d74-b394-d8ae0805059a' },
{ status: 'errored' },
])
})

it('should call page with stage error if rpc fails', async () => {
const { args, cloudagentMock } = withQueriesMocks()
cloudagentMock.submitDrpcRequest = sinon.stub().rejects(new Error())
cloudagentMock.submitDrpcRequest = sinon.stub().rejects(new Error('testing'))

const controller = new QueriesController(...args)
const result = await controller
Expand All @@ -318,7 +372,7 @@ describe('QueriesController', () => {
})

it('should call page with stage error if rpc succeeds with error', async () => {
const { args, cloudagentMock } = withQueriesMocks()
const { dbMock, args, cloudagentMock } = withQueriesMocks()
cloudagentMock.submitDrpcRequest = sinon.stub().resolves({
error: new Error('error'),
id: 'request-id',
Expand All @@ -332,7 +386,11 @@ describe('QueriesController', () => {
emissions: '25',
})
.then(toHTMLString)

expect(dbMock.update.getCall(0).args).to.deep.equal([
'query',
{ id: '5390af91-c551-4d74-b394-d8ae0805059a' },
{ status: 'errored' },
])
expect(result).to.equal('scope3_error_scope3')
})

Expand Down Expand Up @@ -438,6 +496,7 @@ describe('QueriesController', () => {
query: 'Scope 3 Carbon Consumption',
productId: 'partial-product-id',
quantity: 10,
emissions: '10',
queryIdForResponse: 'ccaaaaaa-0000-0000-0000-d8ae0805059e',
},
])
Expand All @@ -452,9 +511,11 @@ describe('QueriesController', () => {
parent_id: '5390af91-c551-4d74-b394-d8ae0805059a',
status: 'pending_their_input',
details: {
emissions: '10',
productId: 'partial-product-id',
quantity: 10,
emissions: '10',
query: 'Scope 3 Carbon Consumption',
queryIdForResponse: 'ccaaaaaa-0000-0000-0000-d8ae0805059e',
},
response_id: null,
query_response: null,
Expand All @@ -463,6 +524,18 @@ describe('QueriesController', () => {
])
})

it('updates existing query status to forwarded', () => {
expect(dbMock.update.getCall(0).args).to.deep.equal([
'query',
{
id: '5390af91-c551-4d74-b394-d8ae0805059a',
},
{
status: 'forwarded',
},
])
})

it('inserts a drpc response to query_rpc table', () => {
expect(dbMock.insert.getCall(1).args).to.deep.equal([
'query_rpc',
Expand Down
Loading

0 comments on commit 5add30b

Please sign in to comment.