Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[gen1][core] ENG-7515 add query.id when hitting content API for symbols #3752

Merged
merged 28 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3a4bf4e
fix[gen1][core] ENG-7515 add query.id when hitting content API for sy…
Nov 20, 2024
fc86801
fix[gen1][core] ENG-7515 test added
Nov 20, 2024
7f0a194
fix[gen1][core] ENG-7515 commented code removed
Nov 20, 2024
ba53c57
fix[gen1][react] ENG-7515 add query.id at the Symbol level
Nov 21, 2024
e6478ab
fix[gen1][core] ENG-7515 change to tests
Nov 21, 2024
691495f
Merge branch 'main' into ENG-7515
Nov 21, 2024
1593bac
Merge branch 'main' into ENG-7515
Dec 3, 2024
de48611
feat[gen1][react] ENG-7515 add query.id only if entry is set
Dec 3, 2024
271854a
Merge branch 'main' into ENG-7515
Dec 9, 2024
80b5578
feat[react][symbol] ENG-7515 check for apiEndpoint when passing query.id
Dec 9, 2024
b416c83
feat[changeset] ENG-7515 changeset added
Dec 9, 2024
ee12509
Merge branch 'main' into ENG-7515
Dec 10, 2024
bdc61d0
feat[api][react] ENG-7515 change to code
Dec 10, 2024
d4be4db
feat[api][react] ENG-7515 change to tests
Dec 10, 2024
142907e
fix[changeset] ENG-7515 changeset added
Dec 10, 2024
f6d49c5
fix[sdkTests][snippet] ENG-7515 change to test
Dec 10, 2024
9d78d4e
fix[sdkTests][snippet] ENG-7515 change to test
Dec 10, 2024
2adb132
fix[sdkTests][snippet] ENG-7515 change to test
Dec 10, 2024
252fc23
fix[sdkTests][snippet] ENG-7515 change to test
Dec 11, 2024
37c8e13
fix[sdkTests][snippet] ENG-7515 change to test
Dec 11, 2024
30c6be7
fix[gitHub][workflows] ENG-7515 change to ci.yml to test builder.clas…
Dec 11, 2024
8bdf820
fix[gitHub][workflows] ENG-7515 change to ci.yml to test builder.clas…
Dec 11, 2024
0c7e635
fix[gen1][core] ENG-7515 change to test
Dec 11, 2024
a14f723
fix[gen1][core] ENG-7515 change to test
Dec 11, 2024
45934a6
fix[gen1][core] ENG-7515 change to test
Dec 11, 2024
0616543
fix[gen1][core] ENG-7515 change to test
Dec 11, 2024
98eb0c5
fix[gen1][core] ENG-7515 change to tests
Dec 12, 2024
f91a490
fix[gen1][core] ENG-7515 change to tests
Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/new-snails-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@builder.io/react': patch
'@builder.io/sdk': patch
---

Renders Symbol correctly when apiEndpoint is 'content'
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ jobs:
cache-node-modules: true
cache-install-state: true

- name: Test Core
run: yarn g:nx test @builder.io/sdk

- name: Build Core
run: yarn g:nx build @builder.io/sdk

Expand Down
28 changes: 28 additions & 0 deletions packages/core/src/builder.class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,32 @@ describe('flushGetContentQueue', () => {
{ headers: { Authorization: `Bearer ${AUTH_TOKEN}` } }
);
});

