From 9fd883c6b6f09a33cda113f54bc3ae5b4934199e Mon Sep 17 00:00:00 2001 From: Francois GRUNERT Date: Fri, 8 Nov 2024 14:44:38 +0100 Subject: [PATCH] [backend] add playbook resolver test (#8793) Co-authored-by: Celine Sebe Co-authored-by: marie flores --- .../02-resolvers/playbook-test.ts | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/playbook-test.ts diff --git a/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/playbook-test.ts b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/playbook-test.ts new file mode 100644 index 000000000000..c6f76996cd22 --- /dev/null +++ b/opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/playbook-test.ts @@ -0,0 +1,116 @@ +import { describe, expect, it } from 'vitest'; +import gql from 'graphql-tag'; +import { adminQueryWithSuccess } from '../../utils/testQueryHelper'; + +const LIST_PLAYBOOKS = gql` + query playbooks( + $first: Int + $after: ID + $orderBy: PlaybooksOrdering + $orderMode: OrderingMode + $filters: FilterGroup + $search: String + ) { + playbooks( + first: $first + after: $after + orderBy: $orderBy + orderMode: $orderMode + filters: $filters + search: $search + ) { + edges { + node { + id + name + } + } + } + } +`; + +const CREATE_PLAYBOOK = gql` + mutation playbookAdd($input: PlaybookAddInput!) { + playbookAdd(input: $input){ + id + name + } + } +`; + +const READ_PLAYBOOK = gql` + query playbook($id: String!) { + playbook(id: $id) { + id + name + description + playbook_running + playbook_definition + } + } +`; + +const UPDATE_PLAYBOOK = gql` + mutation playbookFieldPatchEdit($id: ID!, $input: [EditInput!]!) { + playbookFieldPatch(id: $id, input: $input) { + id + name + } + } +`; + +const DELETE_PLAYBOOK = gql` + mutation playbookDelete($id: ID!) { + playbookDelete(id:$id) + } +`; + +describe('Playbook resolver standard behavior', () => { + let playbookId = ''; + const playbookName = 'Playbook1'; + it('should list playbooks', async () => { + const queryResult = await adminQueryWithSuccess({ query: LIST_PLAYBOOKS, variables: { first: 10 } }); + expect(queryResult.data?.playbooks.edges.length).toEqual(0); + }); + it('should add playbook', async () => { + const input = { + input: { + name: playbookName, + } + }; + const queryResult = await adminQueryWithSuccess({ + query: CREATE_PLAYBOOK, + variables: input, + }); + expect(queryResult.data?.playbookAdd.name).toEqual(playbookName); + playbookId = queryResult.data?.playbookAdd.id; + }); + it('should list playbooks', async () => { + const queryResult = await adminQueryWithSuccess({ query: LIST_PLAYBOOKS, variables: { first: 10 } }); + expect(queryResult.data?.playbooks.edges.length).toEqual(1); + }); + it('should read playbook', async () => { + const queryResult = await adminQueryWithSuccess({ query: READ_PLAYBOOK, variables: { id: playbookId } }); + expect(queryResult.data?.playbook.name).toEqual(playbookName); + expect(queryResult.data?.playbook.playbook_running).toEqual(false); + }); + it('should update playbook', async () => { + const queryResult = await adminQueryWithSuccess({ + query: UPDATE_PLAYBOOK, + variables: { + id: playbookId, + input: [ + { key: 'name', value: ['Playbook1 - updated'] }, + ] + } + }); + expect(queryResult.data?.playbookFieldPatch.name).toEqual('Playbook1 - updated'); + }); + it('should remove playbook', async () => { + const queryResult = await adminQueryWithSuccess({ + query: DELETE_PLAYBOOK, + variables: { id: playbookId }, + }); + expect(queryResult.data?.playbookDelete).toEqual(playbookId); + }); +});