| package e2e |
|
|
| import ( |
| "context" |
| "fmt" |
| "net/http" |
| "testing" |
|
|
| "github.com/samber/lo" |
| "github.com/stretchr/testify/require" |
|
|
| api "github.com/openmeterio/openmeter/api/client/go" |
| ) |
|
|
| |
| func CreateCustomerWithSubject(t *testing.T, client *api.ClientWithResponses, customerKey string, subjectKey string) *api.Customer { |
| t.Helper() |
|
|
| ctx, cancel := context.WithCancel(context.Background()) |
| defer cancel() |
|
|
| |
| resp, err := client.CreateCustomerWithResponse(ctx, api.CreateCustomerJSONRequestBody{ |
| Name: fmt.Sprintf("Test Customer %s", customerKey), |
| Currency: lo.ToPtr("USD"), |
| Key: lo.ToPtr(customerKey), |
| PrimaryEmail: lo.ToPtr(fmt.Sprintf("test-%s@test.com", customerKey)), |
| UsageAttribution: &api.CustomerUsageAttribution{ |
| SubjectKeys: []string{subjectKey}, |
| }, |
| }) |
|
|
| require.NoError(t, err) |
| require.Equal(t, http.StatusCreated, resp.StatusCode(), "Invalid status code [response_body=%s]", string(resp.Body)) |
|
|
| require.Equal(t, []string{subjectKey}, resp.JSON201.UsageAttribution.SubjectKeys) |
|
|
| |
| { |
| resp, err := client.UpsertSubjectWithResponse(ctx, api.UpsertSubjectJSONRequestBody{ |
| api.SubjectUpsert{Key: subjectKey}, |
| }) |
| require.NoError(t, err) |
| require.Equal(t, http.StatusOK, resp.StatusCode(), "Invalid status code [response_body=%s]", string(resp.Body)) |
| } |
|
|
| return resp.JSON201 |
| } |
|
|
| func GetMeterIDBySlug(t *testing.T, client *api.ClientWithResponses, meterSlug string) string { |
| t.Helper() |
|
|
| resp, err := client.GetMeterWithResponse(context.Background(), meterSlug) |
| require.NoError(t, err) |
| require.Equal(t, http.StatusOK, resp.StatusCode(), "Invalid status code [response_body=%s]", string(resp.Body)) |
| require.NotNil(t, resp.JSON200) |
|
|
| return resp.JSON200.Id |
| } |
|
|