test('hits content url with query.id when id is passed in options.query', async () => {
const expectedModel = 'symbol';
const expectedFormat = 'email';
const expectedEntryId = '123';

builder.apiEndpoint = 'content';
const result = await builder['flushGetContentQueue'](true, [
{
model: expectedModel,
format: expectedFormat,
key: expectedModel,
omit: OMIT,
fields: 'data',
limit: 10,
entry: expectedEntryId,
query: {
id: expectedEntryId,
},
},
]);

expect(builder['makeFetchApiCall']).toBeCalledTimes(1);
expect(builder['makeFetchApiCall']).toBeCalledWith(
`https://cdn.builder.io/api/v3/content/${expectedModel}?omit=data.blocks&apiKey=${API_KEY}&fields=data&format=${expectedFormat}&userAttributes=%7B%22urlPath%22%3A%22%2F%22%2C%22host%22%3A%22localhost%22%2C%22device%22%3A%22desktop%22%7D&limit=10&model=%22${expectedModel}%22&entry=%22${expectedEntryId}%22&enrich=true&query.id=${expectedEntryId}`,
{ headers: { Authorization: `Bearer ${AUTH_TOKEN}` } }
);
});
});
6 changes: 4 additions & 2 deletions packages/react-tests/nextjs/pages/[[...index]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default function Page(props: PageProps & { apiVersion: any }) {
builder.apiVersion = props?.apiVersion;
}

if (props?.apiEndpoint) {
builder.apiEndpoint = props.apiEndpoint;
}

// only enable tracking if we're not in the `/can-track-false` and `symbol-tracking` test route
useEffect(() => {
if (!router.asPath.includes('can-track-false') && !router.asPath.includes('symbol-tracking')) {
Expand All @@ -57,8 +61,6 @@ export default function Page(props: PageProps & { apiVersion: any }) {
.promise()
.then();
} else if (router.asPath.includes('get-content')) {
builder.apiEndpoint = props.apiEndpoint;
delete props.apiEndpoint;
builder
.get('', {
...props,
Expand Down
9 changes: 5 additions & 4 deletions packages/react-tests/react-remix/app/routes/($slug).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ export default function Page() {
builder.apiVersion = props?.apiVersion;
}

if (props?.apiEndpoint) {
builder.apiEndpoint = props.apiEndpoint;
delete props.apiEndpoint;
}

useEffect(() => {
if (
window.location.pathname.includes('get-query') ||
window.location.pathname.includes('get-content')
) {
if (props.apiEndpoint) {
builder.apiEndpoint = props.apiEndpoint;
delete props.apiEndpoint;
}
builder
.get('', {
...props,
Expand Down
7 changes: 5 additions & 2 deletions packages/react-tests/react-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ function App() {
window.location.pathname.includes('get-query') ||
window.location.pathname.includes('get-content')
) {
if (resp.apiEndpoint) {
if (resp?.apiEndpoint) {
builder.apiEndpoint = resp.apiEndpoint;
delete resp.apiEndpoint;
}
builder
.get('', {
Expand All @@ -38,6 +37,10 @@ function App() {
builder.apiVersion = props?.apiVersion;
}

if (props?.apiEndpoint) {
builder.apiEndpoint = props.apiEndpoint;
}

if (props?.trustedHosts) {
Builder.trustedHosts = props.trustedHosts;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/blocks/Symbol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ class SymbolComponent extends React.Component<PropsWithChildren<SymbolProps>> {
key: builderComponentKey,
noEditorUpdates: true,
}),
...(Builder.singletonInstance.apiEndpoint === 'content' &&
entry && {
query: {
id: entry,
},
}),
}}
codegen={!!content?.data?.blocksJs}
hydrate={state.state?._hydrate}
Expand Down
38 changes: 38 additions & 0 deletions packages/sdks-tests/src/e2e-tests/hit-content-api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from '@playwright/test';
import { excludeGen1, test, mapSdkName, getSdkGeneration } from '../helpers/index.js';
import { FIRST_SYMBOL_CONTENT, SECOND_SYMBOL_CONTENT } from '../specs/symbols.js';

test.describe('Get Content', () => {
test('call content API only once - in page', async ({ page, sdk }) => {
Expand Down Expand Up @@ -40,4 +41,41 @@ test.describe('Get Content', () => {
expect(await req!.postDataJSON()).toEqual({ test: 'test' });
expect(req!.method()).toBe('POST');
});
test('fetch symbol with query.id', async ({ page, sdk }) => {
test.skip(!excludeGen1(sdk));

let x = 0;
let headers;

const urlMatch = /https:\/\/cdn\.builder\.io\/api\/v3\/content\/symbol/;

const urls: string[] = [];

await page.route(urlMatch, route => {
x++;
headers = route.request().headers();

const url = new URL(route.request().url());
urls.push(url.href);
return route.fulfill({
status: 200,
json: {
results: [x === 0 ? FIRST_SYMBOL_CONTENT : SECOND_SYMBOL_CONTENT],
},
});
});

await page.goto('/get-content-with-symbol', { waitUntil: 'networkidle' });

await expect(x).toBeGreaterThanOrEqual(2);

urls.forEach(url => {
expect(url).toContain('query.id=29ab534d62c4406c8500e1cbfa609537');
});

// Check for new SDK headers
expect(headers?.['x-builder-sdk']).toBe(mapSdkName(sdk));
expect(headers?.['x-builder-sdk-gen']).toBe(getSdkGeneration(sdk));
expect(headers?.['x-builder-sdk-version']).toMatch(/\d+\.\d+\.\d+/); // Check for semver format
});
});
2 changes: 2 additions & 0 deletions packages/sdks-tests/src/specs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export const PAGES: Record<string, Page> = {
'/symbol-with-jscode': { content: COUNTDOWN },
'/get-content': { content: HTTP_REQUESTS, target: 'gen1' },
'/get-query': { content: HTTP_REQUESTS, target: 'gen1' },
'/get-content-with-symbol': { content: CONTENT_WITHOUT_SYMBOLS, target: 'gen1' },
} as const;

export type Path = keyof typeof PAGES;
Expand Down Expand Up @@ -299,6 +300,7 @@ export const getProps = async (args: {
};
break;
case '/get-content':
case '/get-content-with-symbol':
extraProps = {
apiEndpoint: 'content',
};
Expand Down
Loading