Skip to content

Commit

Permalink
Change undefined values to nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 30, 2020
1 parent 42fbd47 commit 102826e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const ExternalIncidentServiceSecretConfigurationSchema = schema.object(
);

export const UserSchema = schema.object({
fullName: schema.oneOf([schema.nullable(schema.string()), schema.maybe(schema.string())]),
username: schema.oneOf([schema.nullable(schema.string()), schema.maybe(schema.string())]),
fullName: schema.nullable(schema.string()),
username: schema.nullable(schema.string()),
});

const EntityInformation = {
Expand All @@ -57,7 +57,6 @@ export const EntityInformationSchema = schema.object(EntityInformation);
export const CommentSchema = schema.object({
commentId: schema.string(),
comment: schema.string(),
version: schema.maybe(schema.string()),
...EntityInformation,
});

Expand All @@ -70,8 +69,8 @@ export const ExecutorSubActionSchema = schema.oneOf([
export const ExecutorSubActionPushParamsSchema = schema.object({
caseId: schema.string(),
title: schema.string(),
description: schema.maybe(schema.string()),
comments: schema.maybe(schema.arrayOf(CommentSchema)),
description: schema.nullable(schema.string()),
comments: schema.nullable(schema.arrayOf(CommentSchema)),
externalId: schema.nullable(schema.string()),
...EntityInformation,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const fullParams: PushToServiceApiParams = {
comments: [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -87,7 +86,6 @@ const fullParams: PushToServiceApiParams = {
},
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'second comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand Down Expand Up @@ -335,7 +333,6 @@ describe('transformComments', () => {
const comments: Comment[] = [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -347,7 +344,6 @@ describe('transformComments', () => {
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (created at 2020-03-13T08:34:53.450Z by Elastic User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -361,7 +357,6 @@ describe('transformComments', () => {
const comments: Comment[] = [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -376,7 +371,6 @@ describe('transformComments', () => {
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (updated at 2020-03-15T08:34:53.450Z by Another User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -393,7 +387,6 @@ describe('transformComments', () => {
const comments: Comment[] = [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -405,7 +398,6 @@ describe('transformComments', () => {
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -419,7 +411,6 @@ describe('transformComments', () => {
const comments: Comment[] = [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: '', username: 'elastic' },
Expand All @@ -431,7 +422,6 @@ describe('transformComments', () => {
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (added at 2020-03-13T08:34:53.450Z by elastic)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: '', username: 'elastic' },
Expand All @@ -445,7 +435,6 @@ describe('transformComments', () => {
const comments: Comment[] = [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic', username: 'elastic' },
Expand All @@ -457,7 +446,6 @@ describe('transformComments', () => {
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (added at 2020-04-13T08:34:53.450Z by Elastic2)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic', username: 'elastic' },
Expand All @@ -471,7 +459,6 @@ describe('transformComments', () => {
const comments: Comment[] = [
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic', username: 'elastic' },
Expand All @@ -483,7 +470,6 @@ describe('transformComments', () => {
expect(res).toEqual([
{
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
version: 'WzU3LDFd',
comment: 'first comment (added at 2020-04-13T08:34:53.450Z by elastic2)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic', username: 'elastic' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('api', () => {
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-1',
version: 'WzU3LDFd',
comment: 'A comment (added at 2020-04-27T10:59:46.202Z by Elastic User)',
createdAt: '2020-04-27T10:59:46.202Z',
createdBy: {
Expand All @@ -97,7 +96,6 @@ describe('api', () => {
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-2',
version: 'WlK3LDFd',
comment: 'Another comment (added at 2020-04-27T10:59:46.202Z by Elastic User)',
createdAt: '2020-04-27T10:59:46.202Z',
createdBy: {
Expand Down Expand Up @@ -172,7 +170,6 @@ describe('api', () => {
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-1',
version: 'WzU3LDFd',
comment: 'A comment (added at 2020-04-27T10:59:46.202Z by Elastic User)',
createdAt: '2020-04-27T10:59:46.202Z',
createdBy: {
Expand All @@ -192,7 +189,6 @@ describe('api', () => {
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-2',
version: 'WlK3LDFd',
comment: 'Another comment (added at 2020-04-27T10:59:46.202Z by Elastic User)',
createdAt: '2020-04-27T10:59:46.202Z',
createdBy: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const executorParams: ExecutorSubActionPushParams = {
comments: [
{
commentId: 'case-comment-1',
version: 'WzU3LDFd',
comment: 'A comment',
createdAt: '2020-04-27T10:59:46.202Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -108,7 +107,6 @@ const executorParams: ExecutorSubActionPushParams = {
},
{
commentId: 'case-comment-2',
version: 'WlK3LDFd',
comment: 'Another comment',
createdAt: '2020-04-27T10:59:46.202Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('api', () => {
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-1',
version: 'WzU3LDFd',
comment: 'A comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: {
Expand All @@ -99,7 +98,6 @@ describe('api', () => {
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-2',
version: 'WlK3LDFd',
comment: 'Another comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: {
Expand Down Expand Up @@ -175,7 +173,6 @@ describe('api', () => {
incidentId: 'incident-2',
comment: {
commentId: 'case-comment-1',
version: 'WzU3LDFd',
comment: 'A comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: {
Expand All @@ -195,7 +192,6 @@ describe('api', () => {
incidentId: 'incident-2',
comment: {
commentId: 'case-comment-2',
version: 'WlK3LDFd',
comment: 'Another comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const executorParams: ExecutorSubActionPushParams = {
comments: [
{
commentId: 'case-comment-1',
version: 'WzU3LDFd',
comment: 'A comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand All @@ -101,7 +100,6 @@ const executorParams: ExecutorSubActionPushParams = {
},
{
commentId: 'case-comment-2',
version: 'WlK3LDFd',
comment: 'Another comment',
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
Expand Down
26 changes: 11 additions & 15 deletions x-pack/plugins/case/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,17 @@ export const ServiceConnectorCommentParamsRt = rt.type({
updatedBy: rt.union([ServiceConnectorUserParams, rt.null]),
});

export const ServiceConnectorCaseParamsRt = rt.intersection([
rt.type({
caseId: rt.string,
createdAt: rt.string,
createdBy: ServiceConnectorUserParams,
externalId: rt.union([rt.string, rt.null]),
title: rt.string,
updatedAt: rt.union([rt.string, rt.null]),
updatedBy: rt.union([ServiceConnectorUserParams, rt.null]),
}),
rt.partial({
description: rt.string,
comments: rt.array(ServiceConnectorCommentParamsRt),
}),
]);
export const ServiceConnectorCaseParamsRt = rt.type({
caseId: rt.string,
createdAt: rt.string,
createdBy: ServiceConnectorUserParams,
externalId: rt.union([rt.string, rt.null]),
title: rt.string,
updatedAt: rt.union([rt.string, rt.null]),
updatedBy: rt.union([ServiceConnectorUserParams, rt.null]),
description: rt.union([rt.string, rt.null]),
comments: rt.union([rt.array(ServiceConnectorCommentParamsRt), rt.null]),
});

export const ServiceConnectorCaseResponseRt = rt.intersection([
rt.type({
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/siem/public/containers/case/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const casePushParams = {
updatedAt: basicCreatedAt,
updatedBy: elasticUser,
description: 'nice',
comments: null,
};
export const actionTypeExecutorResult = {
actionId: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.commentId]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.commentId]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]',
});
});
});
Expand Down Expand Up @@ -482,7 +482,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.comment]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.comment]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]',
});
});
});
Expand Down Expand Up @@ -510,7 +510,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.createdAt]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.createdAt]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.commentId]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.commentId]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]',
});
});
});
Expand Down Expand Up @@ -453,7 +453,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.comment]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.comment]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]',
});
});
});
Expand Down Expand Up @@ -481,7 +481,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.createdAt]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.createdAt]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]',
});
});
});
Expand Down

0 comments on commit 102826e

Please sign in to comment.