From 43bf40c8123d239f997633b03abbd2cca8d08646 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Tue, 12 Mar 2024 08:39:54 +0100 Subject: [PATCH] fix: techdocs cookie mocking date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Signed-off-by: Camila Belo --- .changeset/healthy-mirrors-obey.md | 2 +- packages/techdocs-cli-embedded-app/src/apis.ts | 5 +++-- plugins/techdocs-addons-test-utils/src/test-utils.tsx | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.changeset/healthy-mirrors-obey.md b/.changeset/healthy-mirrors-obey.md index 23e655e160..f0a52f83e6 100644 --- a/.changeset/healthy-mirrors-obey.md +++ b/.changeset/healthy-mirrors-obey.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-techdocs-react': patch +'@backstage/plugin-techdocs-react': minor --- Create a new api method for issuing user cookie. diff --git a/packages/techdocs-cli-embedded-app/src/apis.ts b/packages/techdocs-cli-embedded-app/src/apis.ts index 805a748c11..d48bee569d 100644 --- a/packages/techdocs-cli-embedded-app/src/apis.ts +++ b/packages/techdocs-cli-embedded-app/src/apis.ts @@ -127,8 +127,9 @@ class TechDocsDevApi implements TechDocsApi { this.identityApi = identityApi; } - async issueUserCookie(): Promise<{ expiresAt: string }> { - return { expiresAt: new Date().toISOString() }; + async getCookie(): Promise<{ expiresAt: string }> { + const tenMinutesFromNow = new Date(Date.now() + 10 * 60 * 1000); + return { expiresAt: tenMinutesFromNow.toISOString() }; } async getApiOrigin() { diff --git a/plugins/techdocs-addons-test-utils/src/test-utils.tsx b/plugins/techdocs-addons-test-utils/src/test-utils.tsx index 5502b0950f..f26dfea6fd 100644 --- a/plugins/techdocs-addons-test-utils/src/test-utils.tsx +++ b/plugins/techdocs-addons-test-utils/src/test-utils.tsx @@ -48,9 +48,10 @@ const { renderToStaticMarkup } = const techdocsApi = { getTechDocsMetadata: jest.fn(), getEntityMetadata: jest.fn(), - issueUserCookie: jest - .fn() - .mockReturnValue({ expiresAt: new Date().toISOString() }), + getCookie: jest.fn().mockReturnValue({ + // Expires in 10 minutes + expiresAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(), + }), }; const techdocsStorageApi = {