Skip to content

Commit

Permalink
Intercept test calls that hardcode API base (#1855)
Browse files Browse the repository at this point in the history
* Intercept test calls that hardcode API base

* lint
  • Loading branch information
pakrym-stripe authored Jul 24, 2023
1 parent f6d9d5d commit 5355f76
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions test/resources/generated_examples_test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,11 @@ describe('Quotes', function() {
const lineItems = await stripe.quotes.listLineItems('qt_xxxxxxxxxxxxx');
expect(lineItems).not.to.be.null;
});

it('pdf method', async function() {
const file = await stripe.quotes.pdf('qt_xxxxxxxxxxxxx');
expect(file).not.to.be.null;
});
});

describe('Radar.EarlyFraudWarnings', function() {
Expand Down
29 changes: 26 additions & 3 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
StripeObject as StripeClient,
} from '../src/Types.js';
import stripe = require('../src/stripe.cjs.node.js');
import {NodeHttpClient} from '../src/net/NodeHttpClient.js';
import {HttpClientResponseInterface} from '../src/net/HttpClient.js';

const testingHttpAgent = new http.Agent({keepAlive: false});

Expand Down Expand Up @@ -58,11 +60,32 @@ export const getTestServerStripe = (

export const getStripeMockClient = (): StripeClient => {
const stripe = require('../src/stripe.cjs.node.js');
class StripeMockForwardingClient extends NodeHttpClient {
makeRequest(
_host: string,
_port: string,
path: string,
method: string,
headers: RequestHeaders,
requestData: RequestData,
_protocol: string,
timeout: number
): Promise<HttpClientResponseInterface> {
return super.makeRequest(
process.env.STRIPE_MOCK_HOST || 'localhost',
(process.env.STRIPE_MOCK_PORT || 12111).toString(),
path,
method,
headers,
requestData,
'http',
timeout
);
}
}

return stripe(FAKE_API_KEY, {
host: process.env.STRIPE_MOCK_HOST || 'localhost',
port: process.env.STRIPE_MOCK_PORT || 12111,
protocol: 'http',
httpClient: new StripeMockForwardingClient(),
});
};

Expand Down

0 comments on commit 5355f76

Please sign in to comment.