Skip to content

Commit 39e5cb6

Browse files
authored
Fix context Id not returned by lookupSpaceByAPI (#2618)
1 parent 5b5928f commit 39e5cb6

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

packages/gitbook/e2e/pages.spec.ts

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import {
1010
SiteCustomizationSettings,
1111
} from '@gitbook/api';
1212
import { test, expect, Page } from '@playwright/test';
13+
import deepMerge from 'deepmerge';
1314
import jwt from 'jsonwebtoken';
1415
import rison from 'rison';
1516
import { DeepPartial } from 'ts-essentials';
16-
import deepMerge from 'deepmerge';
1717

1818
import { getContentTestURL } from '../tests/utils';
1919

@@ -930,6 +930,94 @@ const testCases: TestsCase[] = [
930930
},
931931
],
932932
},
933+
{
934+
name: 'Adaptive Content - VA',
935+
baseUrl: `https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-va/`,
936+
tests: [
937+
{
938+
name: 'isAlphaUser',
939+
url: (() => {
940+
const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9';
941+
const token = jwt.sign(
942+
{
943+
name: 'gitbook-open-tests',
944+
isAlphaUser: true,
945+
},
946+
privateKey,
947+
{
948+
expiresIn: '24h',
949+
},
950+
);
951+
return `?jwt_token=${token}`;
952+
})(),
953+
run: async (page) => {
954+
const alphaUserPage = page
955+
.locator('a[class*="group\\/toclink"]')
956+
.filter({ hasText: 'Alpha users' });
957+
const betaUserPage = page
958+
.locator('a[class*="group\\/toclink"]')
959+
.filter({ hasText: 'Beta users' });
960+
await expect(alphaUserPage).toBeVisible();
961+
await expect(betaUserPage).toHaveCount(0);
962+
},
963+
},
964+
{
965+
name: 'isBetaUser',
966+
url: (() => {
967+
const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9';
968+
const token = jwt.sign(
969+
{
970+
name: 'gitbook-open-tests',
971+
isBetaUser: true,
972+
},
973+
privateKey,
974+
{
975+
expiresIn: '24h',
976+
},
977+
);
978+
return `?jwt_token=${token}`;
979+
})(),
980+
run: async (page) => {
981+
const alphaUserPage = page
982+
.locator('a[class*="group\\/toclink"]')
983+
.filter({ hasText: 'Alpha users' });
984+
const betaUserPage = page
985+
.locator('a[class*="group\\/toclink"]')
986+
.filter({ hasText: 'Beta users' });
987+
await expect(betaUserPage).toBeVisible();
988+
await expect(alphaUserPage).toHaveCount(0);
989+
},
990+
},
991+
{
992+
name: 'isAlphaUser & isBetaUser',
993+
url: (() => {
994+
const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9';
995+
const token = jwt.sign(
996+
{
997+
name: 'gitbook-open-tests',
998+
isAlphaUser: true,
999+
isBetaUser: true,
1000+
},
1001+
privateKey,
1002+
{
1003+
expiresIn: '24h',
1004+
},
1005+
);
1006+
return `?jwt_token=${token}`;
1007+
})(),
1008+
run: async (page) => {
1009+
const alphaUserPage = page
1010+
.locator('a[class*="group\\/toclink"]')
1011+
.filter({ hasText: 'Alpha users' });
1012+
const betaUserPage = page
1013+
.locator('a[class*="group\\/toclink"]')
1014+
.filter({ hasText: 'Beta users' });
1015+
await expect(alphaUserPage).toBeVisible();
1016+
await expect(betaUserPage).toBeVisible();
1017+
},
1018+
},
1019+
],
1020+
},
9331021
];
9341022

9351023
for (const testCase of testCases) {

packages/gitbook/src/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ async function lookupSpaceByAPI(
722722
siteSpace: data.siteSpace,
723723
organization: data.organization,
724724
shareKey: data.shareKey,
725+
...(data.contextId ? { contextId: data.contextId } : {}),
725726
}
726727
: {}),
727728
} as PublishedContentWithCache;

0 commit comments

Comments
 (0)