Skip to content

Commit 6587fd0

Browse files
committed
format
1 parent 21984fd commit 6587fd0

File tree

1 file changed

+178
-130
lines changed

1 file changed

+178
-130
lines changed

test/suite/stripeTerminal.test.ts

Lines changed: 178 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -4,141 +4,189 @@ import * as vscode from 'vscode';
44
import {StripeTerminal} from '../../src/stripeTerminal';
55

66
suite('stripeTerminal', function () {
7-
this.timeout(20000);
8-
9-
let sandbox: sinon.SinonSandbox;
10-
11-
const terminalStub = <vscode.Terminal><unknown>{
12-
name: 'Stubbed Terminal',
13-
processId: Promise.resolve(undefined),
14-
creationOptions: {},
15-
exitStatus: undefined,
16-
sendText: (text: string, addNewLine?: boolean) => { },
17-
show: (preserveFocus?: boolean) => { },
18-
hide: () => { },
19-
dispose: () => { },
20-
};
21-
22-
setup(() => {
23-
sandbox = sinon.createSandbox();
24-
});
25-
26-
teardown(() => {
27-
sandbox.restore();
28-
});
29-
30-
['/usr/local/bin/stripe', '/custom/path/to/stripe'].forEach((path) => {
31-
suite(`when the Stripe CLI is installed at ${path}`, () => {
32-
test('runs command with valid project name', async () => {
33-
const executeTaskSpy = sandbox.spy(vscode.tasks, 'executeTask');
34-
sandbox.stub(terminalStub, 'sendText');
35-
sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
36-
37-
// Mock the configuration with a valid project name
38-
const stripeClientStub = <any>{
39-
getCLIPath: () => { },
40-
isAuthenticated: () => true,
41-
};
42-
43-
// Mock the getConfiguration function to return an invalid project name
44-
// Mock the getConfiguration function to return a configuration object with a specific project name
45-
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
46-
get: (key: string) => {
47-
if (key === 'projectName') {
48-
return 'Valid_Project-Name'; // or 'Invalid Project Name!' for the invalid test
49-
}
50-
return null; // Return null for any other keys
51-
},
52-
});
7+
this.timeout(20000);
8+
9+
let sandbox: sinon.SinonSandbox;
10+
11+
const terminalStub = <vscode.Terminal>(<unknown>{
12+
name: 'Stubbed Terminal',
13+
processId: Promise.resolve(undefined),
14+
creationOptions: {},
15+
exitStatus: undefined,
16+
sendText: (text: string, addNewLine?: boolean) => {},
17+
show: (preserveFocus?: boolean) => {},
18+
hide: () => {},
19+
dispose: () => {},
20+
});
21+
22+
setup(() => {
23+
sandbox = sinon.createSandbox();
24+
});
25+
26+
teardown(() => {
27+
sandbox.restore();
28+
});
29+
30+
['/usr/local/bin/stripe', '/custom/path/to/stripe'].forEach((path) => {
31+
suite(`when the Stripe CLI is installed at ${path}`, () => {
32+
test('runs command with valid project name', async () => {
33+
const executeTaskSpy = sandbox.spy(vscode.tasks, 'executeTask');
34+
sandbox.stub(terminalStub, 'sendText');
35+
sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
36+
37+
// Mock the configuration with a valid project name
38+
const stripeClientStub = <any>{
39+
getCLIPath: () => {},
40+
isAuthenticated: () => true,
41+
};
42+
43+
// Mock the getConfiguration function to return an invalid project name
44+
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
45+
get: (key: string) => {
46+
if (key === 'projectName') {
47+
return 'Valid_Project-Name'; // Invalid project name
48+
}
49+
return null;
50+
},
51+
has: function (section: string): boolean {
52+
throw new Error('Function not implemented.');
53+
},
54+
inspect: function <T>(
55+
section: string,
56+
):
57+
| {
58+
key: string;
59+
defaultValue?: T;
60+
globalValue?: T;
61+
workspaceValue?: T;
62+
workspaceFolderValue?: T;
63+
defaultLanguageValue?: T;
64+
globalLanguageValue?: T;
65+
workspaceLanguageValue?: T;
66+
workspaceFolderLanguageValue?: T;
67+
languageIds?: string[];
68+
}
69+
| undefined {
70+
throw new Error('Function not implemented.');
71+
},
72+
update: function (
73+
section: string,
74+
value: any,
75+
configurationTarget?: vscode.ConfigurationTarget | boolean | null,
76+
overrideInLanguage?: boolean,
77+
): Thenable<void> {
78+
throw new Error('Function not implemented.');
79+
},
80+
});
5381

54-
sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));
55-
56-
const stripeTerminal = new StripeTerminal(stripeClientStub);
57-
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
58-
59-
assert.strictEqual(executeTaskSpy.callCount, 1);
60-
assert.deepStrictEqual(executeTaskSpy.args[0], [
61-
new vscode.Task(
62-
{type: 'stripe', command: 'listen'},
63-
vscode.TaskScope.Workspace,
64-
'listen',
65-
'stripe',
66-
new vscode.ShellExecution(path, [
67-
'listen',
68-
'--forward-to',
69-
'localhost',
70-
'--project-name',
71-
'Valid_Project-Name'
72-
],
73-
{
74-
shellQuoting: {
75-
escape: {
76-
escapeChar: '\\',
77-
charsToEscape: '&`|"\'',
78-
},
79-
},
80-
}),
81-
),
82-
]);
83-
});
84-
85-
test('throws error for invalid project name', async () => {
86-
// Mock the configuration with an invalid project name
87-
const stripeClientStub = <any>{
88-
getCLIPath: () => { },
89-
isAuthenticated: () => true,
90-
};
91-
92-
// Mock the getConfiguration function to return an invalid project name
93-
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
94-
get: (key: string) => {
95-
if (key === 'projectName') {
96-
return 'Invalid Project Name!'; // Invalid project name
97-
}
98-
return null;
99-
},
100-
has: function (section: string): boolean {
101-
throw new Error('Function not implemented.');
82+
sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));
83+
84+
const stripeTerminal = new StripeTerminal(stripeClientStub);
85+
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
86+
87+
assert.strictEqual(executeTaskSpy.callCount, 1);
88+
assert.deepStrictEqual(executeTaskSpy.args[0], [
89+
new vscode.Task(
90+
{type: 'stripe', command: 'listen'},
91+
vscode.TaskScope.Workspace,
92+
'listen',
93+
'stripe',
94+
new vscode.ShellExecution(
95+
path,
96+
['listen', '--forward-to', 'localhost', '--project-name', 'Valid_Project-Name'],
97+
{
98+
shellQuoting: {
99+
escape: {
100+
escapeChar: '\\',
101+
charsToEscape: '&`|"\'',
102102
},
103-
inspect: function <T>(section: string): { key: string; defaultValue?: T; globalValue?: T; workspaceValue?: T; workspaceFolderValue?: T; defaultLanguageValue?: T; globalLanguageValue?: T; workspaceLanguageValue?: T; workspaceFolderLanguageValue?: T; languageIds?: string[] } | undefined {
104-
throw new Error('Function not implemented.');
105-
},
106-
update: function (section: string, value: any, configurationTarget?: vscode.ConfigurationTarget | boolean | null, overrideInLanguage?: boolean): Thenable<void> {
107-
throw new Error('Function not implemented.');
108-
}
109-
});
110-
111-
sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
112-
sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));
113-
114-
const stripeTerminal = new StripeTerminal(stripeClientStub);
115-
116-
// Expect an error to be thrown due to invalid project name
117-
await assert.rejects(
118-
async () => {
119-
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
120-
},
121-
{
122-
name: 'Error',
123-
message: "Invalid project name: 'Invalid Project Name!'. Project names can only contain letters, numbers, spaces, underscores, and hyphens.",
124-
}
125-
);
126-
});
103+
},
104+
},
105+
),
106+
),
107+
]);
108+
});
109+
110+
test('throws error for invalid project name', async () => {
111+
// Mock the configuration with an invalid project name
112+
const stripeClientStub = <any>{
113+
getCLIPath: () => {},
114+
isAuthenticated: () => true,
115+
};
116+
117+
// Mock the getConfiguration function to return an invalid project name
118+
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
119+
get: (key: string) => {
120+
if (key === 'projectName') {
121+
return 'Invalid Project Name!'; // Invalid project name
122+
}
123+
return null;
124+
},
125+
has: function (section: string): boolean {
126+
throw new Error('Function not implemented.');
127+
},
128+
inspect: function <T>(
129+
section: string,
130+
):
131+
| {
132+
key: string;
133+
defaultValue?: T;
134+
globalValue?: T;
135+
workspaceValue?: T;
136+
workspaceFolderValue?: T;
137+
defaultLanguageValue?: T;
138+
globalLanguageValue?: T;
139+
workspaceLanguageValue?: T;
140+
workspaceFolderLanguageValue?: T;
141+
languageIds?: string[];
142+
}
143+
| undefined {
144+
throw new Error('Function not implemented.');
145+
},
146+
update: function (
147+
section: string,
148+
value: any,
149+
configurationTarget?: vscode.ConfigurationTarget | boolean | null,
150+
overrideInLanguage?: boolean,
151+
): Thenable<void> {
152+
throw new Error('Function not implemented.');
153+
},
127154
});
128-
});
129155

