[Fleet] Fix bug caused by API changes (#120886) (#120919)

* fix endpoint integration

* added test

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2021-12-09 11:20:58 -05:00 committed by GitHub
parent b3a3c626c9
commit d9aed2a8de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -172,7 +172,8 @@ export const registerRoutes = (routers: { rbac: FleetRouter; superuser: FleetRou
response
);
if (resp.payload?.item) {
return response.ok({ body: { response: resp.payload.item } });
// returning item as well here, because pkgVersion is optional in new GET endpoint, and if not specified, the router selects the deprecated route
return response.ok({ body: { item: resp.payload.item, response: resp.payload.item } });
}
return resp;
}

View file

@ -102,5 +102,15 @@ export default function (providerContext: FtrProviderContext) {
.auth(testUsers.fleet_read_only.username, testUsers.fleet_read_only.password)
.expect(200);
});
it('returns package info in item field when calling without version', async function () {
// this will install through the registry by default
await installPackage(testPkgName, testPkgVersion);
const res = await supertest.get(`/api/fleet/epm/packages/${testPkgName}`).expect(200);
const packageInfo = res.body.item;
// the uploaded version will have this description
expect(packageInfo.name).to.equal('apache');
await uninstallPackage(testPkgName, testPkgVersion);
});
});
}