Skip to content

Commit

Permalink
MLPAB-2098: Add correspondent to fixture progress, protect against op…
Browse files Browse the repository at this point in the history
…ensearch not being ready (#1233)
  • Loading branch information
acsauk authored May 16, 2024
1 parent 23d64d1 commit 59871d4
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@ terraform-update-docs: ##@terraform updates all terraform-docs managed documenta
terraform-docs --config terraform/account/region/.terraform-docs.yml ./terraform/account/region

delete-all-from-lpa-index: ##@opensearch clears all items from the lpa index
curl -X POST 'http://localhost:9200/lpas/_delete_by_query/?conflicts=proceed&pretty' -H 'Content-Type: application/json' -d '{"query": {"match_all": {}}}'
curl -X POST "http://localhost:9200/lpas/_delete_by_query/?conflicts=proceed&pretty" -H 'Content-Type: application/json' -d '{"query": {"match_all": {}}}'

delete-lpa-index: ##@opensearch deletes the lpa index
curl -XDELETE "http://localhost:9200/lpas"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Confirm your certificate provider is not related', () => {
beforeEach(() => {
cy.visit('/fixtures?redirect=/your-details&progress=peopleToNotifyAboutYourLpa');
cy.visit('/fixtures?redirect=/your-details&progress=addCorrespondent');
cy.get('#f-last-name').clear().type('Cooper');
cy.contains('button', 'Continue').click();
cy.visitLpa('/task-list');
Expand Down
15 changes: 8 additions & 7 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ services:
context: ..
dockerfile: docker/localstack/Dockerfile
depends_on:
- opensearch
opensearch:
condition: service_healthy
container_name: localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
Expand All @@ -68,12 +69,6 @@ services:
default:
aliases:
- my-domain.eu-west-1.opensearch.localhost.localstack.cloud
healthcheck:
test: "curl --silent --fail http://my-domain.eu-west-1.opensearch.localhost.localstack.cloud:4566 | grep 'cluster_name'"
interval: 20s
retries: 10
start_period: 20s
timeout: 10s

opensearch:
container_name: opensearch
Expand All @@ -93,6 +88,12 @@ services:
hard: -1
volumes:
- data01:/usr/share/opensearch/data
# To ensure opensearch is ready for localstack-init commands
healthcheck:
test: "curl --silent --fail localhost:9200/_cluster/health | grep 'cluster_name'"
interval: 5s
retries: 6
timeout: 5s

mock-lpa-store:
build:
Expand Down
8 changes: 5 additions & 3 deletions docker/localstack/localstack-init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/usr/bin/env bash
echo 'configuring opensearch'
awslocal opensearch create-domain --region eu-west-1 --domain-name my-domain

echo 'deleting opensearch lpas index'
curl -XDELETE "http://opensearch:9200/lpas"

echo 'generating key pair'
openssl genpkey -algorithm RSA -out /tmp/private_key.pem -pkeyopt rsa_keygen_bits:2048
Expand Down Expand Up @@ -37,6 +42,3 @@ awslocal lambda wait function-active-v2 --region eu-west-1 --function-name event

awslocal events put-rule --region eu-west-1 --name receive-events-mlpa --event-bus-name default --event-pattern '{"source":["opg.poas.makeregister"],"detail-type":["uid-requested"]}'
awslocal events put-targets --region eu-west-1 --event-bus-name default --rule receive-events-mlpa --targets "Id"="receive-events-sirius","Arn"="arn:aws:lambda:eu-west-1:000000000000:function:event-received"

echo 'configuring opensearch'
awslocal opensearch create-domain --region eu-west-1 --domain-name my-domain
10 changes: 10 additions & 0 deletions internal/page/fixtures/donor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var progressValues = []string{
"addRestrictionsToTheLpa",
"chooseYourCertificateProvider",
"peopleToNotifyAboutYourLpa",
"addCorrespondent",
"checkAndSendToYourCertificateProvider",
"payForTheLpa",
"confirmYourIdentity",
Expand Down Expand Up @@ -301,6 +302,15 @@ func updateLPAProgress(
}

donorDetails.Tasks.PeopleToNotify = actor.TaskCompleted
}

if data.Progress >= slices.Index(progressValues, "addCorrespondent") {
donorDetails.AddCorrespondent = form.Yes
donorDetails.Correspondent = makeCorrespondent(Name{
Firstnames: "Jonathan",
Lastname: "Ashfurlong",
})

donorDetails.Tasks.AddCorrespondent = actor.TaskCompleted
}

Expand Down
20 changes: 20 additions & 0 deletions internal/page/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ func makePersonToNotify(name Name) actor.PersonToNotify {
}
}

func makeCorrespondent(name Name) actor.Correspondent {
return actor.Correspondent{
FirstNames: name.Firstnames,
LastName: name.Lastname,
Address: place.Address{
Line1: "5 RICHMOND PLACE",
Line2: "KINGS HEATH",
Line3: "WEST MIDLANDS",
TownOrCity: "BIRMINGHAM",
Postcode: "B14 7ED",
Country: "GB",
},
Organisation: "Ashfurlong and partners",
WantAddress: form.Yes,
Share: actor.CorrespondentShareAttorneys | actor.CorrespondentShareCertificateProvider,
Email: testEmail,
Telephone: testMobile,
}
}

func makeUID() string {
return strings.ToUpper("M-" + "FAKE" + "-" + random.String(4) + "-" + random.String(4))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/page/fixtures/supporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func waitForLPAIndex(searchClient *search.Client, organisationCtx context.Contex
PageSize: 1,
})
if err != nil {
log.Println(err)
log.Println("error waiting for LPA Index:", err)
}

if count > 10 {
Expand Down
1 change: 1 addition & 0 deletions web/template/fixtures.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
(item "addRestrictionsToTheLpa" "addRestrictionsToTheLpa")
(item "chooseYourCertificateProvider" "chooseYourCertificateProvider")
(item "peopleToNotifyAboutYourLpa" "peopleToNotifyAboutYourLpa")
(item "addCorrespondent" "addCorrespondent")
(item "checkAndSendToYourCertificateProvider" "checkAndSendToYourCertificateProvider")
(item "payForTheLpa" "payForTheLpa")
(item "confirmYourIdentity" "Confirm your identity")
Expand Down

0 comments on commit 59871d4

Please sign in to comment.