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

argBodyにundefinedを含む場合はinvalidにする。テストコードの追加 #85

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions src/argBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ 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を見てください。"
);
}

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

Choose a reason for hiding this comment

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

nullは考慮しなくてもOKですか?

Copy link
Owner Author

Choose a reason for hiding this comment

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

https://github.com/ShuzoN/zut/blob/master/src/Types/lambda.ts#L2

stringってnull許容でしたっけ?(覚えてない)

Copy link
Collaborator

Choose a reason for hiding this comment

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

このtypesが正しければ大丈夫です!
emptyの場合はundefinedではなくnullをセットするライブラリが多いので、lambdaはどうなのかなと思ったところでした。

Copy link
Owner Author

Choose a reason for hiding this comment

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

あーたしかに。types/aws-lambdaみときます


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