Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
name: Build and test

# TODO: this step is not compatible with ubuntu 24 LTS, so we pin the version here instead of using ubuntu-latest
# TODO: this step is not compatible with ubuntu 24 LTS, so we pin the version here instead of using ubuntu-latest
runs-on: ubuntu-22.04

steps:
Expand All @@ -46,7 +46,48 @@ jobs:
- name: Build Release
run: dotnet build src -c Release /p:ContinuousIntegrationBuild=true

- name: Determine OpenAPI versions and extract specs
run: |
set -e -o pipefail

CURL_OPTS=(--retry 3 \
--retry-all-errors \
--fail \
--verbose \
--no-progress-meter \
--show-error)

LATEST_OPENAPI_VERSION=$(curl https://api.github.com/repos/stripe/openapi/releases/latest -s | jq .name -r)
CURRENT_OPENAPI_VERSION=$(cat OPENAPI_VERSION)
if [[ "$PR_BODY" == *"TEST USING LATEST OPENAPI"* ]]; then
OPENAPI_VERSION=$LATEST_OPENAPI_VERSION
else
OPENAPI_VERSION=$CURRENT_OPENAPI_VERSION
fi

CURRENT_OPENAPI_SPEC=$(realpath latest.yaml)
CURRENT_OPENAPI_SPEC_JSON=${CURRENT_OPENAPI_SPEC%.yaml}.json
CURRENT_FIXTURES_JSON=${CURRENT_OPENAPI_SPEC%/*}/fixtures.json

SPEC_NAME="spec3.sdk.yaml"
FIXTURES_NAME="fixtures3.json"
if [[ "$GITHUB_BASE" == *"b"* ]]; then
SPEC_NAME="spec3.beta.sdk.yaml"
FIXTURES_NAME="fixtures3.beta.json"
fi
curl "${CURL_OPTS[@]}" https://raw.githubusercontent.com/stripe/openapi/$OPENAPI_VERSION/openapi/${SPEC_NAME%.yaml}.json -o $CURRENT_OPENAPI_SPEC_JSON
curl "${CURL_OPTS[@]}" https://raw.githubusercontent.com/stripe/openapi/$OPENAPI_VERSION/openapi/$FIXTURES_NAME -o $CURRENT_FIXTURES_JSON

env:
PR_BODY: ${{ github.event.pull_request.body }}
GITHUB_BASE: ${{ github.base_ref || github.ref_name }}

- uses: stripe/openapi/actions/stripe-mock@master
with:
# Used to determine if stripe-mock runs in beta mode
base: ${{ github.base_ref || github.ref_name }}
fixtures: "/workspace/fixtures.json"
spec_path: "/workspace/latest.json"

- name: Run test suite
run: just ci-test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public BalanceTransactionTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/balance/history/txn_123");
var json = GetResourceAsString("api_fixtures.balance_transaction.json");
var balanceTransaction = JsonConvert.DeserializeObject<BalanceTransaction>(json);
Assert.NotNull(balanceTransaction);
Assert.IsType<BalanceTransaction>(balanceTransaction);
Expand Down
9 changes: 2 additions & 7 deletions src/StripeTests/Entities/BankAccounts/BankAccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void DeserializeForAccount()
[Fact]
public void DeserializeForCustomer()
{
string json = this.GetFixture("/v1/customers/cus_123/bank_accounts/ba_123");
var json = GetResourceAsString("api_fixtures.bank_account.json");
var bankAccount = JsonConvert.DeserializeObject<BankAccount>(json);
Assert.NotNull(bankAccount);
Assert.IsType<BankAccount>(bankAccount);
Expand All @@ -36,12 +36,7 @@ public void DeserializeForCustomer()
[Fact]
public void DeserializeWithExpansionsForCustomer()
{
string[] expansions =
{
"customer",
};

string json = this.GetFixture("/v1/customers/cus_123/bank_accounts/ba_123", expansions);
var json = GetResourceAsString("api_fixtures.bank_account_with_expansion.json");
var bankAccount = JsonConvert.DeserializeObject<BankAccount>(json);
Assert.NotNull(bankAccount);
Assert.IsType<BankAccount>(bankAccount);
Expand Down
9 changes: 2 additions & 7 deletions src/StripeTests/Entities/Cards/CardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CardTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/customers/cus_123/cards/card_123");
var json = GetResourceAsString("api_fixtures.customer_card.json");
var card = JsonConvert.DeserializeObject<Card>(json);
Assert.NotNull(card);
Assert.IsType<Card>(card);
Expand All @@ -25,12 +25,7 @@ public void Deserialize()
[Fact]
public void DeserializeWithExpansions()
{
string[] expansions =
{
"customer",
};

string json = this.GetFixture("/v1/customers/cus_123/cards/card_123", expansions);
var json = GetResourceAsString("api_fixtures.customer_card_with_expansion.json");
var card = JsonConvert.DeserializeObject<Card>(json);
Assert.NotNull(card);
Assert.IsType<Card>(card);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public SubscriptionScheduleTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/subscription_schedules/sub_sched_123");
var json = GetResourceAsString("api_fixtures.subscription_schedule.json");
var schedule = JsonConvert.DeserializeObject<SubscriptionSchedule>(json);
Assert.NotNull(schedule);
Assert.IsType<SubscriptionSchedule>(schedule);
Expand All @@ -25,16 +25,7 @@ public void Deserialize()
[Fact]
public void DeserializeWithExpansions()
{
// TODO: support expanding "phases.coupon" and "phases.plans.plan" and others with stripe-mock
string[] expansions =
{
"customer",
"default_settings.default_payment_method",
"phases.plans.plan",
"subscription",
};

string json = this.GetFixture("/v1/subscription_schedules/sub_sched_123", expansions);
var json = GetResourceAsString("api_fixtures.subscription_schedule_with_expansions.json");
var schedule = JsonConvert.DeserializeObject<SubscriptionSchedule>(json);
Assert.NotNull(schedule);
Assert.IsType<SubscriptionSchedule>(schedule);
Expand Down
12 changes: 2 additions & 10 deletions src/StripeTests/Entities/Subscriptions/SubscriptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public SubscriptionTest(StripeMockFixture stripeMockFixture)
[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/subscriptions/sub_123");
var json = GetResourceAsString("api_fixtures.subscription.json");
var subscription = JsonConvert.DeserializeObject<Subscription>(json);
Assert.NotNull(subscription);
Assert.IsType<Subscription>(subscription);
Expand All @@ -25,15 +25,7 @@ public void Deserialize()
[Fact]
public void DeserializeWithExpansions()
{
string[] expansions =
{
"customer",
"default_payment_method",
"latest_invoice",
"pending_setup_intent",
};

string json = this.GetFixture("/v1/subscriptions/sub_123", expansions);
var json = GetResourceAsString("api_fixtures.subscription_with_expansions.json");
var subscription = JsonConvert.DeserializeObject<Subscription>(json);
Assert.NotNull(subscription);
Assert.IsType<Subscription>(subscription);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "txn_123",
"object": "balance_transaction",
"source": {
"id": "random",
"object": "unknown_object"
}
}
16 changes: 16 additions & 0 deletions src/StripeTests/Resources/api_fixtures/bank_account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"account_holder_name": "Jane Austen",
"account_holder_type": "company",
"account_type": null,
"bank_name": "STRIPE TEST BANK",
"country": "US",
"currency": "usd",
"customer": null,
"fingerprint": "AuoSJ18zsVWV9SPc",
"id": "ba_123",
"last4": "6789",
"metadata": {},
"object": "bank_account",
"routing_number": "110000000",
"status": "new"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"account_holder_name": "Jane Austen",
"account_holder_type": "company",
"account_type": null,
"bank_name": "STRIPE TEST BANK",
"country": "US",
"currency": "usd",
"customer": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"balance": 0,
"created": 1234567890,
"currency": "usd",
"default_source": null,
"delinquent": false,
"description": null,
"discount": {
"checkout_session": null,
"coupon": {
"amount_off": null,
"created": 1028554472,
"currency": null,
"duration": "forever",
"duration_in_months": null,
"id": "obj_123",
"livemode": true,
"max_redemptions": null,
"metadata": null,
"name": null,
"object": "coupon",
"percent_off": null,
"redeem_by": null,
"times_redeemed": 990066668,
"valid": true
},
"customer": null,
"end": null,
"id": "obj_123",
"invoice": null,
"invoice_item": null,
"object": "discount",
"promotion_code": null,
"start": 109757538,
"subscription": null,
"subscription_item": null
},
"email": null,
"id": "cus_123",
"invoice_prefix": "7FE1103",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": null,
"footer": null,
"rendering_options": {
"amount_tax_display": null,
"template": null
}
},
"livemode": false,
"metadata": {},
"name": null,
"next_invoice_sequence": 1,
"object": "customer",
"phone": null,
"preferred_locales": [],
"shipping": {},
"tax_exempt": "none",
"test_clock": null
},
"fingerprint": "AuoSJ18zsVWV9SPc",
"id": "ba_123",
"last4": "6789",
"metadata": {},
"object": "bank_account",
"routing_number": "110000000",
"status": "new"
}
26 changes: 26 additions & 0 deletions src/StripeTests/Resources/api_fixtures/customer_card.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": null,
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 8,
"exp_year": 2025,
"fingerprint": "AOB934RVNwzk6xtn",
"funding": "credit",
"id": "card_123",
"last4": "4242",
"metadata": {},
"name": "Jenny Rosen",
"object": "card",
"regulated_status": null,
"tokenization_method": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"balance": 0,
"created": 1234567890,
"currency": "usd",
"default_source": null,
"delinquent": false,
"description": null,
"discount": {
"checkout_session": null,
"coupon": {
"amount_off": null,
"created": 1028554472,
"currency": null,
"duration": "forever",
"duration_in_months": null,
"id": "obj_123",
"livemode": true,
"max_redemptions": null,
"metadata": null,
"name": null,
"object": "coupon",
"percent_off": null,
"redeem_by": null,
"times_redeemed": 990066668,
"valid": true
},
"customer": null,
"end": null,
"id": "obj_123",
"invoice": null,
"invoice_item": null,
"object": "discount",
"promotion_code": null,
"start": 109757538,
"subscription": null,
"subscription_item": null
},
"email": null,
"id": "cus_123",
"invoice_prefix": "7FE1103",
"invoice_settings": {
"custom_fields": null,
"default_payment_method": null,
"footer": null,
"rendering_options": {
"amount_tax_display": null,
"template": null
}
},
"livemode": false,
"metadata": {},
"name": null,
"next_invoice_sequence": 1,
"object": "customer",
"phone": null,
"preferred_locales": [],
"shipping": {},
"tax_exempt": "none",
"test_clock": null
},
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 8,
"exp_year": 2025,
"fingerprint": "AOB934RVNwzk6xtn",
"funding": "credit",
"id": "card_123",
"last4": "4242",
"metadata": {},
"name": "Jenny Rosen",
"object": "card",
"regulated_status": null,
"tokenization_method": null
}
Loading
Loading