Skip to content

Commit

Permalink
短縮URLの場合のテストケースを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
shun91 committed Apr 2, 2024
1 parent 37896ba commit d799d89
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/parseTextAndUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,29 @@ test("テキストがURLのみである場合のパース", async () => {

expect(result).toEqual(expectedOutput);
});

test("短縮URLの場合はリダイレクトレスポンスのLocationヘッダーから元のURLを取得して変換する", async () => {
const testInput = "http://redirect.com";
const originalUrl = "http://finalurl.com";
const expectedOutput = [
{
type: "text",
text: {
content: originalUrl,
link: {
url: originalUrl,
},
},
},
];

server.use(
rest.get(testInput, (req, res, ctx) => {
return res(ctx.status(302), ctx.set("Location", originalUrl));
})
);

const result = await parseTextAndUrl(testInput);

expect(result).toEqual(expectedOutput);
});

0 comments on commit d799d89

Please sign in to comment.