Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/argBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { LambdaBody } from "./Types/lambda";
import { ParseBody } from "./Types/utils";

export const parse = (body: LambdaBody): ParseBody => {
const args = body.text?.split(" ");
if (args === undefined) {
if (body.text === undefined) {
throw new Error(
"引数が正しく渡されていません。もう一度helpを見てください。"
Copy link
Copy Markdown
Collaborator

@mii288 mii288 May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今回のPRとはちょっと関係ないですが、ここに到達するケースはどういうケースでしょう・・?

image

);
}

if (body.text?.match(/.*\u3000.*/g) !== null) {
throw new Error("全角スペースが含まれています。引数から削除してください。");
}

const args = body.text?.split(" ");

// 引数がないもしくは'--'が入ってるときはhelp
const isHelp = args[0] === "" || args[0].includes("--");
// locationIdは数値5桁(prefecturesId2桁 + placeId3桁)のみ指定されている場合
Expand Down
26 changes: 26 additions & 0 deletions test/argBody.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as argBody from "../src/argBody";
import { LambdaBody } from "../src/Types/lambda";

test("bodyがundefinedの場合は例外を吐く", async () => {
const body: LambdaBody = {
text: undefined,
};

const expectError = new Error(
"引数が正しく渡されていません。もう一度helpを見てください。"
);

expect(() => argBody.parse(body)).toThrowError(expectError);
});

test("bodyに全角スペースが含まれる場合は例外を吐く", async () => {
const body: LambdaBody = {
text: " 01101",
};

const expectError = new Error(
"全角スペースが含まれています。引数から削除してください。"
);

expect(() => argBody.parse(body)).toThrowError(expectError);
});