Skip to content

Commit b9145ef

Browse files
committed
check status after installation
1 parent a34e114 commit b9145ef

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

x-pack/plugins/ai_infra/product_doc_base/public/services/installation/installation_service.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,30 @@ describe('InstallationService', () => {
3737
});
3838
});
3939
describe('#install', () => {
40+
beforeEach(() => {
41+
http.post.mockResolvedValue({ installed: true });
42+
});
43+
4044
it('calls the endpoint with the right parameters', async () => {
4145
await service.install();
4246
expect(http.post).toHaveBeenCalledTimes(1);
4347
expect(http.post).toHaveBeenCalledWith(INSTALL_ALL_API_PATH);
4448
});
4549
it('returns the value from the server', async () => {
46-
const expected = { stubbed: true };
50+
const expected = { installed: true };
4751
http.post.mockResolvedValue(expected);
4852

4953
const response = await service.install();
5054
expect(response).toEqual(expected);
5155
});
56+
it('throws when the server returns installed: false', async () => {
57+
const expected = { installed: false };
58+
http.post.mockResolvedValue(expected);
59+
60+
await expect(service.install()).rejects.toThrowErrorMatchingInlineSnapshot(
61+
`"Installation did not complete successfully"`
62+
);
63+
});
5264
});
5365
describe('#uninstall', () => {
5466
it('calls the endpoint with the right parameters', async () => {

x-pack/plugins/ai_infra/product_doc_base/public/services/installation/installation_service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export class InstallationService {
2727
}
2828

2929
async install(): Promise<PerformInstallResponse> {
30-
return await this.http.post<PerformInstallResponse>(INSTALL_ALL_API_PATH);
30+
const response = await this.http.post<PerformInstallResponse>(INSTALL_ALL_API_PATH);
31+
if (!response.installed) {
32+
throw new Error('Installation did not complete successfully');
33+
}
34+
return response;
3135
}
3236

3337
async uninstall(): Promise<UninstallResponse> {

x-pack/plugins/ai_infra/product_doc_base/server/routes/installation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ export const registerInstallationRoutes = ({
7373
wait: true,
7474
});
7575

76+
// check status after installation in case of failure
77+
const { status } = await documentationManager.getStatus();
78+
7679
return res.ok<PerformInstallResponse>({
7780
body: {
78-
installed: true,
81+
installed: status === 'installed',
7982
},
8083
});
8184
}

0 commit comments

Comments
 (0)