Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from superfaceai/fix/create-command-bugs
Browse files Browse the repository at this point in the history
fix: create command bugs
  • Loading branch information
TheEdward162 authored Nov 30, 2020
2 parents 6aa6736 + 0d0abc3 commit cdf7551
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
34 changes: 16 additions & 18 deletions src/commands/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ describe('Create CLI command', () => {
stderr.stop();
stdout.stop();

const path = `${__dirname}/${documentName}`;

if (fs.existsSync(`${path}.supr`)) {
fs.unlinkSync(`${path}.supr`);
if (fs.existsSync(`${documentName}.supr`)) {
fs.unlinkSync(`${documentName}.supr`);
}
if (fs.existsSync(`${path}.suma`)) {
fs.unlinkSync(`${path}.suma`);
if (fs.existsSync(`${documentName}.suma`)) {
fs.unlinkSync(`${documentName}.suma`);
}
});

Expand All @@ -33,7 +31,7 @@ describe('Create CLI command', () => {
`-> Created SendSMS.supr (id = "https://example.com/profile/SendSMS")\n`
);

await Lint.run([`${__dirname}/${documentName}.supr`]);
await Lint.run([`${documentName}.supr`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -44,7 +42,7 @@ describe('Create CLI command', () => {
`-> Created SMSService.supr (id = "https://example.com/profile/SMSService")\n`
);

await Lint.run([`${__dirname}/${documentName}.supr`]);
await Lint.run([`${documentName}.supr`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -62,7 +60,7 @@ describe('Create CLI command', () => {
`-> Created SMSService.supr (id = "https://example.com/profile/SMSService")\n`
);

await Lint.run([`${__dirname}/${documentName}.supr`]);
await Lint.run([`${documentName}.supr`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -73,7 +71,7 @@ describe('Create CLI command', () => {
`-> Created SendSMS.suma (provider = Twillio, id = "https://example.com/Twillio/SendSMS")\n`
);

await Lint.run([`${__dirname}/${documentName}.suma`]);
await Lint.run([`${documentName}.suma`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -92,7 +90,7 @@ describe('Create CLI command', () => {
`-> Created SMSService.suma (provider = Twillio, id = "https://example.com/Twillio/SMSService")\n`
);

await Lint.run([`${__dirname}/${documentName}.suma`]);
await Lint.run([`${documentName}.suma`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -112,7 +110,7 @@ describe('Create CLI command', () => {
`-> Created SMSService.suma (provider = Twillio, id = "https://example.com/Twillio/SMSService")\n`
);

await Lint.run([`${__dirname}/${documentName}.suma`]);
await Lint.run([`${documentName}.suma`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -123,10 +121,10 @@ describe('Create CLI command', () => {
`-> Created SendSMS.supr (id = "https://example.com/profile/SendSMS")\n-> Created SendSMS.suma (provider = Twillio, id = "https://example.com/Twillio/SendSMS")\n`
);

await Lint.run([`${__dirname}/${documentName}.supr`]);
await Lint.run([`${documentName}.supr`]);
expect(stdout.output).toContain('Detected 0 problems\n');

await Lint.run([`${__dirname}/${documentName}.suma`]);
await Lint.run([`${documentName}.suma`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -137,10 +135,10 @@ describe('Create CLI command', () => {
`-> Created SMSService.supr (id = "https://example.com/profile/SMSService")\n-> Created SMSService.suma (provider = Twillio, id = "https://example.com/Twillio/SMSService")\n`
);

await Lint.run([`${__dirname}/${documentName}.supr`]);
await Lint.run([`${documentName}.supr`]);
expect(stdout.output).toContain('Detected 0 problems\n');

await Lint.run([`${__dirname}/${documentName}.suma`]);
await Lint.run([`${documentName}.suma`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});

Expand All @@ -158,10 +156,10 @@ describe('Create CLI command', () => {
`-> Created SMSService.supr (id = "https://example.com/profile/SMSService")\n-> Created SMSService.suma (provider = Twillio, id = "https://example.com/Twillio/SMSService")\n`
);

await Lint.run([`${__dirname}/${documentName}.supr`]);
await Lint.run([`${documentName}.supr`]);
expect(stdout.output).toContain('Detected 0 problems\n');

await Lint.run([`${__dirname}/${documentName}.suma`]);
await Lint.run([`${documentName}.suma`]);
expect(stdout.output).toContain('Detected 0 problems\n');
});
});
9 changes: 6 additions & 3 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export default class Create extends Command {
const { documentName } = args;
let usecases: string[];

if (typeof documentName !== 'string') {
if (
typeof documentName !== 'string' ||
!/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(documentName)
) {
throw new CLIError('Invalid document name!', {
exit: -1,
});
Expand Down Expand Up @@ -72,7 +75,7 @@ export default class Create extends Command {
useCaseNames: string[]
): Promise<void> {
const fileName = `${documentName}${PROFILE_EXTENSIONS[0]}`;
const outputStream = new OutputStream(`${__dirname}/${fileName}`);
const outputStream = new OutputStream(fileName);

await outputStream.write(
`profile = "https://example.com/profile/${documentName}"\n\n${this.getUsecases(
Expand Down Expand Up @@ -100,7 +103,7 @@ export default class Create extends Command {
}

const fileName = `${documentName}${MAP_EXTENSIONS[0]}`;
const outputStream = new OutputStream(`${__dirname}/${fileName}`);
const outputStream = new OutputStream(fileName);

await outputStream.write(
`profile = "https://example.com/profile/${documentName}"\nprovider = "https://example.com/${providerName}/${documentName}"\n\n${this.getUsecases(
Expand Down

0 comments on commit cdf7551

Please sign in to comment.