Skip to content

Commit

Permalink
Merge pull request #45 from lifeomic/PW-850
Browse files Browse the repository at this point in the history
[PW-850] Add app link
  • Loading branch information
0xch4z authored Oct 5, 2022
2 parents 8b67cff + c5ced74 commit 940a34e
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ in this repository to demonstrate usage.
In order to build the provider from source, you'll need to have [go][go-binaries]1.19+
installed. Then run `make build`.

### Regenerating GQL Client

If you're picking up changes to GQL APIs, run `make generate`

### Using a local provider build

Refer to the upstream documentation on [development overrides][tf-dev-overrides].
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/marketplace_wellness_offering.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ marketplace_wellness_offering manages Wellness Offering subsidies
- `install_url` (String)
- `is_enabled` (Boolean)
- `marketplace_provider` (String)
- `subsidy_type` (String)
- `subsidy_type` (String) One of SERVICE | REDEMPTION | LIFE_LEAGUE_PARTNER | LIFE_LEAGUE_PARENT
- `title` (String) The title of the Wellness Offering

### Optional

- `app_link` (String) Link to open the subsidy in-app
- `id` (String) An optional id for the Wellness Offering
- `is_test_module` (Boolean)
- `parent_module_id` (String)
Expand Down
28 changes: 28 additions & 0 deletions internal/gqlclient/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/gqlclient/marketplace.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fragment WellnessOfferingSource on WellnessOffering {
configurationSchema
approximateUnitCost
subsidyType
appLink
}

