Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
erikb-stripe committed Dec 10, 2024
1 parent 4c4d564 commit 5110246
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/stripeTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class StripeTerminal {

const projectName = stripeConfig.get<string | null>('projectName', null);

if (projectName !== null) {
if (projectName !== null && projectName !== '') {
// Regex to validate project name
const projectNameRegex = /^[a-zA-Z0-9_-\s]+$/;

Expand Down
102 changes: 51 additions & 51 deletions test/suite/stripeTerminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ suite('stripeTerminal', function () {

['/usr/local/bin/stripe', '/custom/path/to/stripe'].forEach((path) => {
suite(`when the Stripe CLI is installed at ${path}`, () => {
test('runs command with valid project name', async () => {
test(`runs command with ${path}`, async () => {
const executeTaskSpy = sandbox.spy(vscode.tasks, 'executeTask');
sandbox.stub(terminalStub, 'sendText');
sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);

// Mock the configuration with a valid project name
const stripeClientStub = <any>{
getCLIPath: () => { },
isAuthenticated: () => true,
};
sandbox
.stub(vscode.window, 'createTerminal')
.returns(terminalStub);
const stripeClientStub = <any>{getCLIPath: () => {}, isAuthenticated: () => true};
sandbox
.stub(stripeClientStub, 'getCLIPath')
.returns(Promise.resolve(path));

// Mock the getConfiguration function to return a valid project name
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
Expand All @@ -59,8 +59,6 @@ suite('stripeTerminal', function () {
}
});

sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));

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

Expand All @@ -76,7 +74,7 @@ suite('stripeTerminal', function () {
'--forward-to',
'localhost',
'--project-name',
'Valid_Project-Name'
'Valid_Project-Name',
],
{
shellQuoting: {
Expand All @@ -89,57 +87,59 @@ suite('stripeTerminal', function () {
),
]);
});
});

test('throws error for invalid project name', async () => {
// Mock the configuration with an invalid project name
const stripeClientStub = <any>{
getCLIPath: () => { },
isAuthenticated: () => true,
};

// Mock the getConfiguration function to return an invalid project name
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
get: (key: string) => {
if (key === 'projectName') {
return 'Invalid Project Name!'; // Invalid project name
}
return null;
},
has: function (section: string): boolean {
throw new Error('Function not implemented.');
},
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 {
throw new Error('Function not implemented.');
},
update: function (section: string, value: any, configurationTarget?: vscode.ConfigurationTarget | boolean | null, overrideInLanguage?: boolean): Thenable<void> {
throw new Error('Function not implemented.');
test('throws error for invalid project name', async () => {
// Mock the configuration with an invalid project name
const stripeClientStub = <any>{
getCLIPath: () => { },
isAuthenticated: () => true,
};

// Mock the getConfiguration function to return an invalid project name
sandbox.stub(vscode.workspace, 'getConfiguration').returns({
get: (key: string) => {
if (key === 'projectName') {
return 'Invalid Project Name!'; // Invalid project name
}
});
return null;
},
has: function (section: string): boolean {
throw new Error('Function not implemented.');
},
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 {

Check warning on line 110 in test/suite/stripeTerminal.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Unexpected separator (;)

Check warning on line 110 in test/suite/stripeTerminal.test.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Unexpected separator (;)

Check warning on line 110 in test/suite/stripeTerminal.test.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Unexpected separator (;)

Check warning on line 110 in test/suite/stripeTerminal.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Unexpected separator (;)

Check warning on line 110 in test/suite/stripeTerminal.test.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Unexpected separator (;)

Check warning on line 110 in test/suite/stripeTerminal.test.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Unexpected separator (;)
throw new Error('Function not implemented.');
},
update: function (section: string, value: any, configurationTarget?: vscode.ConfigurationTarget | boolean | null, overrideInLanguage?: boolean): Thenable<void> {
throw new Error('Function not implemented.');
}
});

sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));
sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
sandbox.stub(stripeClientStub, 'getCLIPath').returns(Promise.resolve(path));

const stripeTerminal = new StripeTerminal(stripeClientStub);
const stripeTerminal = new StripeTerminal(stripeClientStub);

// Expect an error to be thrown due to invalid project name
await assert.rejects(
async () => {
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
},
{
name: 'Error',
message: "Invalid project name: 'Invalid Project Name!'. Project names can only contain letters, numbers, spaces, underscores, and hyphens.",
}
);
});
// Expect an error to be thrown due to invalid project name
await assert.rejects(
async () => {
await stripeTerminal.execute('listen', ['--forward-to', 'localhost']);
},
{
name: 'Error',
message: "Invalid project name: 'Invalid Project Name!'. Project names can only contain letters, numbers, spaces, underscores, and hyphens.",
}
);
});
});

suite('with no Stripe CLI installed', () => {
test('does not run command', async () => {
const sendTextStub = sandbox.stub(terminalStub, 'sendText');
const createTerminalStub = sandbox.stub(vscode.window, 'createTerminal').returns(terminalStub);
const stripeClientStub = <any>{getCLIPath: () => { }, isAuthenticated: () => true};
const createTerminalStub = sandbox
.stub(vscode.window, 'createTerminal')
.returns(terminalStub);
const stripeClientStub = <any>{getCLIPath: () => {}, isAuthenticated: () => true};
sandbox.stub(stripeClientStub, 'getCLIPath').returns(null);

const stripeTerminal = new StripeTerminal(stripeClientStub);
Expand Down

0 comments on commit 5110246

Please sign in to comment.