From 59871d42a37f58d19f751964b48fa54996bb53f5 Mon Sep 17 00:00:00 2001 From: Alex Saunders Date: Thu, 16 May 2024 13:14:41 +0100 Subject: [PATCH] MLPAB-2098: Add correspondent to fixture progress, protect against opensearch not being ready (#1233) --- Makefile | 5 ++++- ...-certificate-provider-is-not-related.cy.js | 2 +- docker/docker-compose.yml | 15 +++++++------- docker/localstack/localstack-init.sh | 8 +++++--- internal/page/fixtures/donor.go | 10 ++++++++++ internal/page/fixtures/fixtures.go | 20 +++++++++++++++++++ internal/page/fixtures/supporter.go | 2 +- web/template/fixtures.gohtml | 1 + 8 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index f150ef15e3..a8794a240e 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/cypress/e2e/donor/confirm-your-certificate-provider-is-not-related.cy.js b/cypress/e2e/donor/confirm-your-certificate-provider-is-not-related.cy.js index f2396b9ad0..29d3d607a8 100644 --- a/cypress/e2e/donor/confirm-your-certificate-provider-is-not-related.cy.js +++ b/cypress/e2e/donor/confirm-your-certificate-provider-is-not-related.cy.js @@ -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'); diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 003e41e822..0deb52ef7e 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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 @@ -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 @@ -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: diff --git a/docker/localstack/localstack-init.sh b/docker/localstack/localstack-init.sh index 9286d6031c..c072923f57 100644 --- a/docker/localstack/localstack-init.sh +++ b/docker/localstack/localstack-init.sh @@ -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 @@ -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 diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index 236fadef14..42684649dd 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -44,6 +44,7 @@ var progressValues = []string{ "addRestrictionsToTheLpa", "chooseYourCertificateProvider", "peopleToNotifyAboutYourLpa", + "addCorrespondent", "checkAndSendToYourCertificateProvider", "payForTheLpa", "confirmYourIdentity", @@ -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 } diff --git a/internal/page/fixtures/fixtures.go b/internal/page/fixtures/fixtures.go index 9472976fd4..7234eb2d78 100644 --- a/internal/page/fixtures/fixtures.go +++ b/internal/page/fixtures/fixtures.go @@ -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)) } diff --git a/internal/page/fixtures/supporter.go b/internal/page/fixtures/supporter.go index 1a470fc9b4..7e3f2c1020 100644 --- a/internal/page/fixtures/supporter.go +++ b/internal/page/fixtures/supporter.go @@ -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 { diff --git a/web/template/fixtures.gohtml b/web/template/fixtures.gohtml index ac2adbf8e4..de977d6222 100644 --- a/web/template/fixtures.gohtml +++ b/web/template/fixtures.gohtml @@ -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")