fragment WellnessOfferingModule on MarketplaceModule {
Expand Down
6 changes: 6 additions & 0 deletions internal/gqlclient/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,9 @@ type WebAppletTileBehavior {
}

type WellnessOffering {
"""The link to open details about the subsidy for the participant"""
appLink: String

"""The approximate per-redemption cost of the offering in pennies."""
approximateUnitCost: Int!

Expand Down Expand Up @@ -2166,6 +2169,9 @@ input WellnessOfferingInput {
}

input WellnessOfferingModuleSourceInfo {
"""The link to open details about the subsidy for the participant"""
appLink: String

"""The approximate per-redemption cost of the offering in pennies."""
approximateUnitCost: Int!

Expand Down
12 changes: 12 additions & 0 deletions internal/gqlclient/schemas/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -5922,6 +5922,18 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "appLink",
"description": "The link to open details about the subsidy for the participant",
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
22 changes: 22 additions & 0 deletions internal/gqlclient/schemas/marketplaceAuthed.json
Original file line number Diff line number Diff line change
Expand Up @@ -14566,6 +14566,16 @@
"ofType": null
},
"defaultValue": null
},
{
"name": "appLink",
"description": "The link to open details about the subsidy for the participant",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
Expand Down Expand Up @@ -19598,6 +19608,18 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "appLink",
"description": "The link to open details about the subsidy for the participant",
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
22 changes: 18 additions & 4 deletions internal/provider/resource_marketplace_wellness_offering.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type wellnessOffering struct {
InfoURL types.String `tfsdk:"info_url"`
ApproximateUnitCost types.Int64 `tfsdk:"approximate_unit_cost"`
SubsidyType types.String `tfsdk:"subsidy_type"`
AppLink types.String `tfsdk:"app_link"`
InstallURL types.String `tfsdk:"install_url"`
ConfigurationSchema types.String `tfsdk:"configuration_schema"`
IsEnabled types.Bool `tfsdk:"is_enabled"`
Expand Down Expand Up @@ -104,6 +105,11 @@ func (wellnessOfferingResourceType) GetSchema(_ context.Context) (tfsdk.Schema,
Type: types.StringType,
Description: "One of SERVICE | REDEMPTION | LIFE_LEAGUE_PARTNER | LIFE_LEAGUE_PARENT",
},
"app_link": {
Optional: true,
Type: types.StringType,
Description: "Link to open the subsidy in-app",
},
"is_test_module": {
Optional: true,
Type: types.BoolType,
Expand Down Expand Up @@ -180,6 +186,7 @@ func (w wellnessOfferingResource) Create(ctx context.Context, req tfsdk.CreateRe
ApproximateUnitCost: int(plan.ApproximateUnitCost.Value),
ConfigurationSchema: plan.ConfigurationSchema.Value,
SubsidyType: gqlclient.SubsidyType(plan.SubsidyType.Value),
AppLink: plan.AppLink.Value,
ImageUrl: plan.ImageURL.Value,
InfoUrl: plan.InfoURL.Value,
InstallUrl: plan.InstallURL.Value,
Expand Down Expand Up @@ -282,6 +289,7 @@ func (w wellnessOfferingResource) Update(ctx context.Context, req tfsdk.UpdateRe
ApproximateUnitCost: int(plan.ApproximateUnitCost.Value),
ConfigurationSchema: plan.ConfigurationSchema.Value,
SubsidyType: gqlclient.SubsidyType(plan.SubsidyType.Value),
AppLink: plan.AppLink.Value,
ImageUrl: plan.ImageURL.Value,
InfoUrl: plan.InfoURL.Value,
InstallUrl: plan.InstallURL.Value,
Expand Down Expand Up @@ -429,10 +437,16 @@ func setWellnessOfferingState(ctx context.Context, config *wellnessOffering, sta
IsTestModule: config.IsTestModule,
InstallURL: config.InstallURL,

ID: types.String{Value: w.Id},
Title: types.String{Value: w.Title},
Description: types.String{Value: w.Description},
SubsidyType: types.String{Value: string(source.SubsidyType)},
ID: types.String{Value: w.Id},
Title: types.String{Value: w.Title},
Description: types.String{Value: w.Description},
SubsidyType: types.String{Value: string(source.SubsidyType)},
AppLink: types.String{
// Since AppLink is optional, but GQL returns string for a null value
// we explicitly set this to null so we don't get inconsistent plans
Null: source.AppLink == "",
Value: source.AppLink,
},
MarketplaceProvider: types.String{Value: source.Provider},
Version: types.String{Value: w.Version},
ImageURL: types.String{Value: source.ImageUrl},
Expand Down
46 changes: 46 additions & 0 deletions internal/provider/resource_marketplace_wellness_offering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ func TestAccMarketplaceWellnessOffering_basic(t *testing.T) {
})
}

func TestAccMarketplaceWellnessOffering_basicWithAppLink(t *testing.T) {
skipNoLambda(t)
id, _ := uuid.GenerateUUID()
t.Setenv(common.HeadersEnvVar, getHeaders(t))
header, err := common.HeaderFromEnv()
if err != nil {
t.Fatalf("error getting required headers %v", err)
}

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProviderFactories,

Steps: []resource.TestStep{
{
Config: testAccOffering_withAppLink(id, true, defaultDesc),
Check: resource.ComposeAggregateTestCheckFunc(testCheckPublishedModule(t, id, header),
resource.TestCheckResourceAttr(testWellnessOfferingResName, "is_test_module", "true"),
resource.TestCheckResourceAttr(testWellnessOfferingResName, "is_approved", "true"),
resource.TestCheckResourceAttr(testWellnessOfferingResName, "app_link", "https://example.com"),
),
},
},
})
}

func TestAccMarketplaceWellnessOffering_basicUpdate(t *testing.T) {
skipNoLambda(t)
id, _ := uuid.GenerateUUID()
Expand Down Expand Up @@ -278,6 +303,27 @@ func testAccOffering_basic(id string, isTest bool, desc string) string {
}`, id, desc, isTest)
}

func testAccOffering_withAppLink(id string, isTest bool, desc string) string {
return fmt.Sprintf(`resource "lifeomic_marketplace_wellness_offering" "test" {
id = "%s"
title = "Fake Module"
description = "%s"
marketplace_provider = "LifeOmic"
image_url = "https://placekitten.com/1800/1600"
info_url = "https://example.com"
approximate_unit_cost = 10000
configuration_schema = jsonencode({
"version": "06-28-2021",
"fields": []
})
is_enabled = true
install_url = "lambda://wellness-service:deployed/v1/private/life-league"
subsidy_type = "SERVICE"
is_test_module = %t
app_link = "https://example.com"
}`, id, desc, isTest)
}

func testCheckPublishedModule(t *testing.T, id string, header map[string]string) func(s *terraform.State) error {
t.Helper()
return func(s *terraform.State) error {
Expand Down

0 comments on commit 940a34e

Please sign in to comment.