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

[Cases] Decode responses from the user actions service #157971

Merged
merged 17 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ const CaseUserActionDeprecatedResponseRt = rt.intersection([
/**
* This includes the comment_id but not the action_id or case_id
*/
const UserActionAttributes = rt.intersection([CaseUserActionBasicRt, CaseUserActionInjectedIdsRt]);
export const UserActionAttributesRt = rt.intersection([
CaseUserActionBasicRt,
CaseUserActionInjectedIdsRt,
]);

const UserActionRt = rt.intersection([
UserActionAttributes,
UserActionAttributesRt,
rt.type({
id: rt.string,
version: rt.string,
Expand All @@ -93,7 +96,7 @@ export type CaseUserActionsDeprecatedResponse = rt.TypeOf<
typeof CaseUserActionsDeprecatedResponseRt
>;
export type CaseUserActionDeprecatedResponse = rt.TypeOf<typeof CaseUserActionDeprecatedResponseRt>;
export type UserActionAttributes = rt.TypeOf<typeof UserActionAttributes>;
export type UserActionAttributes = rt.TypeOf<typeof UserActionAttributesRt>;

/**
* This defines the high level category for the user action. Whether the user add, removed, updated something
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/cases/server/common/types/user_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type { SavedObject } from '@kbn/core/server';
import type { UserActionAttributes } from '../../../common/api';
import { UserActionAttributesRt } from '../../../common/api';
import type { User } from './user';

interface UserActionCommonPersistedAttributes {
Expand All @@ -21,5 +22,7 @@ export interface UserActionPersistedAttributes extends UserActionCommonPersisted
payload: Record<string, unknown>;
}

export const UserActionTransformedAttributesRt = UserActionAttributesRt;

export type UserActionTransformedAttributes = UserActionAttributes;
export type UserActionSavedObjectTransformed = SavedObject<UserActionTransformedAttributes>;
20 changes: 10 additions & 10 deletions x-pack/plugins/cases/server/services/cases/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ describe('CasesService', () => {
});
});

describe('Encoding responses', () => {
describe('Decoding responses', () => {
const caseTransformedAttributesProps = CaseTransformedAttributesRt.types.reduce(
(acc, type) => ({ ...acc, ...type.props }),
{}
Expand All @@ -1883,7 +1883,7 @@ describe('CasesService', () => {
);

describe('getCase', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
unsecuredSavedObjectsClient.get.mockResolvedValue(createCaseSavedObjectResponse());

await expect(service.getCase({ id: 'a' })).resolves.not.toThrow();
Expand Down Expand Up @@ -1913,7 +1913,7 @@ describe('CasesService', () => {
});

describe('getResolveCase', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
unsecuredSavedObjectsClient.resolve.mockResolvedValue({
saved_object: createCaseSavedObjectResponse(),
outcome: 'exactMatch',
Expand Down Expand Up @@ -1952,7 +1952,7 @@ describe('CasesService', () => {
});

describe('getCases', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
unsecuredSavedObjectsClient.bulkGet.mockResolvedValue({
saved_objects: [
createCaseSavedObjectResponse({ caseId: '1' }),
Expand All @@ -1963,7 +1963,7 @@ describe('CasesService', () => {
await expect(service.getCases({ caseIds: ['a', 'b'] })).resolves.not.toThrow();
});

it('do not encodes errors', async () => {
it('do not decodes errors', async () => {
const errorSO = {
...omit(createCaseSavedObjectResponse({ caseId: '2' }), 'attributes'),
error: {
Expand Down Expand Up @@ -2078,7 +2078,7 @@ describe('CasesService', () => {
});

describe('findCases', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
const findMockReturn = createSOFindResponse([
createFindSO({ caseId: '1' }),
createFindSO({ caseId: '2' }),
Expand Down Expand Up @@ -2123,7 +2123,7 @@ describe('CasesService', () => {
});

describe('post', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
unsecuredSavedObjectsClient.create.mockResolvedValue(createCaseSavedObjectResponse());

await expect(
Expand Down Expand Up @@ -2166,7 +2166,7 @@ describe('CasesService', () => {
});

describe('patchCase', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
unsecuredSavedObjectsClient.update.mockResolvedValue(createUpdateSOResponse());

await expect(
Expand Down Expand Up @@ -2199,7 +2199,7 @@ describe('CasesService', () => {
});

describe('patchCases', () => {
it('encodes correctly', async () => {
it('decodes correctly', async () => {
unsecuredSavedObjectsClient.bulkUpdate.mockResolvedValue({
saved_objects: [
createCaseSavedObjectResponse({ caseId: '1' }),
Expand All @@ -2222,7 +2222,7 @@ describe('CasesService', () => {
).resolves.not.toThrow();
});

it('do not encodes errors', async () => {
it('do not decodes errors', async () => {
const errorSO = {
...omit(createCaseSavedObjectResponse({ caseId: '2' }), 'attributes'),
error: {
Expand Down
Loading