From d9cf8d7aef0d848ff4262232fd059debbc8010cd Mon Sep 17 00:00:00 2001 From: Joshua Hawxwell Date: Thu, 8 Aug 2024 14:44:37 +0100 Subject: [PATCH] MLPAB-1900 Voucher start page (#1413) * Remove unused mocks * Add voucher start page * Add test to check translation file has unique keys --- Makefile | 1 + cmd/mlpa/main_test.go | 52 ++++++++++++++++-- internal/app/app.go | 2 + internal/notify/mock_Bundle_test.go | 83 ----------------------------- internal/page/paths.go | 1 + internal/templatefn/paths.go | 2 + lang/cy.json | 3 +- lang/en.json | 3 +- web/template/voucher_start.gohtml | 20 +++++++ 9 files changed, 79 insertions(+), 88 deletions(-) delete mode 100644 internal/notify/mock_Bundle_test.go create mode 100644 web/template/voucher_start.gohtml diff --git a/Makefile b/Makefile index b686822b76..ac02a8cce3 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ go-test: ##@testing Runs full go test suite go test ./... -race -covermode=atomic -coverprofile=coverage.out go-generate: ##@testing Runs go generate for mocks and enums + git ls-files | grep '.*/mock_.*_test\.go' | xargs rm mockery go install ./cmd/enumerator go generate ./... diff --git a/cmd/mlpa/main_test.go b/cmd/mlpa/main_test.go index b589b7c264..a37f049a25 100644 --- a/cmd/mlpa/main_test.go +++ b/cmd/mlpa/main_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "io" "net/http" @@ -28,6 +29,51 @@ func TestAwsRegion(t *testing.T) { assert.Equal(t, "us-west-2", region) } +func TestLanguageFilesUniqueKeys(t *testing.T) { + for _, path := range []string{"lang/en.json", "lang/cy.json"} { + data, err := os.ReadFile("../../" + path) + if err != nil { + panic(err) + } + + keys := map[json.Token]struct{}{} + dec := json.NewDecoder(bytes.NewReader(data)) + + // skip opening { + _, _ = dec.Token() + + for { + tok, err := dec.Token() + if err != nil { + panic(err) + } + + if tok == json.Delim('}') { + break + } + + // skip value + valTok, _ := dec.Token() + + if _, found := keys[tok]; found { + t.Fail() + t.Log(path, "duplicate:", tok) + } + + keys[tok] = struct{}{} + + if valTok == json.Delim('{') { + for dec.More() { + _, _ = dec.Token() + } + + // skip closing } + _, _ = dec.Token() + } + } + } +} + func TestLanguageFilesMatch(t *testing.T) { en := loadTranslations("../../lang/en.json") cy := loadTranslations("../../lang/cy.json") @@ -35,14 +81,14 @@ func TestLanguageFilesMatch(t *testing.T) { for k := range en { if _, ok := cy[k]; !ok { t.Fail() - t.Log("lang/cy.json missing: ", k) + t.Log("lang/cy.json missing:", k) } } for k := range cy { if _, ok := en[k]; !ok { t.Fail() - t.Log("lang/en.json missing: ", k) + t.Log("lang/en.json missing:", k) } } } @@ -61,7 +107,7 @@ func TestApostrophesAreCurly(t *testing.T) { for k, v := range cy { if strings.Contains(v, "'") { t.Fail() - t.Log("lang/cy.json: ", k) + t.Log("lang/cy.json:", k) } } } diff --git a/internal/app/app.go b/internal/app/app.go index 485cb6a19b..152f0e478f 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -140,6 +140,8 @@ func App( page.Guidance(tmpls.Get("certificate_provider_start.gohtml"))) handleRoot(page.PathAttorneyStart, None, page.Guidance(tmpls.Get("attorney_start.gohtml"))) + handleRoot(page.PathVoucherStart, None, + page.Guidance(tmpls.Get("voucher_start.gohtml"))) handleRoot(page.PathDashboard, RequireSession, page.Dashboard(tmpls.Get("dashboard.gohtml"), donorStore, dashboardStore)) handleRoot(page.PathLpaDeleted, RequireSession, diff --git a/internal/notify/mock_Bundle_test.go b/internal/notify/mock_Bundle_test.go deleted file mode 100644 index e7426ec49e..0000000000 --- a/internal/notify/mock_Bundle_test.go +++ /dev/null @@ -1,83 +0,0 @@ -// Code generated by mockery v2.42.2. DO NOT EDIT. - -package notify - -import ( - localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - mock "github.com/stretchr/testify/mock" -) - -// mockBundle is an autogenerated mock type for the Bundle type -type mockBundle struct { - mock.Mock -} - -type mockBundle_Expecter struct { - mock *mock.Mock -} - -func (_m *mockBundle) EXPECT() *mockBundle_Expecter { - return &mockBundle_Expecter{mock: &_m.Mock} -} - -// For provides a mock function with given fields: lang -func (_m *mockBundle) For(lang localize.Lang) *localize.Localizer { - ret := _m.Called(lang) - - if len(ret) == 0 { - panic("no return value specified for For") - } - - var r0 *localize.Localizer - if rf, ok := ret.Get(0).(func(localize.Lang) *localize.Localizer); ok { - r0 = rf(lang) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*localize.Localizer) - } - } - - return r0 -} - -// mockBundle_For_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'For' -type mockBundle_For_Call struct { - *mock.Call -} - -// For is a helper method to define mock.On call -// - lang localize.Lang -func (_e *mockBundle_Expecter) For(lang interface{}) *mockBundle_For_Call { - return &mockBundle_For_Call{Call: _e.mock.On("For", lang)} -} - -func (_c *mockBundle_For_Call) Run(run func(lang localize.Lang)) *mockBundle_For_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(localize.Lang)) - }) - return _c -} - -func (_c *mockBundle_For_Call) Return(_a0 *localize.Localizer) *mockBundle_For_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockBundle_For_Call) RunAndReturn(run func(localize.Lang) *localize.Localizer) *mockBundle_For_Call { - _c.Call.Return(run) - return _c -} - -// newMockBundle creates a new instance of mockBundle. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newMockBundle(t interface { - mock.TestingT - Cleanup(func()) -}) *mockBundle { - mock := &mockBundle{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/page/paths.go b/internal/page/paths.go index fae41025a5..b659e756c7 100644 --- a/internal/page/paths.go +++ b/internal/page/paths.go @@ -32,6 +32,7 @@ const ( PathSupporterOrganisationDeleted = Path("/organisation-deleted") PathSupporterSigningInAdvice = Path("/signing-in-with-govuk-one-login") PathSupporterStart = Path("/supporter-start") + PathVoucherStart = Path("/voucher-start") PathAttorneyFixtures = Path("/fixtures/attorney") PathAuthRedirect = Path("/auth/redirect") diff --git a/internal/templatefn/paths.go b/internal/templatefn/paths.go index be376f26e1..36f0e68575 100644 --- a/internal/templatefn/paths.go +++ b/internal/templatefn/paths.go @@ -114,6 +114,7 @@ type appPaths struct { SignOut page.Path Start page.Path SupporterFixtures page.Path + VoucherStart page.Path AboutPayment donor.Path AddCorrespondent donor.Path @@ -329,6 +330,7 @@ var paths = appPaths{ SignOut: page.PathSignOut, Start: page.PathStart, SupporterFixtures: page.PathSupporterFixtures, + VoucherStart: page.PathVoucherStart, AboutPayment: donor.PathAboutPayment, AddCorrespondent: donor.PathAddCorrespondent, diff --git a/lang/cy.json b/lang/cy.json index 26a08f0e61..e724f4f782 100644 --- a/lang/cy.json +++ b/lang/cy.json @@ -1310,5 +1310,6 @@ "someOfTheseDetailsCanNoLongerBeChanged": "Welsh", "whichFeeTypeYouAreApplyingFor": "pa fath o ffi yr ydych yn gwneud cais amdano", "emailGreetingDonor": "Welsh {{.DonorFullName}},", - "emailGreetingCorrespondent": "Welsh: {{.LpaUID}} {{.CorrespondentFullName}} {{.DonorFullNamePossessive}} {{.LpaType}}" + "emailGreetingCorrespondent": "Welsh: {{.LpaUID}} {{.CorrespondentFullName}} {{.DonorFullNamePossessive}} {{.LpaType}}", + "voucherStartContent": "

Welsh

" } diff --git a/lang/en.json b/lang/en.json index c7d3dff60f..9094bd1cdb 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1239,5 +1239,6 @@ "someOfTheseDetailsCanNoLongerBeChanged": "Some of these details can no longer be changed because they have been successfully matched with your confirmed identity details.", "whichFeeTypeYouAreApplyingFor": "which fee type you are applying for", "emailGreetingDonor": "Dear {{.DonorFullName}},", - "emailGreetingCorrespondent": "Our ref: {{.LpaUID}}\n\nDear {{.CorrespondentFullName}}\n\nRe: {{.DonorFullNamePossessive}} Lasting Power of Attorney for {{.LpaType}}" + "emailGreetingCorrespondent": "Our ref: {{.LpaUID}}\n\nDear {{.CorrespondentFullName}}\n\nRe: {{.DonorFullNamePossessive}} Lasting Power of Attorney for {{.LpaType}}", + "voucherStartContent": "

Vouching allows you to verify the identity of someone you know well. This might be because they do not have ID documentation or failed an ID check.

To vouch for someone, you must:

You cannot vouch for someone if you are:

What you will need to do

You will need to confirm your own identity using GOV.UK One Login.

You will need either:

We will then ask you to verify the person’s identity and sign a declaration.

" } diff --git a/web/template/voucher_start.gohtml b/web/template/voucher_start.gohtml new file mode 100644 index 0000000000..e337a5e612 --- /dev/null +++ b/web/template/voucher_start.gohtml @@ -0,0 +1,20 @@ +{{ template "page" . }} + +{{ define "main" }} +
+
+

{{ tr .App "whatIsVouching" }}

+ + {{ trHtml .App "voucherStartContent" }} + +

+ + {{ tr .App "start" }} + + +

+
+
+{{ end }}