Skip to content

Commit

Permalink
POST /awesome/from-slack-text retruns blank template
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoya committed Nov 6, 2024
1 parent 4de70d1 commit 3b53141
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/api/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ content = """
えっ、yasunori 知らないの?
yasuhara
"""
meta = """
"""
`);
});

test("Should return blank YA toml response", async () => {
const res = await app.request("/awesome/from-slack-text", {
method: "POST",
});
const parsed = await res.text();
const today = new Date().toISOString().split("T").at(0);
const [header, id, ...rest] = parsed.split("\n");
expect(header).toStrictEqual("[[yasunori]]");
expect(id).toMatch("id = "); // いまのテスト環境だとidが変化するため値のテストはできない
expect(rest.join("\n")).toStrictEqual(`title = ""
date = "${today}"
at = "vim-jp #times-yasunori"
senpan = ""
content = """
"""
meta = """
"""
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const route = app
}
const id = latestEntry.id + 1;
const lines = slackText.split("\n");
const [senpan, , title, ...restContents] = lines;
const [senpan, , title = "", ...restContents] = lines;
const date = new Date().toISOString().split("T").at(0);
const content = `${title}\n${restContents.join("\n")}`;
const content = title ? `${title}\n${restContents.join("\n")}` : "";
const tomlString = `[[yasunori]]\nid = ${id}\ntitle = "${title}"\ndate = "${date}"\nat = "vim-jp #times-yasunori"\nsenpan = "${senpan}"\ncontent = """\n${content}\n"""\nmeta = """\n"""\n`;
return c.text(tomlString);
})
Expand Down

0 comments on commit 3b53141

Please sign in to comment.