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

dx-6943: allow user defined sample name #445

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
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
30 changes: 24 additions & 6 deletions src/stripeSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class StripeSamples {
return;
}

const clonePath = await this.promptPath(selectedSample);
const cloneSampleAsName = await this.promptSampleName(sampleName);

const clonePath = await this.promptPath(selectedSample, cloneSampleAsName);
if (!clonePath) {
return;
}
Expand All @@ -93,9 +95,13 @@ export class StripeSamples {

progress.report({increment: 100});

const sampleIsReady = `Your sample "${cloneSampleAsName}" is all ready to go`;
// eslint-disable-next-line no-nested-ternary
const postInstallMessage = !!sampleCreateResponse
? sampleCreateResponse.getPostInstall()
: 'Your sample is all ready to go, but we could not set the API keys in the .env file. Please set them manually.';
? !!sampleCreateResponse.getPostInstall()
? sampleCreateResponse.getPostInstall()
: `${sampleIsReady}.`
: `${sampleIsReady}, but we could not set the API keys in the .env file. Please set them manually.`;

await this.promptOpenFolder(postInstallMessage, clonePath);
},
Expand Down Expand Up @@ -230,7 +236,7 @@ export class StripeSamples {
/**
* Ask for where to clone the sample
*/
private promptPath = async (sample: SampleQuickPickItem): Promise<string | undefined> => {
private promptPath = async (sample: SampleQuickPickItem, cloneSampleAsName: string): Promise<string | undefined> => {
const cloneDirectoryUri = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
Expand All @@ -243,11 +249,23 @@ export class StripeSamples {
return;
}

const clonePath = path.resolve(cloneDirectoryUri[0].fsPath, sample.sampleData.name);
const clonePath = path.resolve(cloneDirectoryUri[0].fsPath, cloneSampleAsName);

return clonePath;
};

/**
* Ask for sample name
*/
private promptSampleName = async (sampleName: string): Promise<string> => {
const inputName = await window.showInputBox({
value: sampleName,
prompt: 'Enter a sample name',
});

return !!inputName ? inputName : sampleName;
};

/**
* Execute the sample creation with the given config at the given path
*/
Expand Down Expand Up @@ -293,7 +311,7 @@ export class StripeSamples {
};

const selectedOption = await window.showInformationMessage(
postInstallMessage || 'Your sample is all ready to go.',
postInstallMessage,
{modal: true},
...Object.values(openFolderOptions),
);
Expand Down
7 changes: 6 additions & 1 deletion test/suite/stripeSamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ suite('StripeSamples', function () {
test('prompts for sample config, clones, and opens sample', async () => {
sandbox.stub(stripeDaemon, 'setupClient').resolves(daemonClient);
const showQuickPickSpy = sandbox.spy(vscode.window, 'showQuickPick');
const showInputBoxStub = sandbox
.stub(vscode.window, 'showInputBox')
.resolves('sample-name-by-user');
const showOpenDialogStub = sandbox
.stub(vscode.window, 'showOpenDialog')
.resolves([vscode.Uri.parse('/my/path')]);
Expand All @@ -95,6 +98,7 @@ suite('StripeSamples', function () {
await simulateSelectAll();

assert.strictEqual(showQuickPickSpy.callCount, 4);
assert.strictEqual(showInputBoxStub.callCount, 1);
assert.strictEqual(showOpenDialogStub.callCount, 1);
assert.strictEqual(showInformationMessageStub.callCount, 1);
});
Expand All @@ -118,6 +122,7 @@ suite('StripeSamples', function () {
);

sandbox.stub(stripeDaemon, 'setupClient').resolves(daemonClient);
sandbox.stub(vscode.window, 'showInputBox').resolves('sample-name-by-user');
sandbox.stub(vscode.window, 'showOpenDialog').resolves([vscode.Uri.parse('/my/path')]);
const showInformationMessageStub = sandbox
.stub(vscode.window, 'showInformationMessage')
Expand All @@ -130,7 +135,7 @@ suite('StripeSamples', function () {

assert.deepStrictEqual(
showInformationMessageStub.args[0][0],
'Your sample is all ready to go, but we could not set the API keys in the .env file. Please set them manually.',
'Your sample "sample-name-by-user" is all ready to go, but we could not set the API keys in the .env file. Please set them manually.',
);
});
});
Expand Down