Repository: amp-labs/connectors
Pull request #1298 (2025-01-23 01:18:03)

[CON-883] feat(Stripe): ListObjectMetadata
# Test
![image](https://github.com/user-attachments/assets/9e9cc3aa-d49e-4749-af2f-c530d75e276a)


Cobalt0s: > [!WARNING]
> <b>This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1298?utm_source=stack-comment-downstack-mergeability-warning" >on Graphite</a>.</b>
> <a href="https://graphite.dev/docs/merge-pull-requests">Learn more</a>

* **#1299** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1299?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#1298** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1298?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈 <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1298?utm_source=stack-comment-view-in-graphite" target="_blank">(View in Graphite)</a>
* **#1297** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1297?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#1296** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1296?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* **#1295** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1295?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a>
* `main`


<h2></h2>

This stack of pull requests is managed by <a href="https://graphite.dev?utm-source=stack-comment"><b>Graphite</b></a>. Learn more about <a href="https://stacking.dev/?utm_source=stack-comment">stacking</a>.
<!-- Current dependencies on/for this PR: -->

Patch:
diff --git a/providers/stripe/metadata.go b/providers/stripe/metadata.go
new file mode 100644
index 00000000..2efe73b6
--- /dev/null
+++ b/providers/stripe/metadata.go
@@ -0,0 +1,14 @@
+package stripe
+
+import (
+	"context"
+
+	"github.com/amp-labs/connectors/common"
+	"github.com/amp-labs/connectors/providers/stripe/metadata"
+)
+
+func (c *Connector) ListObjectMetadata(
+	ctx context.Context, objectNames []string,
+) (*common.ListObjectMetadataResult, error) {
+	return metadata.Schemas.Select(c.Module.ID, objectNames)
+}


Test patch:
diff --git a/providers/stripe/metadata_test.go b/providers/stripe/metadata_test.go
new file mode 100644
index 00000000..5b6583cd
--- /dev/null
+++ b/providers/stripe/metadata_test.go
@@ -0,0 +1,72 @@
+package stripe
+
+import (
+	"testing"
+
+	"github.com/amp-labs/connectors"
+	"github.com/amp-labs/connectors/common"
+	"github.com/amp-labs/connectors/test/utils/mockutils/mockserver"
+	"github.com/amp-labs/connectors/test/utils/testroutines"
+)
+
+func TestListObjectMetadata(t *testing.T) { // nolint:funlen,gocognit,cyclop
+	t.Parallel()
+
+	tests := []testroutines.Metadata{
+		{
+			Name:         "At least one object name must be queried",
+			Input:        nil,
+			Server:       mockserver.Dummy(),
+			ExpectedErrs: []error{common.ErrMissingObjects},
+		},
+		{
+			Name:         "Unknown object requested",
+			Input:        []string{"butterflies"},
+			Server:       mockserver.Dummy(),
+			ExpectedErrs: []error{common.ErrObjectNotSupported},
+		},
+		{
+			Name:       "Successfully describe multiple objects with metadata",
+			Input:      []string{"coupons", "products"},
+			Server:     mockserver.Dummy(),
+			Comparator: testroutines.ComparatorSubsetMetadata,
+			Expected: &common.ListObjectMetadataResult{
+				Result: map[string]common.ObjectMetadata{
+					"coupons": {
+						DisplayName: "Coupons",
+						FieldsMap: map[string]string{
+							"id":               "id",
+							"livemode":         "livemode",
+							"currency":         "currency",
+							"currency_options": "currency_options",
+							"percent_off":      "percent_off",
+						},
+					},
+					"products": {
+						DisplayName: "Products",
+						FieldsMap: map[string]string{
+							"id":            "id",
+							"images":        "images",
+							"default_price": "default_price",
+							"tax_code":      "tax_code",
+							"unit_label":    "unit_label",
+						},
+					},
+				},
+				Errors: nil,
+			},
+			ExpectedErrs: nil,
+		},
+	}
+
+	for _, tt := range tests {
+		// nolint:varnamelen
+		t.Run(tt.Name, func(t *testing.T) {
+			t.Parallel()
+
+			tt.Run(t, func() (connectors.ObjectMetadataConnector, error) {
+				return constructTestConnector(tt.Server.URL)
+			})
+		})
+	}
+}
diff --git a/test/stripe/metadata/customers/main.go b/test/stripe/metadata/customers/main.go
new file mode 100644
index 00000000..ab62d343
--- /dev/null
+++ b/test/stripe/metadata/customers/main.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+	"context"
+	"log/slog"
+	"os"
+	"os/signal"
+	"syscall"
+
+	connTest "github.com/amp-labs/connectors/test/stripe"
+	"github.com/amp-labs/connectors/test/utils"
+)
+
+var objectName = "customers"
+
+func main() {
+	// Handle Ctrl-C gracefully.
+	ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+	defer done()
+
+	// Set up slog logging.
+	utils.SetupLogging()
+
+	conn := connTest.GetStripeConnector(ctx)
+
+	metadata, err := conn.ListObjectMetadata(ctx, []string{
+		objectName,
+	})
+	if err != nil {
+		utils.Fail("error listing metadata for Stripe", "error", err)
+	}
+
+	slog.Info("Metadata " + objectName + "..")
+	utils.DumpJSON(metadata, os.Stdout)
+}