Skip to content

Commit

Permalink
chore: refactor to expose lib on usecases only
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellgithinji committed Sep 7, 2021
1 parent 0c1e36e commit 211fb44
Show file tree
Hide file tree
Showing 12 changed files with 1,232 additions and 25 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Engagement service
# Engagement Library

[![Maintained](https://img.shields.io/badge/Maintained-Actively-informational.svg?style=for-the-badge)](https://shields.io/)


[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) ![Linting and Tests](https://github.com/savannahghi/engagementcore/actions/workflows/ci.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/savannahghi/engagementcore/badge.svg?branch=develop)](https://coveralls.io/github/savannahghi/engagementcore?branch=develop)

A service that fetches and preprocesses content for the feed,library and faqs section in Bewell app.
A helper library for the [engagement-service](https://github.com/savannahghi/engagementcore-service) and other services that will contain some common functionalities used by these services

## Description

Expand Down Expand Up @@ -36,6 +36,21 @@ A cleanly architected project should be:
- _Independent of any external agency_: In fact your business rules simply
don’t know anything at all about the outside world.

## How to use this library

This project uses [semantic versioning](https://semver.org/) and can be imported as a package in the (engagement-service)[https://github.com/savannahghi/engagementcore-service] or any other service.

after importing the package, you can create a new instance from the `usecases`, and use the functionality exposed

## How to deploy changes for this projects

This is a library that uses semantic versioning hence every change made to the library, after approval and release, it must be tagged, then upgrade the (engagement-service)[https://github.com/savannahghi/engagementcore-service] with the latest tag version.

tagging
```sh
git tag -m "v0.0.n" "v0.0.n"
git push --tags
```
## This project has 5 layers:

### Domain Layer
Expand Down
6 changes: 0 additions & 6 deletions pkg/engagement/infrastructure/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
type Interactor struct {
repository.Repository
*fcm.ServiceFCMImpl
*fcm.RemotePushService
*library.ServiceLibraryImpl
*mail.ServiceMailImpl
messaging.NotificationService
Expand All @@ -52,10 +51,6 @@ func NewInteractor() Interactor {
onboarding := onboarding.NewRemoteProfileService(onboarding.NewOnboardingClient())

fcmOne := fcm.NewService(db, onboarding)
push, err := fcm.NewRemotePushService(ctx)
if err != nil {
log.Fatal(err)
}

lib := library.NewLibraryService(onboarding)

Expand All @@ -79,7 +74,6 @@ func NewInteractor() Interactor {
return Interactor{
db,
fcmOne,
push,
lib,
mail,
pubsub,
Expand Down
96 changes: 84 additions & 12 deletions pkg/engagement/infrastructure/services/fcm/mock/fcm_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,98 @@ package mock

import (
"context"
"time"

"github.com/savannahghi/engagementcore/pkg/engagement/application/common/dto"
"github.com/savannahghi/firebasetools"
)

// FakeServiceFcm simulates the behavior of our FCM push implementation
type FakeServiceFcm struct {
PushFn func(
SendNotificationFn func(
ctx context.Context,
sender string,
payload firebasetools.SendNotificationPayload,
) error
registrationTokens []string,
data map[string]string,
notification *firebasetools.FirebaseSimpleNotificationInput,
android *firebasetools.FirebaseAndroidConfigInput,
ios *firebasetools.FirebaseAPNSConfigInput,
web *firebasetools.FirebaseWebpushConfigInput,
) (bool, error)

NotificationsFn func(
ctx context.Context,
registrationToken string,
newerThan time.Time,
limit int,
) ([]*dto.SavedNotification, error)

SendFCMByPhoneOrEmailFn func(
ctx context.Context,
phoneNumber *string,
email *string,
data map[string]interface{},
notification firebasetools.FirebaseSimpleNotificationInput,
android *firebasetools.FirebaseAndroidConfigInput,
ios *firebasetools.FirebaseAPNSConfigInput,
web *firebasetools.FirebaseWebpushConfigInput,
) (bool, error)
}

// SendNotification is a mock of the SendNotification method
func (f *FakeServiceFcm) SendNotification(
ctx context.Context,
registrationTokens []string,
data map[string]string,
notification *firebasetools.FirebaseSimpleNotificationInput,
android *firebasetools.FirebaseAndroidConfigInput,
ios *firebasetools.FirebaseAPNSConfigInput,
web *firebasetools.FirebaseWebpushConfigInput,
) (bool, error) {
return f.SendNotificationFn(
ctx,
registrationTokens,
data,
notification,
android,
ios,
web,
)
}

// Notifications is a mock of the Notifications method
func (f *FakeServiceFcm) Notifications(
ctx context.Context,
registrationToken string,
newerThan time.Time,
limit int,
) ([]*dto.SavedNotification, error) {
return f.NotificationsFn(
ctx,
registrationToken,
newerThan,
limit,
)
}

// Push instructs a remote FCM service to send a push notification.
//
// This is done over Google Cloud Pub-Sub.
func (f *FakeServiceFcm) Push(
// SendFCMByPhoneOrEmail is a mock of the SendFCMByPhoneOrEmail method
func (f *FakeServiceFcm) SendFCMByPhoneOrEmail(
ctx context.Context,
sender string,
payload firebasetools.SendNotificationPayload,
) error {
return f.PushFn(ctx, sender, payload)
phoneNumber *string,
email *string,
data map[string]interface{},
notification firebasetools.FirebaseSimpleNotificationInput,
android *firebasetools.FirebaseAndroidConfigInput,
ios *firebasetools.FirebaseAPNSConfigInput,
web *firebasetools.FirebaseWebpushConfigInput,
) (bool, error) {
return f.SendFCMByPhoneOrEmailFn(
ctx,
phoneNumber,
email,
data,
notification,
android,
ios,
web,
)
}
Loading

0 comments on commit 211fb44

Please sign in to comment.