forked from stripe/stripe-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAuth.spec.js
More file actions
126 lines (101 loc) · 3.28 KB
/
OAuth.spec.js
File metadata and controls
126 lines (101 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
const stripe = require('../testUtils.js').getSpyableStripe();
const expect = require('chai').expect;
const URL = require('url');
const qs = require('node:querystring');
describe('OAuth', () => {
describe('authorize', () => {
describe('when a default client_id is set', () => {
beforeEach(() => {
stripe.setClientId('default_client_id');
});
it('Uses the correct host', () => {
const url = stripe.oauth.authorizeUrl();
const host = URL.parse(url).hostname;
expect(host).to.equal('connect.stripe.com');
});
it('Uses the correct path', () => {
const url = stripe.oauth.authorizeUrl({state: 'some_state'});
const pathname = URL.parse(url).pathname;
expect(pathname).to.equal('/oauth/authorize');
});
it('Uses the correct query', () => {
const url = stripe.oauth.authorizeUrl({state: 'some_state'});
const query = qs.parse(URL.parse(url).query);
expect(query.client_id).to.equal('default_client_id');
expect(query.response_type).to.equal('code');
expect(query.scope).to.equal('read_write');
expect(query.state).to.equal('some_state');
});
it('Uses a provided client_id instead of the default', () => {
const url = stripe.oauth.authorizeUrl({client_id: '123abc'});
const query = qs.parse(URL.parse(url).query);
expect(query.client_id).to.equal('123abc');
});
describe('for Express account', () => {
it('Uses the correct path', () => {
const url = stripe.oauth.authorizeUrl({}, {express: true});
const pathname = URL.parse(url).pathname;
expect(pathname).to.equal('/express/oauth/authorize');
});
});
});
});
describe('token', () => {
it('Sends the correct request', () => {
stripe.oauth.token({
code: '123abc',
grant_type: 'authorization_code',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
host: 'connect.stripe.com',
url: '/oauth/token',
headers: {},
data: {
code: '123abc',
grant_type: 'authorization_code',
},
settings: {},
});
});
});
describe('deauthorize', () => {
beforeEach(() => {
stripe.setClientId('default_client_id');
});
it('Sends the correct request without explicit client_id', () => {
stripe.oauth.deauthorize({
stripe_user_id: 'some_user_id',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
host: 'connect.stripe.com',
url: '/oauth/deauthorize',
headers: {},
data: {
client_id: stripe.getClientId(),
stripe_user_id: 'some_user_id',
},
settings: {},
});
});
it('Sends the correct request with explicit client_id', () => {
stripe.oauth.deauthorize({
stripe_user_id: 'some_user_id',
client_id: '123abc',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
host: 'connect.stripe.com',
url: '/oauth/deauthorize',
headers: {},
data: {
client_id: '123abc',
stripe_user_id: 'some_user_id',
},
settings: {},
});
});
});
});