Skip to content

Commit

Permalink
fix create package policy schema
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Sep 17, 2024
1 parent 4ab28e8 commit 0dc0807
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
UpgradePackagePoliciesResponseBodySchema,
DryRunPackagePoliciesResponseBodySchema,
OrphanedPackagePoliciesResponseSchema,
CreatePackagePolicyResponseSchema,
} from '../../types';
import type { PackagePolicy } from '../../types';

Expand Down Expand Up @@ -711,12 +712,13 @@ describe('When calling package policy', () => {
const request = httpServerMock.createKibanaRequest({
body: testPackagePolicy,
});
const expectedResponse = { item: testPackagePolicy };
await createPackagePolicyHandler(context, request, response);
expect(response.ok).toHaveBeenCalledWith({
body: { item: testPackagePolicy },
body: expectedResponse,
});
const validationResp = PackagePolicyResponseSchema.validate(testPackagePolicy);
expect(validationResp).toEqual(testPackagePolicy);
const validationResp = CreatePackagePolicyResponseSchema.validate(expectedResponse);
expect(validationResp).toEqual(expectedResponse);
});
});

Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/fleet/server/routes/package_policy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
UpgradePackagePoliciesResponseBodySchema,
DryRunPackagePoliciesResponseBodySchema,
OrphanedPackagePoliciesResponseSchema,
CreatePackagePolicyResponseSchema,
} from '../../types';
import { calculateRouteAuthz } from '../../services/security/security';

Expand Down Expand Up @@ -170,10 +171,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
request: {},
response: {
200: {
body: () =>
schema.object({
items: schema.arrayOf(PackagePolicyResponseSchema),
}),
body: () => OrphanedPackagePoliciesResponseSchema,
},
400: {
body: genericErrorResponse,
Expand Down Expand Up @@ -201,7 +199,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
request: CreatePackagePolicyRequestSchema,
response: {
200: {
body: () => OrphanedPackagePoliciesResponseSchema,
body: () => CreatePackagePolicyResponseSchema,
},
400: {
body: genericErrorResponse,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/types/rest_spec/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export const CreatePackagePolicyRequestSchema = {
}),
};

export const CreatePackagePolicyResponseSchema = schema.object({
item: PackagePolicyResponseSchema,
});

export const UpdatePackagePolicyRequestSchema = {
...GetOnePackagePolicyRequestSchema,
body: schema.oneOf([
Expand Down

0 comments on commit 0dc0807

Please sign in to comment.