From 39e5cb63ef294c704d2db43fbd90835b050e17ff Mon Sep 17 00:00:00 2001 From: spastorelli Date: Wed, 11 Dec 2024 10:54:17 +0100 Subject: [PATCH] Fix context Id not returned by lookupSpaceByAPI (#2618) --- packages/gitbook/e2e/pages.spec.ts | 90 +++++++++++++++++++++++++++++- packages/gitbook/src/middleware.ts | 1 + 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/packages/gitbook/e2e/pages.spec.ts b/packages/gitbook/e2e/pages.spec.ts index 845be06aa..4ff7d786a 100644 --- a/packages/gitbook/e2e/pages.spec.ts +++ b/packages/gitbook/e2e/pages.spec.ts @@ -10,10 +10,10 @@ import { SiteCustomizationSettings, } from '@gitbook/api'; import { test, expect, Page } from '@playwright/test'; +import deepMerge from 'deepmerge'; import jwt from 'jsonwebtoken'; import rison from 'rison'; import { DeepPartial } from 'ts-essentials'; -import deepMerge from 'deepmerge'; import { getContentTestURL } from '../tests/utils'; @@ -930,6 +930,94 @@ const testCases: TestsCase[] = [ }, ], }, + { + name: 'Adaptive Content - VA', + baseUrl: `https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-va/`, + tests: [ + { + name: 'isAlphaUser', + url: (() => { + const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9'; + const token = jwt.sign( + { + name: 'gitbook-open-tests', + isAlphaUser: true, + }, + privateKey, + { + expiresIn: '24h', + }, + ); + return `?jwt_token=${token}`; + })(), + run: async (page) => { + const alphaUserPage = page + .locator('a[class*="group\\/toclink"]') + .filter({ hasText: 'Alpha users' }); + const betaUserPage = page + .locator('a[class*="group\\/toclink"]') + .filter({ hasText: 'Beta users' }); + await expect(alphaUserPage).toBeVisible(); + await expect(betaUserPage).toHaveCount(0); + }, + }, + { + name: 'isBetaUser', + url: (() => { + const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9'; + const token = jwt.sign( + { + name: 'gitbook-open-tests', + isBetaUser: true, + }, + privateKey, + { + expiresIn: '24h', + }, + ); + return `?jwt_token=${token}`; + })(), + run: async (page) => { + const alphaUserPage = page + .locator('a[class*="group\\/toclink"]') + .filter({ hasText: 'Alpha users' }); + const betaUserPage = page + .locator('a[class*="group\\/toclink"]') + .filter({ hasText: 'Beta users' }); + await expect(betaUserPage).toBeVisible(); + await expect(alphaUserPage).toHaveCount(0); + }, + }, + { + name: 'isAlphaUser & isBetaUser', + url: (() => { + const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9'; + const token = jwt.sign( + { + name: 'gitbook-open-tests', + isAlphaUser: true, + isBetaUser: true, + }, + privateKey, + { + expiresIn: '24h', + }, + ); + return `?jwt_token=${token}`; + })(), + run: async (page) => { + const alphaUserPage = page + .locator('a[class*="group\\/toclink"]') + .filter({ hasText: 'Alpha users' }); + const betaUserPage = page + .locator('a[class*="group\\/toclink"]') + .filter({ hasText: 'Beta users' }); + await expect(alphaUserPage).toBeVisible(); + await expect(betaUserPage).toBeVisible(); + }, + }, + ], + }, ]; for (const testCase of testCases) { diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts index 8a937d67f..8c00e71ea 100644 --- a/packages/gitbook/src/middleware.ts +++ b/packages/gitbook/src/middleware.ts @@ -722,6 +722,7 @@ async function lookupSpaceByAPI( siteSpace: data.siteSpace, organization: data.organization, shareKey: data.shareKey, + ...(data.contextId ? { contextId: data.contextId } : {}), } : {}), } as PublishedContentWithCache;