Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for specifying a custom host on StripeMethod. #1403

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
77 changes: 77 additions & 0 deletions test/StripeResource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,83 @@ describe('StripeResource', () => {
});
});

describe('custom host on method', () => {
const makeResource = (stripe) => {
return new (StripeResource.extend({
path: 'resourceWithHost',

testMethod: stripeMethod({
method: 'GET',
host: 'some.host.stripe.com',
}),
}))(stripe);
};

it('is not impacted by the global host', (done) => {
const stripe = require('../lib/stripe')('sk_test', {
host: 'bad.host.stripe.com',
});

const scope = nock('https://some.host.stripe.com')
.get('/v1/resourceWithHost')
.reply(200, '{}');

makeResource(stripe).testMethod({}, (err, response) => {
done(err);
scope.done();
});
});

it('still lets users override the host on a per-request basis', (done) => {
const stripe = require('../lib/stripe')('sk_test');

const scope = nock('https://some.other.host.stripe.com')
.get('/v1/resourceWithHost')
.reply(200, '{}');

makeResource(stripe).testMethod(
{},
{host: 'some.other.host.stripe.com'},
(err, response) => {
done(err);
scope.done();
}
);
});
});

describe('method with fullPath', () => {
it('interpolates in parameters', (callback) => {
const handleRequest = (req, res) => {
expect(req.url).to.equal('/v1/parent/hello/child/world');

// Write back JSON to close out the server.
res.write('{}');
res.end();
};

testUtils.getTestServerStripe(
{},
handleRequest,
(err, stripe, closeServer) => {
const resource = new (StripeResource.extend({
test: stripeMethod({
method: 'GET',
fullPath: '/v1/parent/{param1}/child/{param2}',
}),
}))(stripe);

return resource.test('hello', 'world', (err, res) => {
closeServer();
// Spot check that we received a response.
expect(res).to.deep.equal({});
return callback(err);
});
}
);
});
});

describe('streaming', () => {
/**
* Defines a fake resource with a `pdf` method
Expand Down