From 51102462d0a20e4a352b214435bfa2d8fda39e2f Mon Sep 17 00:00:00 2001 From: Erik Barbara Date: Tue, 10 Dec 2024 07:57:57 -0500 Subject: [PATCH] format --- src/stripeTerminal.ts | 2 +- test/suite/stripeTerminal.test.ts | 102 +++++++++++++++--------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/stripeTerminal.ts b/src/stripeTerminal.ts index cc8c406d..f9f61f93 100644 --- a/src/stripeTerminal.ts +++ b/src/stripeTerminal.ts @@ -59,7 +59,7 @@ export class StripeTerminal { const projectName = stripeConfig.get('projectName', null); - if (projectName !== null) { + if (projectName !== null && projectName !== '') { // Regex to validate project name const projectNameRegex = /^[a-zA-Z0-9_-\s]+$/; diff --git a/test/suite/stripeTerminal.test.ts b/test/suite/stripeTerminal.test.ts index 272a8fea..76fe9ebe 100644 --- a/test/suite/stripeTerminal.test.ts +++ b/test/suite/stripeTerminal.test.ts @@ -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 = { - getCLIPath: () => { }, - isAuthenticated: () => true, - }; + sandbox + .stub(vscode.window, 'createTerminal') + .returns(terminalStub); + const stripeClientStub = {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({ @@ -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']); @@ -76,7 +74,7 @@ suite('stripeTerminal', function () { '--forward-to', 'localhost', '--project-name', - 'Valid_Project-Name' + 'Valid_Project-Name', ], { shellQuoting: { @@ -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 = { - 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 (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 { - throw new Error('Function not implemented.'); + test('throws error for invalid project name', async () => { + // Mock the configuration with an invalid project name + const stripeClientStub = { + 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 (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 { + 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 = {getCLIPath: () => { }, isAuthenticated: () => true}; + const createTerminalStub = sandbox + .stub(vscode.window, 'createTerminal') + .returns(terminalStub); + const stripeClientStub = {getCLIPath: () => {}, isAuthenticated: () => true}; sandbox.stub(stripeClientStub, 'getCLIPath').returns(null); const stripeTerminal = new StripeTerminal(stripeClientStub);