From 065deb7be4b7e8c2c350714c481d85686e0c8a3d Mon Sep 17 00:00:00 2001 From: Raymond Tukpe Date: Fri, 10 Jun 2022 11:07:09 +0100 Subject: [PATCH 1/3] feat: add subscription metadata --- datastore/models.go | 10 ++++-- docs/docs.go | 9 +++-- docs/swagger.json | 7 ++-- docs/swagger.yaml | 6 ++-- docs/v3/openapi3.json | 7 ++-- docs/v3/openapi3.yaml | 6 ++-- server/application.go | 3 +- server/models/models.go | 2 +- services/event_service.go | 12 +++---- services/subscription_service.go | 57 ++++++++++++++++++++++++++++++-- 10 files changed, 92 insertions(+), 27 deletions(-) diff --git a/datastore/models.go b/datastore/models.go index 8263651e1b..d160c2af85 100644 --- a/datastore/models.go +++ b/datastore/models.go @@ -439,8 +439,9 @@ type Subscription struct { SourceID string `json:"-" bson:"source_id"` EndpointID string `json:"-" bson:"endpoint_id"` - Source *Source `json:"source"` - Endpoint *Endpoint `json:"endpoint"` + Source *Source `json:"source_metadata,omitempty" bson:"-"` + Endpoint *Endpoint `json:"endpoint_metadata,omitempty" bson:"-"` + App *Application `json:"app_metadata,omitempty" bson:"-"` // subscription config AlertConfig *AlertConfiguration `json:"alert_config,omitempty" bson:"alert_config,omitempty"` @@ -604,3 +605,8 @@ func (p *Password) Matches() (bool, error) { return true, err } + +type EventMap map[string]*Event +type SourceMap map[string]*Source +type AppMap map[string]*Application +type EndpointMap map[string]*Endpoint diff --git a/docs/docs.go b/docs/docs.go index ca944e3412..0befed5010 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,6 +1,6 @@ // Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2022-06-09 18:25:28.184686 +0100 WAT m=+65.405881751 +// 2022-06-10 11:08:30.465468456 +0100 WAT m=+80.799317685 package docs import ( @@ -7689,13 +7689,16 @@ var doc = `{ "description": "subscription config", "$ref": "#/definitions/datastore.AlertConfiguration" }, + "app_metadata": { + "$ref": "#/definitions/datastore.Application" + }, "created_at": { "type": "string" }, "deleted_at": { "type": "string" }, - "endpoint": { + "endpoint_metadata": { "$ref": "#/definitions/datastore.Endpoint" }, "filter_config": { @@ -7707,7 +7710,7 @@ var doc = `{ "retry_config": { "$ref": "#/definitions/datastore.RetryConfiguration" }, - "source": { + "source_metadata": { "$ref": "#/definitions/datastore.Source" }, "status": { diff --git a/docs/swagger.json b/docs/swagger.json index f4a920fbc8..dda291fb7c 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -7677,13 +7677,16 @@ "description": "subscription config", "$ref": "#/definitions/datastore.AlertConfiguration" }, + "app_metadata": { + "$ref": "#/definitions/datastore.Application" + }, "created_at": { "type": "string" }, "deleted_at": { "type": "string" }, - "endpoint": { + "endpoint_metadata": { "$ref": "#/definitions/datastore.Endpoint" }, "filter_config": { @@ -7695,7 +7698,7 @@ "retry_config": { "$ref": "#/definitions/datastore.RetryConfiguration" }, - "source": { + "source_metadata": { "$ref": "#/definitions/datastore.Source" }, "status": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 86ad8fc003..065ff71554 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -411,11 +411,13 @@ definitions: alert_config: $ref: '#/definitions/datastore.AlertConfiguration' description: subscription config + app_metadata: + $ref: '#/definitions/datastore.Application' created_at: type: string deleted_at: type: string - endpoint: + endpoint_metadata: $ref: '#/definitions/datastore.Endpoint' filter_config: $ref: '#/definitions/datastore.FilterConfiguration' @@ -423,7 +425,7 @@ definitions: type: string retry_config: $ref: '#/definitions/datastore.RetryConfiguration' - source: + source_metadata: $ref: '#/definitions/datastore.Source' status: type: string diff --git a/docs/v3/openapi3.json b/docs/v3/openapi3.json index ed3187fc45..ed81a09333 100644 --- a/docs/v3/openapi3.json +++ b/docs/v3/openapi3.json @@ -609,13 +609,16 @@ "alert_config": { "$ref": "#/components/schemas/datastore.AlertConfiguration" }, + "app_metadata": { + "$ref": "#/components/schemas/datastore.Application" + }, "created_at": { "type": "string" }, "deleted_at": { "type": "string" }, - "endpoint": { + "endpoint_metadata": { "$ref": "#/components/schemas/datastore.Endpoint" }, "filter_config": { @@ -627,7 +630,7 @@ "retry_config": { "$ref": "#/components/schemas/datastore.RetryConfiguration" }, - "source": { + "source_metadata": { "$ref": "#/components/schemas/datastore.Source" }, "status": { diff --git a/docs/v3/openapi3.yaml b/docs/v3/openapi3.yaml index 593db4a1e4..b3cb696d2c 100644 --- a/docs/v3/openapi3.yaml +++ b/docs/v3/openapi3.yaml @@ -410,11 +410,13 @@ components: properties: alert_config: $ref: '#/components/schemas/datastore.AlertConfiguration' + app_metadata: + $ref: '#/components/schemas/datastore.Application' created_at: type: string deleted_at: type: string - endpoint: + endpoint_metadata: $ref: '#/components/schemas/datastore.Endpoint' filter_config: $ref: '#/components/schemas/datastore.FilterConfiguration' @@ -422,7 +424,7 @@ components: type: string retry_config: $ref: '#/components/schemas/datastore.RetryConfiguration' - source: + source_metadata: $ref: '#/components/schemas/datastore.Source' status: type: string diff --git a/server/application.go b/server/application.go index 24af550d18..f3cde3bf1d 100644 --- a/server/application.go +++ b/server/application.go @@ -76,7 +76,7 @@ func newApplicationHandler( gs := services.NewGroupService(appRepo, groupRepo, eventRepo, eventDeliveryRepo, limiter) ss := services.NewSecurityService(groupRepo, apiKeyRepo) os := services.NewOrganisationService(orgRepo, orgMemberRepo) - rs := services.NewSubscriptionService(subRepo) + rs := services.NewSubscriptionService(subRepo, appRepo, sourceRepo) sos := services.NewSourceService(sourceRepo) us := services.NewUserService(userRepo, cache) ois := services.NewOrganisationInviteService(orgRepo, userRepo, orgMemberRepo, orgInviteRepo) @@ -293,7 +293,6 @@ func (a *applicationHandler) CreateAppEndpoint(w http.ResponseWriter, r *http.Re // @Security ApiKeyAuth // @Router /applications/{appID}/endpoints/{endpointID} [get] func (a *applicationHandler) GetAppEndpoint(w http.ResponseWriter, r *http.Request) { - _ = render.Render(w, r, newServerResponse("App endpoint fetched successfully", *getApplicationEndpointFromContext(r.Context()), http.StatusOK)) } diff --git a/server/models/models.go b/server/models/models.go index 98db4ca06b..9d34f3f4fa 100644 --- a/server/models/models.go +++ b/server/models/models.go @@ -198,7 +198,7 @@ type Subscription struct { Name string `json:"name" bson:"name" valid:"required~please provide a valid subscription name"` Type string `json:"type" bson:"type" valid:"required~please provide a valid subscription type"` AppID string `json:"app_id" bson:"app_id" valid:"required~please provide a valid app id"` - SourceID string `json:"source_id" bson:"source_id" valid:"required~please provide a valid source id"` + SourceID string `json:"source_id" bson:"source_id"` EndpointID string `json:"endpoint_id" bson:"endpoint_id" valid:"required~please provide a valid endpoint id"` AlertConfig *datastore.AlertConfiguration `json:"alert_config,omitempty" bson:"alert_config,omitempty"` diff --git a/services/event_service.go b/services/event_service.go index ef96f824c2..66bcc8461c 100644 --- a/services/event_service.go +++ b/services/event_service.go @@ -30,10 +30,6 @@ type EventService struct { searcher searcher.Searcher } -type EventMap map[string]*datastore.Event -type AppMap map[string]*datastore.Application -type EndpointMap map[string]*datastore.Endpoint - func NewEventService(appRepo datastore.ApplicationRepository, eventRepo datastore.EventRepository, eventDeliveryRepo datastore.EventDeliveryRepository, queue queue.Queuer, cache cache.Cache, seacher searcher.Searcher, subRepo datastore.SubscriptionRepository) *EventService { return &EventService{appRepo: appRepo, eventRepo: eventRepo, eventDeliveryRepo: eventDeliveryRepo, queue: queue, cache: cache, searcher: seacher, subRepo: subRepo} @@ -233,7 +229,7 @@ func (e *EventService) GetEventsPaged(ctx context.Context, filter *datastore.Fil return nil, datastore.PaginationData{}, NewServiceError(http.StatusInternalServerError, errors.New("an error occurred while fetching events")) } - appMap := AppMap{} + appMap := datastore.AppMap{} for i, event := range events { if _, ok := appMap[event.AppID]; !ok { a, _ := e.appRepo.FindApplicationByID(ctx, event.AppID) @@ -259,9 +255,9 @@ func (e *EventService) GetEventDeliveriesPaged(ctx context.Context, filter *data return nil, datastore.PaginationData{}, NewServiceError(http.StatusInternalServerError, errors.New("an error occurred while fetching event deliveries")) } - appMap := AppMap{} - eventMap := EventMap{} - endpointMap := EndpointMap{} + appMap := datastore.AppMap{} + eventMap := datastore.EventMap{} + endpointMap := datastore.EndpointMap{} for i, ed := range deliveries { if _, ok := appMap[ed.AppID]; !ok { diff --git a/services/subscription_service.go b/services/subscription_service.go index 2eb6abfa1e..6e8cf82b01 100644 --- a/services/subscription_service.go +++ b/services/subscription_service.go @@ -24,11 +24,13 @@ var ( ) type SubcriptionService struct { - subRepo datastore.SubscriptionRepository + subRepo datastore.SubscriptionRepository + appRepo datastore.ApplicationRepository + sourceRepo datastore.SourceRepository } -func NewSubscriptionService(subRepo datastore.SubscriptionRepository) *SubcriptionService { - return &SubcriptionService{subRepo: subRepo} +func NewSubscriptionService(subRepo datastore.SubscriptionRepository, appRepo datastore.ApplicationRepository, sourceRepo datastore.SourceRepository) *SubcriptionService { + return &SubcriptionService{subRepo: subRepo, sourceRepo: sourceRepo, appRepo: appRepo} } func (s *SubcriptionService) CreateSubscription(ctx context.Context, groupID string, newSubscription *models.Subscription) (*datastore.Subscription, error) { @@ -156,5 +158,54 @@ func (s *SubcriptionService) LoadSubscriptionsPaged(ctx context.Context, groupId subscriptions = make([]datastore.Subscription, 0) } + appMap := datastore.AppMap{} + sourceMap := datastore.SourceMap{} + endpointMap := datastore.EndpointMap{} + + for i, sub := range subscriptions { + if _, ok := appMap[sub.AppID]; !ok { + a, _ := s.appRepo.FindApplicationByID(ctx, sub.AppID) + aa := &datastore.Application{ + UID: a.UID, + Title: a.Title, + GroupID: a.GroupID, + SupportEmail: a.SupportEmail, + } + appMap[sub.AppID] = aa + } + + if _, ok := sourceMap[sub.SourceID]; !ok { + ev, _ := s.sourceRepo.FindSourceByID(ctx, sub.GroupID, sub.SourceID) + source := &datastore.Source{ + UID: ev.UID, + Name: ev.Name, + Type: ev.Type, + Verifier: ev.Verifier, + GroupID: sub.GroupID, + MaskID: ev.MaskID, + IsDisabled: ev.IsDisabled, + } + sourceMap[sub.SourceID] = source + } + + if _, ok := endpointMap[sub.EndpointID]; !ok { + en, _ := s.appRepo.FindApplicationEndpointByID(ctx, sub.AppID, sub.EndpointID) + endpoint := &datastore.Endpoint{ + UID: en.UID, + TargetURL: en.TargetURL, + DocumentStatus: en.DocumentStatus, + Secret: en.Secret, + HttpTimeout: en.HttpTimeout, + RateLimit: en.RateLimit, + RateLimitDuration: en.RateLimitDuration, + } + endpointMap[sub.EndpointID] = endpoint + } + + subscriptions[i].App = appMap[sub.AppID] + subscriptions[i].Source = sourceMap[sub.SourceID] + subscriptions[i].Endpoint = endpointMap[sub.EndpointID] + } + return subscriptions, paginatedData, nil } From aa3c1e90d0cb9916b64c1a4814aaf9d11954c337 Mon Sep 17 00:00:00 2001 From: Raymond Tukpe Date: Fri, 10 Jun 2022 12:50:13 +0100 Subject: [PATCH 2/3] feat: add metadata fields to event deliery --- server/middleware.go | 38 ++++++++- server/route.go | 6 +- services/event_service.go | 56 ++++++++----- services/subscription_service.go | 60 +++++++------- services/subscription_service_test.go | 112 ++++++++++++++++++++++++-- 5 files changed, 213 insertions(+), 59 deletions(-) diff --git a/server/middleware.go b/server/middleware.go index 466f9f56b5..2068046b76 100644 --- a/server/middleware.go +++ b/server/middleware.go @@ -419,12 +419,12 @@ func requireOrganisationMemberRole(roleType auth.RoleType) func(next http.Handle } } -func requireEventDelivery(eventRepo datastore.EventDeliveryRepository) func(next http.Handler) http.Handler { +func requireEventDelivery(eventDeliveryRepo datastore.EventDeliveryRepository, appRepo datastore.ApplicationRepository, eventRepo datastore.EventRepository) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { eventDeliveryID := chi.URLParam(r, "eventDeliveryID") - eventDelivery, err := eventRepo.FindEventDeliveryByID(r.Context(), eventDeliveryID) + eventDelivery, err := eventDeliveryRepo.FindEventDeliveryByID(r.Context(), eventDeliveryID) if err != nil { eventDelivery := "an error occurred while retrieving event delivery details" @@ -439,6 +439,40 @@ func requireEventDelivery(eventRepo datastore.EventDeliveryRepository) func(next return } + a, err := appRepo.FindApplicationByID(r.Context(), eventDelivery.AppID) + if err == nil { + app := &datastore.Application{ + UID: a.UID, + Title: a.Title, + GroupID: a.GroupID, + SupportEmail: a.SupportEmail, + } + eventDelivery.App = app + } + + ev, err := eventRepo.FindEventByID(r.Context(), eventDelivery.EventID) + if err == nil { + event := &datastore.Event{ + UID: ev.UID, + EventType: ev.EventType, + } + eventDelivery.Event = event + } + + en, err := appRepo.FindApplicationEndpointByID(r.Context(), eventDelivery.AppID, eventDelivery.EndpointID) + if err == nil { + endpoint := &datastore.Endpoint{ + UID: en.UID, + TargetURL: en.TargetURL, + DocumentStatus: en.DocumentStatus, + Secret: en.Secret, + HttpTimeout: en.HttpTimeout, + RateLimit: en.RateLimit, + RateLimitDuration: en.RateLimitDuration, + } + eventDelivery.Endpoint = endpoint + } + r = r.WithContext(setEventDeliveryInContext(r.Context(), eventDelivery)) next.ServeHTTP(w, r) }) diff --git a/server/route.go b/server/route.go index 00540077b5..d4702ee052 100644 --- a/server/route.go +++ b/server/route.go @@ -147,7 +147,7 @@ func buildRoutes(app *applicationHandler) http.Handler { eventDeliveryRouter.Get("/countbatchretryevents", app.CountAffectedEventDeliveries) eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) { - eventDeliverySubRouter.Use(requireEventDelivery(app.eventDeliveryRepo)) + eventDeliverySubRouter.Use(requireEventDelivery(app.eventDeliveryRepo, app.appRepo, app.eventRepo)) eventDeliverySubRouter.Get("/", app.GetEventDelivery) eventDeliverySubRouter.Put("/resend", app.ResendEventDelivery) @@ -341,7 +341,7 @@ func buildRoutes(app *applicationHandler) http.Handler { eventDeliveryRouter.Get("/countbatchretryevents", app.CountAffectedEventDeliveries) eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) { - eventDeliverySubRouter.Use(requireEventDelivery(app.eventDeliveryRepo)) + eventDeliverySubRouter.Use(requireEventDelivery(app.eventDeliveryRepo, app.appRepo, app.eventRepo)) eventDeliverySubRouter.Get("/", app.GetEventDelivery) eventDeliverySubRouter.Put("/resend", app.ResendEventDelivery) @@ -448,7 +448,7 @@ func buildRoutes(app *applicationHandler) http.Handler { eventDeliveryRouter.Get("/countbatchretryevents", app.CountAffectedEventDeliveries) eventDeliveryRouter.Route("/{eventDeliveryID}", func(eventDeliverySubRouter chi.Router) { - eventDeliverySubRouter.Use(requireEventDelivery(app.eventDeliveryRepo)) + eventDeliverySubRouter.Use(requireEventDelivery(app.eventDeliveryRepo, app.appRepo, app.eventRepo)) eventDeliverySubRouter.Get("/", app.GetEventDelivery) eventDeliverySubRouter.Put("/resend", app.ResendEventDelivery) diff --git a/services/event_service.go b/services/event_service.go index 66bcc8461c..9a9ac99fb1 100644 --- a/services/event_service.go +++ b/services/event_service.go @@ -261,37 +261,43 @@ func (e *EventService) GetEventDeliveriesPaged(ctx context.Context, filter *data for i, ed := range deliveries { if _, ok := appMap[ed.AppID]; !ok { - a, _ := e.appRepo.FindApplicationByID(ctx, ed.AppID) - aa := &datastore.Application{ - UID: a.UID, - Title: a.Title, - GroupID: a.GroupID, - SupportEmail: a.SupportEmail, + a, err := e.appRepo.FindApplicationByID(ctx, ed.AppID) + if err == nil { + aa := &datastore.Application{ + UID: a.UID, + Title: a.Title, + GroupID: a.GroupID, + SupportEmail: a.SupportEmail, + } + appMap[ed.AppID] = aa } - appMap[ed.AppID] = aa } if _, ok := eventMap[ed.EventID]; !ok { - ev, _ := e.eventRepo.FindEventByID(ctx, ed.EventID) - event := &datastore.Event{ - UID: ev.UID, - EventType: ev.EventType, + ev, err := e.eventRepo.FindEventByID(ctx, ed.EventID) + if err == nil { + event := &datastore.Event{ + UID: ev.UID, + EventType: ev.EventType, + } + eventMap[ed.EventID] = event } - eventMap[ed.EventID] = event } if _, ok := endpointMap[ed.EndpointID]; !ok { - en, _ := e.appRepo.FindApplicationEndpointByID(ctx, ed.AppID, ed.EndpointID) - endpoint := &datastore.Endpoint{ - UID: en.UID, - TargetURL: en.TargetURL, - DocumentStatus: en.DocumentStatus, - Secret: en.Secret, - HttpTimeout: en.HttpTimeout, - RateLimit: en.RateLimit, - RateLimitDuration: en.RateLimitDuration, + en, err := e.appRepo.FindApplicationEndpointByID(ctx, ed.AppID, ed.EndpointID) + if err == nil { + endpoint := &datastore.Endpoint{ + UID: en.UID, + TargetURL: en.TargetURL, + DocumentStatus: en.DocumentStatus, + Secret: en.Secret, + HttpTimeout: en.HttpTimeout, + RateLimit: en.RateLimit, + RateLimitDuration: en.RateLimitDuration, + } + endpointMap[ed.EndpointID] = endpoint } - endpointMap[ed.EndpointID] = endpoint } deliveries[i].App = appMap[ed.AppID] @@ -378,3 +384,9 @@ func (e *EventService) requeueEventDelivery(ctx context.Context, eventDelivery * } return nil } + +func (e *EventService) populateEventDeliveries(ctx context.Context, eventDelivery *datastore.EventDelivery) (*datastore.EventDelivery, error) { + + + return eventDelivery, nil +} diff --git a/services/subscription_service.go b/services/subscription_service.go index 6e8cf82b01..ba2d843b39 100644 --- a/services/subscription_service.go +++ b/services/subscription_service.go @@ -164,42 +164,48 @@ func (s *SubcriptionService) LoadSubscriptionsPaged(ctx context.Context, groupId for i, sub := range subscriptions { if _, ok := appMap[sub.AppID]; !ok { - a, _ := s.appRepo.FindApplicationByID(ctx, sub.AppID) - aa := &datastore.Application{ - UID: a.UID, - Title: a.Title, - GroupID: a.GroupID, - SupportEmail: a.SupportEmail, + a, err := s.appRepo.FindApplicationByID(ctx, sub.AppID) + if err == nil { + aa := &datastore.Application{ + UID: a.UID, + Title: a.Title, + GroupID: a.GroupID, + SupportEmail: a.SupportEmail, + } + appMap[sub.AppID] = aa } - appMap[sub.AppID] = aa } if _, ok := sourceMap[sub.SourceID]; !ok { - ev, _ := s.sourceRepo.FindSourceByID(ctx, sub.GroupID, sub.SourceID) - source := &datastore.Source{ - UID: ev.UID, - Name: ev.Name, - Type: ev.Type, - Verifier: ev.Verifier, - GroupID: sub.GroupID, - MaskID: ev.MaskID, - IsDisabled: ev.IsDisabled, + ev, err := s.sourceRepo.FindSourceByID(ctx, sub.GroupID, sub.SourceID) + if err == nil { + source := &datastore.Source{ + UID: ev.UID, + Name: ev.Name, + Type: ev.Type, + Verifier: ev.Verifier, + GroupID: ev.GroupID, + MaskID: ev.MaskID, + IsDisabled: ev.IsDisabled, + } + sourceMap[sub.SourceID] = source } - sourceMap[sub.SourceID] = source } if _, ok := endpointMap[sub.EndpointID]; !ok { - en, _ := s.appRepo.FindApplicationEndpointByID(ctx, sub.AppID, sub.EndpointID) - endpoint := &datastore.Endpoint{ - UID: en.UID, - TargetURL: en.TargetURL, - DocumentStatus: en.DocumentStatus, - Secret: en.Secret, - HttpTimeout: en.HttpTimeout, - RateLimit: en.RateLimit, - RateLimitDuration: en.RateLimitDuration, + en, err := s.appRepo.FindApplicationEndpointByID(ctx, sub.AppID, sub.EndpointID) + if err == nil { + endpoint := &datastore.Endpoint{ + UID: en.UID, + TargetURL: en.TargetURL, + DocumentStatus: en.DocumentStatus, + Secret: en.Secret, + HttpTimeout: en.HttpTimeout, + RateLimit: en.RateLimit, + RateLimitDuration: en.RateLimitDuration, + } + endpointMap[sub.EndpointID] = endpoint } - endpointMap[sub.EndpointID] = endpoint } subscriptions[i].App = appMap[sub.AppID] diff --git a/services/subscription_service_test.go b/services/subscription_service_test.go index 085eb4c806..8a64c04d25 100644 --- a/services/subscription_service_test.go +++ b/services/subscription_service_test.go @@ -15,7 +15,9 @@ import ( func provideSubsctiptionService(ctrl *gomock.Controller) *SubcriptionService { subRepo := mocks.NewMockSubscriptionRepository(ctrl) - return NewSubscriptionService(subRepo) + appRepo := mocks.NewMockApplicationRepository(ctrl) + sourceRepo := mocks.NewMockSourceRepository(ctrl) + return NewSubscriptionService(subRepo, appRepo, sourceRepo) } func TestSubscription_CreateSubscription(t *testing.T) { @@ -255,8 +257,72 @@ func TestSubscription_LoadSubscriptionsPaged(t *testing.T) { }, }, wantSubscription: []datastore.Subscription{ - {UID: "123"}, - {UID: "123456"}, + { + UID: "123", + Source: &datastore.Source{ + UID: "123", + Name: "some name", + Type: datastore.HTTPSource, + Verifier: &datastore.VerifierConfig{ + Type: datastore.APIKeyVerifier, + ApiKey: datastore.ApiKey{ + APIKey: "123", + APIKeyHeader: "header", + }, + }, + GroupID: "123", + MaskID: "mask", + IsDisabled: false, + }, + App: &datastore.Application{ + UID: "abc", + Title: "Title", + GroupID: "123", + SupportEmail: "SupportEmail", + }, + Endpoint: &datastore.Endpoint{ + UID: "1234", + TargetURL: "http://localhost.com", + DocumentStatus: "Active", + Secret: "Secret", + HttpTimeout: "30s", + RateLimit: 10, + RateLimitDuration: "1h", + }, + }, + { + UID: "123456", + Source: &datastore.Source{ + UID: "123", + Name: "some name", + Type: datastore.HTTPSource, + Verifier: &datastore.VerifierConfig{ + Type: datastore.APIKeyVerifier, + ApiKey: datastore.ApiKey{ + APIKey: "123", + APIKeyHeader: "header", + }, + }, + GroupID: "123", + MaskID: "mask", + IsDisabled: false, + }, + App: &datastore.Application{ + UID: "abc", + Title: "Title", + GroupID: "123", + SupportEmail: "SupportEmail", + }, + Endpoint: &datastore.Endpoint{ + UID: "1234", + TargetURL: "http://localhost.com", + DocumentStatus: "Active", + Secret: "Secret", + HttpTimeout: "30s", + RateLimit: 10, + RateLimitDuration: "1h", + }, + }, }, wantPaginationData: datastore.PaginationData{ Total: 2, @@ -281,13 +347,49 @@ func TestSubscription_LoadSubscriptionsPaged(t *testing.T) { Next: 2, TotalPage: 3, }, nil) + + ap, _ := ss.appRepo.(*mocks.MockApplicationRepository) + ap.EXPECT().FindApplicationByID(gomock.Any(), gomock.Any()).Return(&datastore.Application{ + UID: "abc", + Title: "Title", + GroupID: "123", + SupportEmail: "SupportEmail", + }, nil).Times(1) + + ev, _ := ss.sourceRepo.(*mocks.MockSourceRepository) + ev.EXPECT().FindSourceByID(gomock.Any(), gomock.Any(), gomock.Any()).Return(&datastore.Source{ + UID: "123", + Name: "some name", + Type: datastore.HTTPSource, + Verifier: &datastore.VerifierConfig{ + Type: datastore.APIKeyVerifier, + ApiKey: datastore.ApiKey{ + APIKey: "123", + APIKeyHeader: "header", + }, + }, + GroupID: "123", + MaskID: "mask", + IsDisabled: false, + }, nil).Times(1) + + en, _ := ss.appRepo.(*mocks.MockApplicationRepository) + en.EXPECT().FindApplicationEndpointByID(gomock.Any(), gomock.Any(), gomock.Any()).Return(&datastore.Endpoint{ + UID: "1234", + TargetURL: "http://localhost.com", + DocumentStatus: "Active", + Secret: "Secret", + HttpTimeout: "30s", + RateLimit: 10, + RateLimitDuration: "1h", + }, nil).Times(1) }, }, { name: "should_fail_load_sources", args: args{ ctx: ctx, - group: &datastore.Group{UID: "12345"}, + group: &datastore.Group{UID: "123"}, pageable: datastore.Pageable{ Page: 1, PerPage: 10, @@ -309,7 +411,7 @@ func TestSubscription_LoadSubscriptionsPaged(t *testing.T) { name: "should_load_sources_empty_list", args: args{ ctx: ctx, - group: &datastore.Group{UID: "12345"}, + group: &datastore.Group{UID: "123"}, pageable: datastore.Pageable{ Page: 1, PerPage: 10, From 856b6237720e8f3d865c06f5114828329adbc938 Mon Sep 17 00:00:00 2001 From: Raymond Tukpe Date: Fri, 10 Jun 2022 14:12:03 +0100 Subject: [PATCH 3/3] chore: remove useless internal function --- services/event_service.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/services/event_service.go b/services/event_service.go index 9a9ac99fb1..e6fab29091 100644 --- a/services/event_service.go +++ b/services/event_service.go @@ -384,9 +384,3 @@ func (e *EventService) requeueEventDelivery(ctx context.Context, eventDelivery * } return nil } - -func (e *EventService) populateEventDeliveries(ctx context.Context, eventDelivery *datastore.EventDelivery) (*datastore.EventDelivery, error) { - - - return eventDelivery, nil -}