130-
suite('with no Stripe CLI installed', () => {
131-
test('does not run command', async () => {
132-
const sendTextStub = sandbox.stub(terminalStub, 'sendText');
133-
const createTerminalStub = sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
134-
const stripeClientStub = <any>{getCLIPath: () => { }, isAuthenticated: () => true};
135-
sandbox.stub(stripeClientStub, 'getCLIPath').returns(null);
156+
sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
157+
sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));
136158

137-
const stripeTerminal = new StripeTerminal(stripeClientStub);
138-
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
159+
const stripeTerminal = new StripeTerminal(stripeClientStub);
139160

140-
assert.strictEqual(createTerminalStub.callCount, 0);
141-
assert.deepStrictEqual(sendTextStub.callCount, 0);
142-
});
161+
// Expect an error to be thrown due to invalid project name
162+
await assert.rejects(
163+
async () => {
164+
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
165+
},
166+
{
167+
name: 'Error',
168+
message:
169+
"Invalid project name: 'Invalid Project Name!'. Project names can only contain letters, numbers, spaces, underscores, and hyphens.",
170+
},
171+
);
172+
});
173+
});
174+
});
175+
176+
suite('with no Stripe CLI installed', () => {
177+
test('does not run command', async () => {
178+
const sendTextStub = sandbox.stub(terminalStub, 'sendText');
179+
const createTerminalStub = sandbox
180+
.stub(vscode.window, 'createTerminal')
181+
.returns(terminalStub);
182+
const stripeClientStub = <any>{getCLIPath: () => {}, isAuthenticated: () => true};
183+
sandbox.stub(stripeClientStub, 'getCLIPath').returns(null);
184+
185+
const stripeTerminal = new StripeTerminal(stripeClientStub);
186+
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
187+
188+
assert.strictEqual(createTerminalStub.callCount, 0);
189+
assert.deepStrictEqual(sendTextStub.callCount, 0);
143190
});
191+
});
144192
});

0 commit comments

Comments
 (0)