diff --git a/Makefile b/Makefile index ef57d88..c17db34 100644 --- a/Makefile +++ b/Makefile @@ -39,24 +39,27 @@ test-component: convey: goconvey ./... - .PHONY: fetch-renderer-lib -fetch-renderer-lib: -ifeq ($(LOCAL_DP_RENDERER_IN_USE), 1) - $(eval CORE_ASSETS_PATH = $(shell grep -w "\"github.com/ONSdigital/dp-renderer\" =>" go.mod | awk -F '=> ' '{print $$2}' | tr -d '"')) -else - $(eval APP_RENDERER_VERSION=$(shell grep "github.com/ONSdigital/dp-renderer" go.mod | cut -d ' ' -f2 )) - $(eval CORE_ASSETS_PATH = $(shell go get github.com/ONSdigital/dp-renderer@$(APP_RENDERER_VERSION) && go list -f '{{.Dir}}' -m github.com/ONSdigital/dp-renderer)) -endif - .PHONY: generate-debug generate-debug: fetch-renderer-lib - cd assets; go run github.com/kevinburke/go-bindata/go-bindata -prefix $(CORE_ASSETS_PATH)/assets -debug -o data.go -pkg assets locales/... templates/... $(CORE_ASSETS_PATH)/assets/locales/... $(CORE_ASSETS_PATH)/assets/templates/... + go get -u github.com/go-bindata/go-bindata/... + go install github.com/go-bindata/go-bindata/... + cd assets; go run github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs -prefix $(CORE_ASSETS_PATH)/assets -o data.go -pkg assets locales/... templates/... $(CORE_ASSETS_PATH)/assets/locales/... $(CORE_ASSETS_PATH)/assets/templates/... { echo "// +build debug\n"; cat assets/data.go; } > assets/debug.go.new mv assets/debug.go.new assets/data.go .PHONY: generate-prod -generate-prod: fetch-renderer-lib - cd assets; go run github.com/kevinburke/go-bindata/go-bindata -prefix $(CORE_ASSETS_PATH)/assets -o data.go -pkg assets locales/... templates/... $(CORE_ASSETS_PATH)/assets/locales/... $(CORE_ASSETS_PATH)/assets/templates/... +generate-prod: fetch-renderer-lib + go get -u github.com/go-bindata/go-bindata/... + go install github.com/go-bindata/go-bindata/... + cd assets; go run github.com/elazarl/go-bindata-assetfs/go-bindata-assetfs -prefix $(CORE_ASSETS_PATH)/assets -o data.go -pkg assets locales/... templates/... $(CORE_ASSETS_PATH)/assets/locales/... $(CORE_ASSETS_PATH)/assets/templates/... { echo "// +build production\n"; cat assets/data.go; } > assets/data.go.new mv assets/data.go.new assets/data.go +.PHONY: fetch-dp-renderer +fetch-renderer-lib: +ifeq ($(LOCAL_DP_RENDERER_IN_USE), 1) + $(eval CORE_ASSETS_PATH = $(shell grep -w "\"github.com/ONSdigital/dp-renderer\" =>" go.mod | awk -F '=> ' '{print $$2}' | tr -d '"')) +else + $(eval APP_RENDERER_VERSION=$(shell grep "github.com/ONSdigital/dp-renderer" go.mod | cut -d ' ' -f2 )) + $(eval CORE_ASSETS_PATH = $(shell go get github.com/ONSdigital/dp-renderer@$(APP_RENDERER_VERSION) && go list -f '{{.Dir}}' -m github.com/ONSdigital/dp-renderer)) +endif diff --git a/config/config.go b/config/config.go index 66d3a5f..d9abad2 100644 --- a/config/config.go +++ b/config/config.go @@ -8,20 +8,28 @@ import ( // Config represents service configuration for dp-frontend-feedback-controller type Config struct { - BindAddr string `envconfig:"BIND_ADDR"` - GracefulShutdownTimeout time.Duration `envconfig:"GRACEFUL_SHUTDOWN_TIMEOUT"` - HealthCheckInterval time.Duration `envconfig:"HEALTHCHECK_INTERVAL"` - HealthCheckCriticalTimeout time.Duration `envconfig:"HEALTHCHECK_CRITICAL_TIMEOUT"` - MailHost string `envconfig:"MAIL_HOST"` - MailUser string `envconfig:"MAIL_USER"` - MailPassword string `envconfig:"MAIL_PASSWORD" json:"-"` - MailPort string `envconfig:"MAIL_PORT"` - FeedbackTo string `envconfig:"FEEDBACK_TO"` - FeedbackFrom string `envconfig:"FEEDBACK_FROM"` - PatternLibraryAssetsPath string `envconfig:"PATTERN_LIBRARY_ASSETS_PATH"` - SiteDomain string `envconfig:"SITE_DOMAIN"` - Debug bool `envconfig:"DEBUG"` - SupportedLanguages []string `envconfig:"SUPPORTED_LANGUAGES"` + APIRouterURL string `envconfig:"API_ROUTER_URL"` + BindAddr string `envconfig:"BIND_ADDR"` + CacheUpdateInterval *time.Duration `envconfig:"CACHE_UPDATE_INTERVAL"` + CensusTopicID string `envconfig:"CENSUS_TOPIC_ID"` + Debug bool `envconfig:"DEBUG"` + EnableCensusTopicSubsection bool `envconfig:"ENABLE_CENSUS_TOPIC_SUBSECTION"` + EnableNewNavBar bool `envconfig:"ENABLE_NEW_NAVBAR"` + GracefulShutdownTimeout time.Duration `envconfig:"GRACEFUL_SHUTDOWN_TIMEOUT"` + HealthCheckInterval time.Duration `envconfig:"HEALTHCHECK_INTERVAL"` + HealthCheckCriticalTimeout time.Duration `envconfig:"HEALTHCHECK_CRITICAL_TIMEOUT"` + MailHost string `envconfig:"MAIL_HOST"` + MailUser string `envconfig:"MAIL_USER"` + MailPassword string `envconfig:"MAIL_PASSWORD" json:"-"` + MailPort string `envconfig:"MAIL_PORT"` + FeedbackTo string `envconfig:"FEEDBACK_TO"` + FeedbackFrom string `envconfig:"FEEDBACK_FROM"` + IsPublishingMode bool `envconfig:"IS_PUBLISHING_MODE"` + Languages string `envconfig:"LANGUAGES"` + PatternLibraryAssetsPath string `envconfig:"PATTERN_LIBRARY_ASSETS_PATH"` + ServiceAuthToken string `envconfig:"SERVICE_AUTH_TOKEN" json:"-"` + SiteDomain string `envconfig:"SITE_DOMAIN"` + SupportedLanguages []string `envconfig:"SUPPORTED_LANGUAGES"` } var cfg *Config @@ -48,19 +56,25 @@ func get() (*Config, error) { } cfg := &Config{ - BindAddr: "localhost:25200", - GracefulShutdownTimeout: 5 * time.Second, - HealthCheckInterval: 30 * time.Second, - HealthCheckCriticalTimeout: 90 * time.Second, - MailHost: "localhost", - MailPort: "1025", - MailUser: "", - MailPassword: "", - FeedbackTo: "to@gmail.com", - FeedbackFrom: "from@gmail.com", - SiteDomain: "localhost", - Debug: false, - SupportedLanguages: []string{"en", "cy"}, + APIRouterURL: "http://localhost:23200/v1", + BindAddr: "localhost:25200", + CensusTopicID: "4445", + Debug: false, + EnableCensusTopicSubsection: false, + EnableNewNavBar: false, + GracefulShutdownTimeout: 5 * time.Second, + HealthCheckInterval: 30 * time.Second, + HealthCheckCriticalTimeout: 90 * time.Second, + MailHost: "localhost", + MailPort: "1025", + MailUser: "", + MailPassword: "", + FeedbackTo: "to@gmail.com", + FeedbackFrom: "from@gmail.com", + IsPublishingMode: false, + ServiceAuthToken: "", + SiteDomain: "localhost", + SupportedLanguages: []string{"en", "cy"}, } return cfg, envconfig.Process("", cfg) diff --git a/config/config_test.go b/config/config_test.go index 3030945..1fe79f2 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -15,6 +15,7 @@ func TestConfig(t *testing.T) { So(err, ShouldBeNil) }) Convey("Then the values should be set to the expected defaults", func() { + So(cfg.EnableNewNavBar, ShouldEqual, false) So(cfg.GracefulShutdownTimeout, ShouldEqual, 5*time.Second) So(cfg.HealthCheckInterval, ShouldEqual, 30*time.Second) So(cfg.HealthCheckCriticalTimeout, ShouldEqual, 90*time.Second) @@ -27,6 +28,8 @@ func TestConfig(t *testing.T) { So(cfg.SiteDomain, ShouldEqual, "localhost") So(cfg.Debug, ShouldEqual, false) So(cfg.SupportedLanguages, ShouldResemble, []string{"en", "cy"}) + So(cfg.IsPublishingMode, ShouldEqual, false) + So(cfg.EnableCensusTopicSubsection, ShouldEqual, false) }) Convey("Then a second call to config should return the same config", func() { diff --git a/email/emailtest/sender.go b/email/emailtest/sender.go index 4cf4d01..0af9c1c 100644 --- a/email/emailtest/sender.go +++ b/email/emailtest/sender.go @@ -18,19 +18,19 @@ var _ email.Sender = &SenderMock{} // SenderMock is a mock implementation of email.Sender. // -// func TestSomethingThatUsesSender(t *testing.T) { +// func TestSomethingThatUsesSender(t *testing.T) { // -// // make and configure a mocked email.Sender -// mockedSender := &SenderMock{ -// SendFunc: func(from string, to []string, msg []byte) error { -// panic("mock out the Send method") -// }, -// } +// // make and configure a mocked email.Sender +// mockedSender := &SenderMock{ +// SendFunc: func(from string, to []string, msg []byte) error { +// panic("mock out the Send method") +// }, +// } // -// // use mockedSender in code that requires email.Sender -// // and then make assertions. +// // use mockedSender in code that requires email.Sender +// // and then make assertions. // -// } +// } type SenderMock struct { // SendFunc mocks the Send method. SendFunc func(from string, to []string, msg []byte) error @@ -71,7 +71,8 @@ func (mock *SenderMock) Send(from string, to []string, msg []byte) error { // SendCalls gets all the calls that were made to Send. // Check the length with: -// len(mockedSender.SendCalls()) +// +// len(mockedSender.SendCalls()) func (mock *SenderMock) SendCalls() []struct { From string To []string diff --git a/go.mod b/go.mod index 6b9a02d..a15e1ac 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,13 @@ module github.com/ONSdigital/dp-frontend-feedback-controller go 1.19 require ( + github.com/ONSdigital/dp-frontend-cache-helper v0.2.0 github.com/ONSdigital/dp-frontend-models v1.10.1 github.com/ONSdigital/dp-healthcheck v1.5.0 - github.com/ONSdigital/dp-net v1.5.0 - github.com/ONSdigital/dp-renderer v1.49.0 - github.com/ONSdigital/go-ns v0.0.0-20210831102424-ebdecc20fe9e + github.com/ONSdigital/dp-net/v2 v2.6.0 + github.com/ONSdigital/dp-renderer v1.58.0 + github.com/ONSdigital/dp-topic-api v0.16.0 + github.com/ONSdigital/go-ns v0.0.0-20210916104633-ac1c1c52327e github.com/ONSdigital/log.go/v2 v2.3.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/schema v1.2.0 @@ -19,18 +21,20 @@ require ( github.com/BurntSushi/toml v0.3.1 // indirect github.com/ONSdigital/dp-api-clients-go v1.43.0 // indirect github.com/ONSdigital/dp-api-clients-go/v2 v2.187.0 // indirect - github.com/ONSdigital/dp-net/v2 v2.6.0 // indirect + github.com/ONSdigital/dp-cache v0.3.0 // indirect + github.com/ONSdigital/dp-net v1.5.0 // indirect github.com/aws/aws-sdk-go v1.44.76 // indirect github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2 // indirect + github.com/elazarl/go-bindata-assetfs v1.0.1 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/gosimple/slug v1.9.0 // indirect github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/justinas/alice v1.2.0 // indirect - github.com/kevinburke/go-bindata v3.24.0+incompatible // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.16 // indirect github.com/nicksnyder/go-i18n/v2 v2.1.2 // indirect diff --git a/go.sum b/go.sum index 1fe3744..c082cab 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,10 @@ github.com/ONSdigital/dp-api-clients-go v1.43.0 h1:0982P/YxnYXvba1RhEcFmwF3xywC4 github.com/ONSdigital/dp-api-clients-go v1.43.0/go.mod h1:V5MfINik+o3OAF985UXUoMjXIfrZe3JKYa5AhZn5jts= github.com/ONSdigital/dp-api-clients-go/v2 v2.187.0 h1:HKZ2DEMdoUlz4nAlVReyFv1XCXYcAvQBXukGnE+zmuY= github.com/ONSdigital/dp-api-clients-go/v2 v2.187.0/go.mod h1:JhWrjETosIKYjbLoa3d19QJlKv7dx+/+x09qg355Rxg= +github.com/ONSdigital/dp-cache v0.3.0 h1:E0T3XVjpcl6PDHL/4Go9a+EGekIwwNsfL0MsSgNK/jM= +github.com/ONSdigital/dp-cache v0.3.0/go.mod h1:cyduXeUO8n9TLZIorCWDzEoLkk1jK8q4Ex5CBsxptKA= +github.com/ONSdigital/dp-frontend-cache-helper v0.2.0 h1:IL1wUKY1gbI4rkLCmzNDDke0gm6D7YQgHufekFq94p8= +github.com/ONSdigital/dp-frontend-cache-helper v0.2.0/go.mod h1:3tOGFnElMHDTfAiFbWD2W64zF+IWJSlPS/f/wbfvEpg= github.com/ONSdigital/dp-frontend-models v1.1.0/go.mod h1:TT96P7Mi69N3Tc/jFNdbjiwG4GAaMjP26HLotFQ6BPw= github.com/ONSdigital/dp-frontend-models v1.10.1 h1:fHXZB/MwcS7pR2MySFvAhkzZpMSaKyhYb6v80cRKVhI= github.com/ONSdigital/dp-frontend-models v1.10.1/go.mod h1:K4n0EwATkzbuWzSajBHja+uc9zvqnKiq6WtUwLav4Kg= @@ -31,11 +35,13 @@ github.com/ONSdigital/dp-net/v2 v2.6.0 h1:orxdb0SVDrJgz/zma0QXgQCAGJdLDhp6g2XqH6 github.com/ONSdigital/dp-net/v2 v2.6.0/go.mod h1:4/2ZyId//hFa7AtbbRNQctY729C1Vbw4UEdOliRvpZI= github.com/ONSdigital/dp-rchttp v0.0.0-20190919143000-bb5699e6fd59/go.mod h1:KkW68U3FPuivW4ogi9L8CPKNj9ZxGko4qcUY7KoAAkQ= github.com/ONSdigital/dp-rchttp v0.0.0-20200114090501-463a529590e8/go.mod h1:821jZtK0oBsV8hjIkNr8vhAWuv0FxJBPJuAHa2B70Gk= -github.com/ONSdigital/dp-renderer v1.49.0 h1:m7p487i+3x236rJ76bZV/uxj6ABi2chCTGuMaTaZDLg= -github.com/ONSdigital/dp-renderer v1.49.0/go.mod h1:q/zlK9Qc7b95w7XPfgS7RPLID++CZgaAn0q51QCqZew= +github.com/ONSdigital/dp-renderer v1.58.0 h1:GBGKiFFtP91Q6XJ4VwYlKUh8LPjpNRNVAaDk1Mkmc0Q= +github.com/ONSdigital/dp-renderer v1.58.0/go.mod h1:aEgUZoxxw4vy5QG/1WYid3ApbLkaakbyn3/CqIGR/yE= +github.com/ONSdigital/dp-topic-api v0.16.0 h1:SScnzJ9uaVxBoXECAbVOsaqLmGqjss7UPdyVLu9L9C8= +github.com/ONSdigital/dp-topic-api v0.16.0/go.mod h1:HySqqTOmVX6ElSOrioTtjWiU3dV9hfy2MFg0730lY1g= github.com/ONSdigital/go-ns v0.0.0-20191104121206-f144c4ec2e58/go.mod h1:iWos35il+NjbvDEqwtB736pyHru0MPFE/LqcwkV1wDc= -github.com/ONSdigital/go-ns v0.0.0-20210831102424-ebdecc20fe9e h1:tXdCJg2SUi2vLPA22bgVmeAY+sp3pKtUsAboBrOkO5Y= -github.com/ONSdigital/go-ns v0.0.0-20210831102424-ebdecc20fe9e/go.mod h1:BCx4ULp5nT3dT7Mft5iMrp9439JG9lqIlc0JOPmsHTg= +github.com/ONSdigital/go-ns v0.0.0-20210916104633-ac1c1c52327e h1:o+AK5m0lxRIFn4t9ng9x19kez72ErAB0cW9ArT6sAZM= +github.com/ONSdigital/go-ns v0.0.0-20210916104633-ac1c1c52327e/go.mod h1:BCx4ULp5nT3dT7Mft5iMrp9439JG9lqIlc0JOPmsHTg= github.com/ONSdigital/log.go v0.0.0-20191127134126-2a610b254f20/go.mod h1:BD7D8FWP1fzwUWsrCopEG72jl9cchCaVNIGSz6YvL+Y= github.com/ONSdigital/log.go v1.0.0/go.mod h1:UnGu9Q14gNC+kz0DOkdnLYGoqugCvnokHBRBxFRpVoQ= github.com/ONSdigital/log.go v1.0.1-0.20200805084515-ee61165ea36a/go.mod h1:dDnQATFXCBOknvj6ZQuKfmDhbOWf3e8mtV+dPEfWJqs= @@ -56,6 +62,8 @@ github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2/go.mod h1:S/7n9cop github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= +github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw= +github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 h1:wWke/RUCl7VRjQhwPlR/v0glZXNYzBHdNUzf/Am2Nmg= github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9/go.mod h1:uPmAp6Sws4L7+Q/OokbWDAK1ibXYhB3PXFP1kol5hPg= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -67,6 +75,8 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-avro/avro v0.0.0-20171219232920-444163702c11/go.mod h1:kxj6THYP0dmFPk4Z+bijIAhJoGgeBfyOKXMduhvdJPA= +github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE= +github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -97,8 +107,6 @@ github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo= github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= -github.com/kevinburke/go-bindata v3.24.0+incompatible h1:qajFA3D0pH94OTLU4zcCCKCDgR+Zr2cZK/RPJHDdFoY= -github.com/kevinburke/go-bindata v3.24.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -136,12 +144,16 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK github.com/unrolled/render v1.0.2/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= github.com/unrolled/render v1.4.0 h1:p73obhpsXuE3paXOtcuXTBKgBJpLCfmABnsUiO35x+Q= github.com/unrolled/render v1.4.0/go.mod h1:cK4RSTTVdND5j9EYEc0LAMOvdG11JeiKjyjfyZRvV2w= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -149,9 +161,11 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E= golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -170,6 +184,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -178,11 +194,15 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/avro.v0 v0.0.0-20171217001914-a730b5802183/go.mod h1:FvqrFXt+jCsyQibeRv4xxEJBL5iG2DDW5aeJwzDiq4A= diff --git a/handlers/feedback.go b/handlers/feedback.go index 23dabce..4243da9 100644 --- a/handlers/feedback.go +++ b/handlers/feedback.go @@ -2,16 +2,18 @@ package handlers import ( "bytes" + "context" "fmt" "html" "net/http" "regexp" + cacheHelper "github.com/ONSdigital/dp-frontend-cache-helper/pkg/navigation/helper" "github.com/ONSdigital/dp-frontend-feedback-controller/config" "github.com/ONSdigital/dp-frontend-feedback-controller/email" "github.com/ONSdigital/dp-frontend-feedback-controller/interfaces" "github.com/ONSdigital/dp-frontend-feedback-controller/model" - dphandlers "github.com/ONSdigital/dp-net/handlers" + dphandlers "github.com/ONSdigital/dp-net/v2/handlers" "github.com/ONSdigital/log.go/v2/log" "github.com/gorilla/schema" ) @@ -28,13 +30,13 @@ type Feedback struct { } // FeedbackThanks loads the Feedback Thank you page -func FeedbackThanks(rend interfaces.Renderer) http.HandlerFunc { +func FeedbackThanks(rend interfaces.Renderer, cacheService *cacheHelper.Helper) http.HandlerFunc { return dphandlers.ControllerHandler(func(w http.ResponseWriter, req *http.Request, lang, collectionID, accessToken string) { - feedbackThanks(w, req, req.Referer(), "", rend) + feedbackThanks(w, req, req.Referer(), "", rend, cacheService, lang) }) } -func feedbackThanks(w http.ResponseWriter, req *http.Request, url, errorType string, rend interfaces.Renderer) { +func feedbackThanks(w http.ResponseWriter, req *http.Request, url, errorType string, rend interfaces.Renderer, cacheHelperService *cacheHelper.Helper, lang string) { ctx := req.Context() basePage := rend.NewBasePageModel() p := model.Feedback{ @@ -48,7 +50,12 @@ func feedbackThanks(w http.ResponseWriter, req *http.Request, url, errorType str } else { wholeSite = cfg.SiteDomain } - + if cfg.EnableNewNavBar { + mappedNavContent, err := cacheHelperService.GetMappedNavigationContent(ctx, lang) + if err == nil { + p.NavigationContent = mappedNavContent + } + } p.Type = "feedback" p.Metadata.Title = "Thank you" p.ErrorType = errorType @@ -68,13 +75,13 @@ func feedbackThanks(w http.ResponseWriter, req *http.Request, url, errorType str } // GetFeedback handles the loading of a feedback page -func GetFeedback(rend interfaces.Renderer) http.HandlerFunc { +func GetFeedback(rend interfaces.Renderer, cacheService *cacheHelper.Helper) http.HandlerFunc { return dphandlers.ControllerHandler(func(w http.ResponseWriter, req *http.Request, lang, collectionID, accessToken string) { - getFeedback(w, req, req.Referer(), "", "", "", "", lang, rend) + getFeedback(w, req, req.Referer(), "", "", "", "", lang, rend, cacheService) }) } -func getFeedback(w http.ResponseWriter, req *http.Request, url, errorType, description, name, userEmail, lang string, rend interfaces.Renderer) { +func getFeedback(w http.ResponseWriter, req *http.Request, url, errorType, description, name, userEmail, lang string, rend interfaces.Renderer, cacheHelperService *cacheHelper.Helper) { basePage := rend.NewBasePageModel() p := model.Feedback{ Page: basePage, @@ -90,6 +97,17 @@ func getFeedback(w http.ResponseWriter, req *http.Request, url, errorType, descr p.Type = "feedback" p.Metadata.Title = "Feedback" p.Metadata.Description = url + ctx := context.Background() + cfg, err := config.Get() + if err != nil { + log.Warn(ctx, "Unable to retrieve configuration", log.FormatErrors([]error{err})) + } + if cfg.EnableNewNavBar { + mappedNavContent, err := cacheHelperService.GetMappedNavigationContent(ctx, lang) + if err == nil { + p.NavigationContent = mappedNavContent + } + } if len(p.Metadata.Description) > 50 { p.Metadata.Description = p.Metadata.Description[len(p.Metadata.Description)-50 : len(p.Metadata.Description)] @@ -105,13 +123,13 @@ func getFeedback(w http.ResponseWriter, req *http.Request, url, errorType, descr } // AddFeedback handles a users feedback request and sends a message to slack -func AddFeedback(to, from string, isPositive bool, rend interfaces.Renderer, emailSender email.Sender) http.HandlerFunc { +func AddFeedback(to, from string, isPositive bool, rend interfaces.Renderer, emailSender email.Sender, cacheService *cacheHelper.Helper) http.HandlerFunc { return dphandlers.ControllerHandler(func(w http.ResponseWriter, req *http.Request, lang, collectionID, accessToken string) { - addFeedback(w, req, isPositive, rend, emailSender, from, to, lang) + addFeedback(w, req, isPositive, rend, emailSender, from, to, lang, cacheService) }) } -func addFeedback(w http.ResponseWriter, req *http.Request, isPositive bool, rend interfaces.Renderer, emailSender email.Sender, from, to, lang string) { +func addFeedback(w http.ResponseWriter, req *http.Request, isPositive bool, rend interfaces.Renderer, emailSender email.Sender, from, to, lang string, cacheService *cacheHelper.Helper) { ctx := req.Context() if err := req.ParseForm(); err != nil { log.Error(ctx, "unable to parse request form", err) @@ -130,13 +148,13 @@ func addFeedback(w http.ResponseWriter, req *http.Request, isPositive bool, rend } if f.Description == "" && !isPositive { - getFeedback(w, req, f.URL, "description", f.Description, f.Name, f.Email, lang, rend) + getFeedback(w, req, f.URL, "description", f.Description, f.Name, f.Email, lang, rend, cacheService) return } if len(f.Email) > 0 && !isPositive { if ok, err := regexp.MatchString(`^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$`, f.Email); !ok || err != nil { - getFeedback(w, req, f.URL, "email", f.Description, f.Name, f.Email, lang, rend) + getFeedback(w, req, f.URL, "email", f.Description, f.Name, f.Email, lang, rend, cacheService) return } } diff --git a/handlers/feedback_test.go b/handlers/feedback_test.go index 78dfddc..5e0f3b8 100644 --- a/handlers/feedback_test.go +++ b/handlers/feedback_test.go @@ -1,18 +1,23 @@ package handlers import ( + "context" "errors" "io" "net/http" "net/http/httptest" "strings" "testing" + "time" + cacheClient "github.com/ONSdigital/dp-frontend-cache-helper/pkg/navigation/client" + cacheHelper "github.com/ONSdigital/dp-frontend-cache-helper/pkg/navigation/helper" "github.com/ONSdigital/dp-frontend-feedback-controller/email/emailtest" "github.com/ONSdigital/dp-frontend-feedback-controller/interfaces/interfacestest" "github.com/ONSdigital/dp-frontend-feedback-controller/model" "github.com/ONSdigital/dp-frontend-models/model/feedback" coreModel "github.com/ONSdigital/dp-renderer/model" + topicModel "github.com/ONSdigital/dp-topic-api/models" . "github.com/smartystreets/goconvey/convey" ) @@ -34,8 +39,21 @@ func Test_getFeedback(t *testing.T) { }, } + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When getFeedback is called", func() { - getFeedback(w, req, url, errorType, description, name, email, lang, mockRenderer) + getFeedback(w, req, url, errorType, description, name, email, lang, mockRenderer, mockNagivationCache) Convey("Then a 200 request is returned", func() { So(w.Code, ShouldEqual, http.StatusOK) }) @@ -57,9 +75,22 @@ func Test_getFeedback(t *testing.T) { return coreModel.Page{} }, } + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When getFeedback is called", func() { - getFeedback(w, req, url, errorType, description, name, email, lang, mockRenderer) + getFeedback(w, req, url, errorType, description, name, email, lang, mockRenderer, mockNagivationCache) Convey("Then the page model is sent to the renderer", func() { var expectedPage feedback.Page expectedPage.Language = "en" @@ -99,9 +130,21 @@ func Test_addFeedback(t *testing.T) { return nil }, } - + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When addFeedback is called", func() { - addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang) + addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang, mockNagivationCache) Convey("Then the renderer is not called", func() { So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 0) }) @@ -134,9 +177,21 @@ func Test_addFeedback(t *testing.T) { return errors.New("email is broken") }, } - + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When addFeedback is called", func() { - addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang) + addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang, mockNagivationCache) Convey("Then the renderer is not called", func() { So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 0) }) @@ -171,9 +226,21 @@ func Test_addFeedback(t *testing.T) { return nil }, } - + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When addFeedback is called", func() { - addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang) + addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang, mockNagivationCache) Convey("Then the renderer is not called", func() { So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 0) }) @@ -209,8 +276,21 @@ func Test_addFeedback(t *testing.T) { return nil }, } + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When addFeedback is called", func() { - addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang) + addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang, mockNagivationCache) Convey("Then the renderer is called to render the feedback page", func() { So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 1) }) @@ -245,9 +325,21 @@ func Test_addFeedback(t *testing.T) { return nil }, } - + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When addFeedback is called", func() { - addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang) + addFeedback(w, req, isPositive, mockRenderer, mockSender, from, to, lang, mockNagivationCache) Convey("Then the renderer is called to render the feedback page", func() { So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 1) }) @@ -262,6 +354,7 @@ func Test_addFeedback(t *testing.T) { } func Test_feedbackThanks(t *testing.T) { + lang := "en" Convey("Given a valid request", t, func() { req := httptest.NewRequest("GET", "http://localhost", nil) w := httptest.NewRecorder() @@ -274,8 +367,21 @@ func Test_feedbackThanks(t *testing.T) { return coreModel.Page{} }, } + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When feedbackThanks is called", func() { - feedbackThanks(w, req, url, errorType, mockRenderer) + feedbackThanks(w, req, url, errorType, mockRenderer, mockNagivationCache, lang) Convey("Then the renderer is called", func() { So(len(mockRenderer.BuildPageCalls()), ShouldEqual, 1) }) @@ -290,15 +396,27 @@ func Test_feedbackThanks(t *testing.T) { w := httptest.NewRecorder() url := "www.test.com" errorType := "" - mockRenderer := &interfacestest.RendererMock{ BuildPageFunc: func(w io.Writer, pageModel interface{}, templateName string) {}, NewBasePageModelFunc: func() coreModel.Page { return coreModel.Page{} }, } + mockNagivationCache := &cacheHelper.Helper{ + Clienter: &cacheClient.ClienterMock{ + AddNavigationCacheFunc: func(ctx context.Context, updateInterval *time.Duration) error { + return nil + }, + CloseFunc: func() { + }, + GetNavigationDataFunc: func(ctx context.Context, lang string) (*topicModel.Navigation, error) { + return &topicModel.Navigation{}, nil + }, + StartBackgroundUpdateFunc: func(ctx context.Context, errorChannel chan error) { + }, + }} Convey("When feedbackThanks is called", func() { - feedbackThanks(w, req, url, errorType, mockRenderer) + feedbackThanks(w, req, url, errorType, mockRenderer, mockNagivationCache, lang) Convey("Then the handler sanitises the request text", func() { dataSentToRender := mockRenderer.BuildPageCalls()[0].PageModel.(model.Feedback) returnToUrl := dataSentToRender.Metadata.Description diff --git a/interfaces/interfacestest/renderer.go b/interfaces/interfacestest/renderer.go index 6a1543a..f46bade 100644 --- a/interfaces/interfacestest/renderer.go +++ b/interfaces/interfacestest/renderer.go @@ -21,22 +21,22 @@ var _ interfaces.Renderer = &RendererMock{} // RendererMock is a mock implementation of interfaces.Renderer. // -// func TestSomethingThatUsesRenderer(t *testing.T) { +// func TestSomethingThatUsesRenderer(t *testing.T) { // -// // make and configure a mocked interfaces.Renderer -// mockedRenderer := &RendererMock{ -// BuildPageFunc: func(w io.Writer, pageModel interface{}, templateName string) { -// panic("mock out the BuildPage method") -// }, -// NewBasePageModelFunc: func() model.Page { -// panic("mock out the NewBasePageModel method") -// }, -// } +// // make and configure a mocked interfaces.Renderer +// mockedRenderer := &RendererMock{ +// BuildPageFunc: func(w io.Writer, pageModel interface{}, templateName string) { +// panic("mock out the BuildPage method") +// }, +// NewBasePageModelFunc: func() model.Page { +// panic("mock out the NewBasePageModel method") +// }, +// } // -// // use mockedRenderer in code that requires interfaces.Renderer -// // and then make assertions. +// // use mockedRenderer in code that requires interfaces.Renderer +// // and then make assertions. // -// } +// } type RendererMock struct { // BuildPageFunc mocks the BuildPage method. BuildPageFunc func(w io.Writer, pageModel interface{}, templateName string) @@ -83,7 +83,8 @@ func (mock *RendererMock) BuildPage(w io.Writer, pageModel interface{}, template // BuildPageCalls gets all the calls that were made to BuildPage. // Check the length with: -// len(mockedRenderer.BuildPageCalls()) +// +// len(mockedRenderer.BuildPageCalls()) func (mock *RendererMock) BuildPageCalls() []struct { W io.Writer PageModel interface{} @@ -115,7 +116,8 @@ func (mock *RendererMock) NewBasePageModel() model.Page { // NewBasePageModelCalls gets all the calls that were made to NewBasePageModel. // Check the length with: -// len(mockedRenderer.NewBasePageModelCalls()) +// +// len(mockedRenderer.NewBasePageModelCalls()) func (mock *RendererMock) NewBasePageModelCalls() []struct { } { var calls []struct { diff --git a/main.go b/main.go index c4a0b7f..46abc7f 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "os/signal" "time" + cacheHelper "github.com/ONSdigital/dp-frontend-cache-helper/pkg/navigation/helper" "github.com/ONSdigital/dp-frontend-feedback-controller/assets" "github.com/ONSdigital/dp-frontend-feedback-controller/config" "github.com/ONSdigital/dp-frontend-feedback-controller/routes" @@ -53,10 +54,25 @@ func main() { os.Exit(1) } + cacheConfig := cacheHelper.Config{ + APIRouterURL: cfg.APIRouterURL, + CacheUpdateInterval: cfg.CacheUpdateInterval, + EnableNewNavBar: cfg.EnableNewNavBar, + EnableCensusTopicSubsection: cfg.EnableCensusTopicSubsection, + CensusTopicID: cfg.CensusTopicID, + IsPublishingMode: cfg.IsPublishingMode, + Languages: cfg.SupportedLanguages, + ServiceAuthToken: cfg.ServiceAuthToken, + } + + svcErrors := make(chan error, 0) + cacheService, err := cacheHelper.Init(ctx, cacheConfig) + cacheService.RunUpdates(ctx, svcErrors) + // nolint: typecheck rend := render.NewWithDefaultClient(assets.Asset, assets.AssetNames, cfg.PatternLibraryAssetsPath, cfg.SiteDomain) - routes.Setup(ctx, r, cfg, rend, healthcheck) + routes.Setup(ctx, r, cfg, rend, healthcheck, cacheService) healthcheck.Start(ctx) diff --git a/routes/routes.go b/routes/routes.go index fc50e25..d4f78ea 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -12,13 +12,14 @@ import ( render "github.com/ONSdigital/dp-renderer" + cacheHelper "github.com/ONSdigital/dp-frontend-cache-helper/pkg/navigation/helper" health "github.com/ONSdigital/dp-healthcheck/healthcheck" "github.com/ONSdigital/log.go/v2/log" "github.com/gorilla/mux" ) // Setup registers routes for the service -func Setup(ctx context.Context, r *mux.Router, cfg *config.Config, rend *render.Render, hc health.HealthCheck) { +func Setup(ctx context.Context, r *mux.Router, cfg *config.Config, rend *render.Render, hc health.HealthCheck, cacheService *cacheHelper.Helper) { auth := smtp.PlainAuth( "", cfg.MailUser, @@ -37,10 +38,10 @@ func Setup(ctx context.Context, r *mux.Router, cfg *config.Config, rend *render. log.Info(ctx, "adding routes") r.StrictSlash(true).Path("/health").HandlerFunc(hc.Handler) - r.StrictSlash(true).Path("/feedback").Methods("GET").HandlerFunc(handlers.GetFeedback(rend)) - r.StrictSlash(true).Path("/feedback").Methods("POST").HandlerFunc(handlers.AddFeedback(cfg.FeedbackTo, cfg.FeedbackFrom, false, rend, emailSender)) - r.StrictSlash(true).Path("/feedback/thanks").Methods("GET").HandlerFunc(handlers.FeedbackThanks(rend)) - r.StrictSlash(true).Path("/feedback/thanks").Methods("POST").HandlerFunc(handlers.AddFeedback(cfg.FeedbackTo, cfg.FeedbackFrom, false, rend, emailSender)) + r.StrictSlash(true).Path("/feedback").Methods("GET").HandlerFunc(handlers.GetFeedback(rend, cacheService)) + r.StrictSlash(true).Path("/feedback").Methods("POST").HandlerFunc(handlers.AddFeedback(cfg.FeedbackTo, cfg.FeedbackFrom, false, rend, emailSender, cacheService)) + r.StrictSlash(true).Path("/feedback/thanks").Methods("GET").HandlerFunc(handlers.FeedbackThanks(rend, cacheService)) + r.StrictSlash(true).Path("/feedback/thanks").Methods("POST").HandlerFunc(handlers.AddFeedback(cfg.FeedbackTo, cfg.FeedbackFrom, false, rend, emailSender, cacheService)) } type unencryptedAuth struct {