Skip to content

Commit d1cba79

Browse files
authored
EES-5846 Fix incorrect public API URLs on preview token page (#5590)
* EES-5846 Fix incorrect public API URLs on preview token page This change also strips out API version from `PUBLIC_API_BASE_URL` in favour of controlling the version from the frontend. This creates less opportunity for error if we eventually publish a new API version as we won't need to make updates in multiple places. * EES-5846 Add tests for public API doc URLs in `DataSetFileApiQuickStart`
1 parent bda58ef commit d1cba79

File tree

6 files changed

+59
-20
lines changed

6 files changed

+59
-20
lines changed

infrastructure/templates/template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@
21352135
"NEXT_CONFIG_MODE": "server",
21362136
"NODE_ENV": "production",
21372137
"PUBLIC_URL": "[concat(variables('publicAppUrl'), '/')]",
2138-
"PUBLIC_API_BASE_URL": "[concat('https://', parameters('publicApiUrl'), '/v1')]",
2138+
"PUBLIC_API_BASE_URL": "[concat('https://', parameters('publicApiUrl'))]",
21392139
"PUBLIC_API_DOCS_URL": "[concat('https://', parameters('publicApiDocsUrl'))]",
21402140
"WEBSITE_NODE_DEFAULT_VERSION": "20.16.0",
21412141
"WEBSITES_PORT": 3000

src/explore-education-statistics-admin/src/pages/release/data/ReleaseApiDataSetPreviewTokenPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function ReleaseApiDataSetPreviewTokenPage() {
6464
history.push(tokenLogPagePath);
6565
};
6666

67-
const tokenExampleUrl = `${publicApiUrl}/api/v1.0/data-sets/${dataSet?.draftVersion?.id}`;
67+
const tokenExampleUrl = `${publicApiUrl}/v1/data-sets/${dataSet?.draftVersion?.id}`;
6868

6969
return (
7070
<>
@@ -177,7 +177,7 @@ response <- GET(url, add_headers("Preview-Token" = "${previewToken.id}"))
177177

178178
{dataSet?.draftVersion && (
179179
<ApiDataSetQuickStart
180-
publicApiBaseUrl={`${publicApiUrl}/api/v1.0`}
180+
publicApiBaseUrl={publicApiUrl}
181181
publicApiDocsUrl={publicApiDocsUrl}
182182
dataSetId={dataSet.id}
183183
dataSetName={dataSet.title}

src/explore-education-statistics-common/src/modules/data-catalogue/components/ApiDataSetQuickStart.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface Props {
1212
headingsTag?: 'h3' | 'h4';
1313
publicApiBaseUrl: string;
1414
publicApiDocsUrl: string;
15+
publicApiVersion?: 'v1';
1516
renderLink: ({
1617
children,
1718
toString,
@@ -28,8 +29,12 @@ export default function ApiDataSetQuickStart({
2829
headingsTag: Heading = 'h3',
2930
publicApiBaseUrl,
3031
publicApiDocsUrl,
32+
publicApiVersion = 'v1',
3133
renderLink,
3234
}: Props) {
35+
const publicApiVersionUrl = `${publicApiBaseUrl}/${publicApiVersion}`;
36+
const publicApiDocsVersionUrl = `${publicApiDocsUrl}/reference-${publicApiVersion}`;
37+
3338
return (
3439
<>
3540
<InsetText>
@@ -69,11 +74,11 @@ export default function ApiDataSetQuickStart({
6974
</>
7075
}
7176
labelHidden={false}
72-
url={`${publicApiBaseUrl}/data-sets/${dataSetId}`}
77+
url={`${publicApiVersionUrl}/data-sets/${dataSetId}`}
7378
/>
7479
<p>
7580
{renderLink({
76-
to: `${publicApiDocsUrl}/reference-v1/endpoints/GetDataSet/`,
81+
to: `${publicApiDocsVersionUrl}/endpoints/GetDataSet/`,
7782
children: 'Guidance: Get data set summary',
7883
})}
7984
</p>
@@ -89,11 +94,11 @@ export default function ApiDataSetQuickStart({
8994
</>
9095
}
9196
labelHidden={false}
92-
url={`${publicApiBaseUrl}/data-sets/${dataSetId}/meta?dataSetVersion=${dataSetVersion}`}
97+
url={`${publicApiVersionUrl}/data-sets/${dataSetId}/meta?dataSetVersion=${dataSetVersion}`}
9398
/>
9499
<p>
95100
{renderLink({
96-
to: `${publicApiDocsUrl}/reference-v1/endpoints/GetDataSetMeta/`,
101+
to: `${publicApiDocsVersionUrl}/endpoints/GetDataSetMeta/`,
97102
children: 'Guidance: Get data set metadata',
98103
})}
99104
</p>
@@ -109,11 +114,11 @@ export default function ApiDataSetQuickStart({
109114
</>
110115
}
111116
labelHidden={false}
112-
url={`${publicApiBaseUrl}/data-sets/${dataSetId}/query?dataSetVersion=${dataSetVersion}`}
117+
url={`${publicApiVersionUrl}/data-sets/${dataSetId}/query?dataSetVersion=${dataSetVersion}`}
113118
/>
114119
<p>
115120
{renderLink({
116-
to: `${publicApiDocsUrl}/reference-v1/endpoints/QueryDataSetGet/`,
121+
to: `${publicApiDocsVersionUrl}/endpoints/QueryDataSetGet/`,
117122
children: 'Guidance: Query data set (GET)',
118123
})}
119124
</p>
@@ -129,11 +134,11 @@ export default function ApiDataSetQuickStart({
129134
</>
130135
}
131136
labelHidden={false}
132-
url={`${publicApiBaseUrl}/data-sets/${dataSetId}/query?dataSetVersion=${dataSetVersion}`}
137+
url={`${publicApiVersionUrl}/data-sets/${dataSetId}/query?dataSetVersion=${dataSetVersion}`}
133138
/>
134139
<p>
135140
{renderLink({
136-
to: `${publicApiDocsUrl}/reference-v1/endpoints/QueryDataSetPost/`,
141+
to: `${publicApiDocsVersionUrl}/endpoints/QueryDataSetPost/`,
137142
children: 'Guidance: Query data set (POST)',
138143
})}
139144
</p>
@@ -149,11 +154,11 @@ export default function ApiDataSetQuickStart({
149154
</>
150155
}
151156
labelHidden={false}
152-
url={`${publicApiBaseUrl}/data-sets/${dataSetId}/csv?dataSetVersion=${dataSetVersion}`}
157+
url={`${publicApiVersionUrl}/data-sets/${dataSetId}/csv?dataSetVersion=${dataSetVersion}`}
153158
/>
154159
<p>
155160
{renderLink({
156-
to: `${publicApiDocsUrl}/reference-v1/endpoints/DownloadDataSetCsv/`,
161+
to: `${publicApiDocsVersionUrl}/endpoints/DownloadDataSetCsv/`,
157162
children: 'Guidance: Download data set as CSV',
158163
})}
159164
</p>

src/explore-education-statistics-common/src/services/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const dataApi = new Client({
1717
});
1818

1919
export const publicApi = new Client({
20-
baseURL: process.env.PUBLIC_API_BASE_URL,
20+
baseURL: `${process.env.PUBLIC_API_BASE_URL}/v1`,
2121
requestInterceptors: [networkActivityRequestInterceptor],
2222
responseInterceptors: [networkActivityResponseInterceptor],
2323
});

src/explore-education-statistics-frontend/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CONTENT_API_BASE_URL=http://localhost:5010/api
22
DATA_API_BASE_URL=http://localhost:5000/api
3-
PUBLIC_API_BASE_URL=http://localhost:5050/v1
3+
PUBLIC_API_BASE_URL=http://localhost:5050
44
PUBLIC_API_DOCS_URL=https://dev.statistics.api.education.gov.uk/docs
55
NOTIFICATION_API_BASE_URL=http://localhost:7073/api
66
GA_TRACKING_ID=

src/explore-education-statistics-frontend/src/modules/data-catalogue/components/__tests__/DataSetFileApiQuickStart.test.tsx

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,54 @@ describe('DataSetFileApiQuickStart', () => {
4343

4444
expect(
4545
screen.getByLabelText('GET data set summary URL'),
46-
).toHaveDisplayValue(/data-sets\/api-data-set-id/);
46+
).toHaveDisplayValue('http://localhost:5050/v1/data-sets/api-data-set-id');
47+
expect(
48+
screen.getByRole('link', { name: 'Guidance: Get data set summary' }),
49+
).toHaveAttribute(
50+
'href',
51+
'https://dev.statistics.api.education.gov.uk/docs/reference-v1/endpoints/GetDataSet/',
52+
);
53+
4754
expect(
4855
screen.getByLabelText('GET data set metadata URL'),
4956
).toHaveDisplayValue(
50-
/data-sets\/api-data-set-id\/meta\?dataSetVersion=1.0/,
57+
'http://localhost:5050/v1/data-sets/api-data-set-id/meta?dataSetVersion=1.0',
5158
);
59+
expect(
60+
screen.getByRole('link', { name: 'Guidance: Get data set metadata' }),
61+
).toHaveAttribute(
62+
'href',
63+
'https://dev.statistics.api.education.gov.uk/docs/reference-v1/endpoints/GetDataSetMeta/',
64+
);
65+
5266
expect(screen.getByLabelText('GET data set query URL')).toHaveDisplayValue(
53-
/data-sets\/api-data-set-id\/query\?dataSetVersion=1.0/,
67+
'http://localhost:5050/v1/data-sets/api-data-set-id/query?dataSetVersion=1.0',
68+
);
69+
expect(
70+
screen.getByRole('link', { name: 'Guidance: Query data set (GET)' }),
71+
).toHaveAttribute(
72+
'href',
73+
'https://dev.statistics.api.education.gov.uk/docs/reference-v1/endpoints/QueryDataSetGet/',
5474
);
75+
5576
expect(screen.getByLabelText('POST data set query URL')).toHaveDisplayValue(
56-
/data-sets\/api-data-set-id\/query\?dataSetVersion=1.0/,
77+
'http://localhost:5050/v1/data-sets/api-data-set-id/query?dataSetVersion=1.0',
78+
);
79+
expect(
80+
screen.getByRole('link', { name: 'Guidance: Query data set (POST)' }),
81+
).toHaveAttribute(
82+
'href',
83+
'https://dev.statistics.api.education.gov.uk/docs/reference-v1/endpoints/QueryDataSetPost/',
5784
);
85+
5886
expect(screen.getByLabelText('GET data set CSV URL')).toHaveDisplayValue(
59-
/data-sets\/api-data-set-id\/csv\?dataSetVersion=1.0/,
87+
'http://localhost:5050/v1/data-sets/api-data-set-id/csv?dataSetVersion=1.0',
88+
);
89+
expect(
90+
screen.getByRole('link', { name: 'Guidance: Download data set as CSV' }),
91+
).toHaveAttribute(
92+
'href',
93+
'https://dev.statistics.api.education.gov.uk/docs/reference-v1/endpoints/DownloadDataSetCsv/',
6094
);
6195
});
6296
});

0 commit comments

Comments
 (0)