From d799d89f7e23acc1c3c063de4ec873a81fe20f65 Mon Sep 17 00:00:00 2001 From: shun91 Date: Tue, 2 Apr 2024 21:40:22 +0900 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E7=B8=AEURL=E3=81=AE=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parseTextAndUrl.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/parseTextAndUrl.test.ts b/src/parseTextAndUrl.test.ts index 8b287fd..4218d10 100644 --- a/src/parseTextAndUrl.test.ts +++ b/src/parseTextAndUrl.test.ts @@ -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); +});