Skip to content

Commit

Permalink
add more test cases and make the code DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
timlubanga committed Sep 15, 2021
1 parent 8e095b0 commit 89e500c
Show file tree
Hide file tree
Showing 21 changed files with 538 additions and 68 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ jobs:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GOOGLE_CLOUD_PROJECT }}
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
export_default_credentials: true
project_id: ${{ secrets.GOOGLE_CLOUD_PROJECT }}
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
export_default_credentials: true
- name: Install Go
uses: actions/setup-go@v2
with:
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
gocov convert coverage.out > coverage.json
gocov report coverage.json > coverage_report.txt
tail coverage_report.txt
- name: Install goveralls
env:
GO111MODULE: off
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ require (
github.com/savannahghi/converterandformatter v0.0.9
github.com/savannahghi/enumutils v0.0.2
github.com/savannahghi/errorcodeutil v0.0.1
github.com/savannahghi/feedlib v0.0.1
github.com/savannahghi/feedlib v0.0.5
github.com/savannahghi/firebasetools v0.0.13
github.com/savannahghi/interserviceclient v0.0.13
github.com/savannahghi/profileutils v0.0.7
github.com/savannahghi/pubsubtools v0.0.2
github.com/savannahghi/scalarutils v0.0.2 // indirect
github.com/savannahghi/serverutils v0.0.3
github.com/savannahghi/serverutils v0.0.4
github.com/segmentio/ksuid v1.0.4
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ github.com/savannahghi/enumutils v0.0.2/go.mod h1:DDdjQBO1qyf5BxLzhTs1uN91drCIHH
github.com/savannahghi/errorcodeutil v0.0.1 h1:q5JYMrzXDAJ9/99fV7Mj2bFF1XOidlRgSlYHy73q2GA=
github.com/savannahghi/errorcodeutil v0.0.1/go.mod h1:nNBaBjatvoRusnDr2aRoNr4Rpmz9Z779mjcL0tr/IXk=
github.com/savannahghi/feedlib v0.0.0-20210628122532-ef88e353d4d6/go.mod h1:P6YHmWsa/TK/qTb2U1ryjuASotTQmbarArB0LYLjMo4=
github.com/savannahghi/feedlib v0.0.1 h1:BixXDyfj1Kj+f8AOwd32A/xXr5CZxrOqLitp09xDQcg=
github.com/savannahghi/feedlib v0.0.1/go.mod h1:P6YHmWsa/TK/qTb2U1ryjuASotTQmbarArB0LYLjMo4=
github.com/savannahghi/feedlib v0.0.5 h1:LQRLQoWCLFjCp4mkQncCNHJ/v9tg2D3yyzvSCnk3xRY=
github.com/savannahghi/feedlib v0.0.5/go.mod h1:PzEP7gw4w1Xuw36uIRr1H2ffd+kozWHyJCuGWO06AtQ=
github.com/savannahghi/firebasetools v0.0.5/go.mod h1:obAxyBfPaGTx/g86LF19gSmmEh5x+Tbnziatk514mUQ=
github.com/savannahghi/firebasetools v0.0.6/go.mod h1:obAxyBfPaGTx/g86LF19gSmmEh5x+Tbnziatk514mUQ=
github.com/savannahghi/firebasetools v0.0.13 h1:2eBFwzsnmhRUzxfgQZxOjedlMuyef2dz4tvpw59pJkE=
Expand All @@ -404,11 +404,10 @@ github.com/savannahghi/pubsubtools v0.0.2/go.mod h1:FQ+BxO4uA1ZkcziY4dR0uT9CKHVH
github.com/savannahghi/scalarutils v0.0.0-20210622091443-bad5089abdad/go.mod h1:Z+Dl3wc3vy5zKvthctHAtYzol1p8w27zEVRfOYueoks=
github.com/savannahghi/scalarutils v0.0.2 h1:naX6Zhv/tDbwKAKVY4bksyhnE43f2583xWesAKHb1CU=
github.com/savannahghi/scalarutils v0.0.2/go.mod h1:Z+Dl3wc3vy5zKvthctHAtYzol1p8w27zEVRfOYueoks=
github.com/savannahghi/server_utils v0.0.1 h1:q6SL4BRvkpYJujXvWwCl4vU1U+VTzKRGfNXnl0H6tfw=
github.com/savannahghi/server_utils v0.0.1/go.mod h1:Tldm4Op4ARxk8xaP3BA0V52XVZEJenkq0ck4FCdEp+I=
github.com/savannahghi/serverutils v0.0.2/go.mod h1:sLX0El0i0DKN/9cUkB8xqm5cVMP79qCZvK60EzB7Pa4=
github.com/savannahghi/serverutils v0.0.3 h1:1gX/zD6tt4tAEpcQFyzXBUp70BvUiqmJpjADqjdvFwI=
github.com/savannahghi/serverutils v0.0.3/go.mod h1:3VCEJ8BTHf/DW3WFjLqV4SznzrXaul/As2RJ5eNOO7U=
github.com/savannahghi/serverutils v0.0.4 h1:mQGAwhNgS1NPSBXqCeyywuGQFnvRxiOmHJEHPgzhWQE=
github.com/savannahghi/serverutils v0.0.4/go.mod h1:3VCEJ8BTHf/DW3WFjLqV4SznzrXaul/As2RJ5eNOO7U=
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
github.com/segmentio/ksuid v1.0.3/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE=
github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c=
Expand Down
2 changes: 1 addition & 1 deletion gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exec:

# model:
# filename: pkg/engagement/domain/model/models_gen.go
# package: model
# package: model

resolver:
layout: follow-schema
Expand Down
135 changes: 117 additions & 18 deletions pkg/engagement/infrastructure/database/firestore/default_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ const (
partnerAccountSetupActionName = "PARTNER_ACCOUNT_SETUP"
verifyEmailActionName = "VERIFY_EMAIL"

defaultOrg = "default-org-id-please-change"
defaultLocation = "default-location-id-please-change"
defaultContentDir = "/static/"
defaultAuthor = "Be.Well Team"
defaultInsuranceText = "Insurance Simplified"
onboardingService = "profile"
defaultOrg = "default-org-id-please-change"
defaultLocation = "default-location-id-please-change"
defaultContentDir = "/static/"
defaultAuthor = "Be.Well Team"
defaultInsuranceText = "Insurance Simplified"
onboardingService = "profile"
mp4Link1 = "https://a.bewell.co.ke/videos/what_you_can_do.mp4"
mp4Link2 = "https://a.bewell.co.ke/videos/how_to_add_cover.mp4"
youtubeLink1 = "https://youtu.be/-mlr9rjRXmc"
youtubeLink2 = "https://a.bewell.co.ke/videos/how_to_add_cover.mp4"
defaultTaglineorSummary = "See what you can do on your Be.Well app."
defaultText = "How to add your health insurance cover to your Be.Well app."
addCovertaglineorSummary = "Learn how to add your cover in 3 easy steps"
addCovertext = "View your health insurance cover benefits on your Be.Well app."
sladeTagline = "Learn what is Be.Well and how you can benefit from using it"
sladeSummary = "Be.Well is a virtual and physical healthcare community."
sladeText = "Be.Well is a virtual and physical healthcare community. Our goal is to make it easy for you to access affordable high-quality healthcare - whether online or in person."
)

// embed default content assets (e.g images and documents) in the binary
Expand Down Expand Up @@ -1198,7 +1209,7 @@ func getFeedWelcomeVideos(flavour feedlib.Flavour) []feedlib.Link {
return videos
}

func feedItemsFromCMSFeedTag(ctx context.Context, flavour feedlib.Flavour) []feedlib.Item {
func feedItemsFromCMSFeedTag(ctx context.Context, flavour feedlib.Flavour, playMP4 bool) []feedlib.Item {
ctx, span := tracer.Start(ctx, "feedItemsFromCMSFeedTag")
defer span.End()
// Initialize ISC clients
Expand Down Expand Up @@ -1227,15 +1238,103 @@ func feedItemsFromCMSFeedTag(ctx context.Context, flavour feedlib.Flavour) []fee
text := ""
sequenceNumber := int(time.Now().Unix())

if videoLink.URL == "https://youtu.be/-mlr9rjRXmc" {
tagline = "See what you can do on your Be.Well app"
summary = "See what you can do on your Be.Well app"
text = "How to add your health insurance cover to your Be.Well app."
if playMP4 {
//Change urls MP4 videos
if videoLink.URL == mp4Link1 {
tagline = defaultTaglineorSummary
summary = defaultTaglineorSummary
text = defaultText
}
if videoLink.URL == mp4Link2 {
tagline = addCovertaglineorSummary
summary = addCovertaglineorSummary
text = addCovertext
sequenceNumber = int(time.Now().Unix()) + 1
}
items = append(items, feedlib.Item{
ID: ksuid.New().String(),
SequenceNumber: sequenceNumber,
Expiry: future,
Persistent: false,
Status: feedlib.StatusPending,
Visibility: feedlib.VisibilityShow,
Icon: feedlib.GetPNGImageLink(common.DefaultIconPath, "Icon", "Feed Item Icon", common.DefaultIconPath),
Author: defaultAuthor,
Tagline: tagline,
Label: common.DefaultLabel,
Summary: summary,
Timestamp: time.Now(),
Text: text,
TextType: feedlib.TextTypeHTML,
Links: []feedlib.Link{
feedlib.GetMP4Link(
videoLink.URL,
videoLink.Title,
videoLink.Description,
videoLink.Thumbnail,
),
},
Actions: []feedlib.Action{},
Conversations: []feedlib.Message{},
Users: []string{},
Groups: []string{},
NotificationChannels: []feedlib.Channel{},
})

for _, post := range feedPosts {
if post == nil {
// non fatal, intentionally
log.Printf("ERROR: nil CMS post when adding welcome posts to feed")
continue
}
items = append(items, feedItemFromCMSPost(*post))
}

// add the slade 360 video last
items = append(items, feedlib.Item{
ID: ksuid.New().String(),
SequenceNumber: int(time.Now().Unix()),
Expiry: future,
Persistent: false,
Status: feedlib.StatusPending,
Visibility: feedlib.VisibilityShow,
Icon: feedlib.GetPNGImageLink(common.DefaultIconPath, "Icon", "Feed Item Icon", common.DefaultIconPath),
Author: defaultAuthor,
Tagline: sladeTagline,
Label: common.DefaultLabel,
Summary: sladeSummary,
Timestamp: time.Now(),
Text: sladeText,
TextType: feedlib.TextTypeHTML,
Links: []feedlib.Link{
feedlib.GetMP4Link(
"healthcare_simplified.mp4 ",
"Slade 360",
"Slade 360. HealthCare. Simplified.",
common.StaticBase+"/items/videos/thumbs/04_slade.png",
),
},
Actions: []feedlib.Action{},
Conversations: []feedlib.Message{},
Users: []string{},
Groups: []string{},
NotificationChannels: []feedlib.Channel{},
})

return items

}

// play youTube videos
if videoLink.URL == youtubeLink1 {
tagline = defaultTaglineorSummary
summary = defaultTaglineorSummary
text = defaultText
}
if videoLink.URL == "https://youtu.be/-iSB8yrSIps" {
tagline = "Learn how to add your cover in 3 easy steps"
summary = "Learn how to add your cover in 3 easy steps"
text = "View your health insurance cover benefits on your Be.Well app."
if videoLink.URL == youtubeLink2 {
tagline = addCovertaglineorSummary
summary = addCovertaglineorSummary
text = addCovertext
sequenceNumber = int(time.Now().Unix()) + 1
}

Expand Down Expand Up @@ -1289,11 +1388,11 @@ func feedItemsFromCMSFeedTag(ctx context.Context, flavour feedlib.Flavour) []fee
Visibility: feedlib.VisibilityShow,
Icon: feedlib.GetPNGImageLink(common.DefaultIconPath, "Icon", "Feed Item Icon", common.DefaultIconPath),
Author: defaultAuthor,
Tagline: "Learn what is Be.Well and how you can benefit from using it",
Tagline: sladeTagline,
Label: common.DefaultLabel,
Summary: "Be.Well is a virtual and physical healthcare community.",
Summary: sladeSummary,
Timestamp: time.Now(),
Text: "Be.Well is a virtual and physical healthcare community. Our goal is to make it easy for you to access affordable high-quality healthcare - whether online or in person.",
Text: sladeText,
TextType: feedlib.TextTypeHTML,
Links: []feedlib.Link{
feedlib.GetYoutubeVideoLink(
Expand Down
4 changes: 3 additions & 1 deletion pkg/engagement/infrastructure/database/firestore/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (fr Repository) GetFeed(
uid *string,
isAnonymous *bool,
flavour feedlib.Flavour,
playMP4 bool,
persistent feedlib.BooleanFilter,
status *feedlib.Status,
visibility *feedlib.Visibility,
Expand Down Expand Up @@ -201,6 +202,7 @@ func (fr Repository) GetFeed(
uid,
isAnonymous,
flavour,
playMP4,
persistent,
status,
visibility,
Expand All @@ -214,7 +216,7 @@ func (fr Repository) GetFeed(
Flavour: flavour,
Actions: actions,
Nudges: nudges,
Items: feedItemsFromCMSFeedTag(ctx, flavour),
Items: feedItemsFromCMSFeedTag(ctx, flavour,playMP4),
IsAnonymous: isAnonymous,
}

Expand Down

0 comments on commit 89e500c

Please sign in to comment.