Skip to content

Commit

Permalink
[Cases] Update io-ts types as strict (#156813)
Browse files Browse the repository at this point in the history
## Summary

This PR fixes #156156

It uses` io-ts strict` type to remove unnecessary attributes.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Jonathan Buttner <jonathan.buttner@elastic.co>
Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
  • Loading branch information
4 people authored May 24, 2023
1 parent 5fa2226 commit bc3e312
Show file tree
Hide file tree
Showing 123 changed files with 5,614 additions and 817 deletions.
46 changes: 46 additions & 0 deletions x-pack/plugins/cases/common/api/cases/alerts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { AlertResponseRt } from './alerts';

describe('Alerts', () => {
describe('AlertResponseRt', () => {
it('has expected attributes in request', () => {
const defaultRequest = [{ id: '1', index: '2', attached_at: '3' }];

const query = AlertResponseRt.decode(defaultRequest);

expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});

it('multiple attributes in request', () => {
const defaultRequest = [
{ id: '1', index: '2', attached_at: '3' },
{ id: '2', index: '3', attached_at: '4' },
];
const query = AlertResponseRt.decode(defaultRequest);

expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});

it('removes foo:bar attributes from request', () => {
const defaultRequest = [{ id: '1', index: '2', attached_at: '3' }];
const query = AlertResponseRt.decode([{ ...defaultRequest[0], foo: 'bar' }]);

expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/api/cases/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as rt from 'io-ts';

const AlertRt = rt.type({
const AlertRt = rt.strict({
id: rt.string,
index: rt.string,
attached_at: rt.string,
Expand Down
41 changes: 41 additions & 0 deletions x-pack/plugins/cases/common/api/cases/assignee.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CaseAssigneesRt } from './assignee';

describe('Assignee', () => {
describe('CaseAssigneesRt', () => {
const defaultRequest = [{ uid: '1' }, { uid: '2' }];

it('has expected attributes in request', () => {
const query = CaseAssigneesRt.decode(defaultRequest);

expect(query).toStrictEqual({
_tag: 'Right',
right: defaultRequest,
});
});

it('removes foo:bar attributes from request', () => {
const query = CaseAssigneesRt.decode([{ ...defaultRequest[0], foo: 'bar' }]);

expect(query).toStrictEqual({
_tag: 'Right',
right: [defaultRequest[0]],
});
});

it('removes foo:bar attributes from assignees', () => {
const query = CaseAssigneesRt.decode([{ uid: '1', foo: 'bar' }, { uid: '2' }]);

expect(query).toStrictEqual({
_tag: 'Right',
right: [{ uid: '1' }, { uid: '2' }],
});
});
});
});
Loading

0 comments on commit bc3e312

Please sign in to comment.