|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import gql from 'graphql-tag'; |
| 3 | +import { adminQueryWithSuccess } from '../../utils/testQueryHelper'; |
| 4 | + |
| 5 | +const LIST_PLAYBOOKS = gql` |
| 6 | + query playbooks( |
| 7 | + $first: Int |
| 8 | + $after: ID |
| 9 | + $orderBy: PlaybooksOrdering |
| 10 | + $orderMode: OrderingMode |
| 11 | + $filters: FilterGroup |
| 12 | + $search: String |
| 13 | + ) { |
| 14 | + playbooks( |
| 15 | + first: $first |
| 16 | + after: $after |
| 17 | + orderBy: $orderBy |
| 18 | + orderMode: $orderMode |
| 19 | + filters: $filters |
| 20 | + search: $search |
| 21 | + ) { |
| 22 | + edges { |
| 23 | + node { |
| 24 | + id |
| 25 | + name |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | +`; |
| 31 | + |
| 32 | +const CREATE_PLAYBOOK = gql` |
| 33 | + mutation playbookAdd($input: PlaybookAddInput!) { |
| 34 | + playbookAdd(input: $input){ |
| 35 | + id |
| 36 | + name |
| 37 | + } |
| 38 | + } |
| 39 | +`; |
| 40 | + |
| 41 | +const READ_PLAYBOOK = gql` |
| 42 | + query playbook($id: String!) { |
| 43 | + playbook(id: $id) { |
| 44 | + id |
| 45 | + name |
| 46 | + description |
| 47 | + playbook_running |
| 48 | + playbook_definition |
| 49 | + } |
| 50 | + } |
| 51 | +`; |
| 52 | + |
| 53 | +const UPDATE_PLAYBOOK = gql` |
| 54 | + mutation playbookFieldPatchEdit($id: ID!, $input: [EditInput!]!) { |
| 55 | + playbookFieldPatch(id: $id, input: $input) { |
| 56 | + id |
| 57 | + name |
| 58 | + } |
| 59 | + } |
| 60 | +`; |
| 61 | + |
| 62 | +const DELETE_PLAYBOOK = gql` |
| 63 | + mutation playbookDelete($id: ID!) { |
| 64 | + playbookDelete(id:$id) |
| 65 | + } |
| 66 | +`; |
| 67 | + |
| 68 | +describe('Playbook resolver standard behavior', () => { |
| 69 | + let playbookId = ''; |
| 70 | + const playbookName = 'Playbook1'; |
| 71 | + it('should list playbooks', async () => { |
| 72 | + const queryResult = await adminQueryWithSuccess({ query: LIST_PLAYBOOKS, variables: { first: 10 } }); |
| 73 | + expect(queryResult.data?.playbooks.edges.length).toEqual(0); |
| 74 | + }); |
| 75 | + it('should add playbook', async () => { |
| 76 | + const input = { |
| 77 | + input: { |
| 78 | + name: playbookName, |
| 79 | + } |
| 80 | + }; |
| 81 | + const queryResult = await adminQueryWithSuccess({ |
| 82 | + query: CREATE_PLAYBOOK, |
| 83 | + variables: input, |
| 84 | + }); |
| 85 | + expect(queryResult.data?.playbookAdd.name).toEqual(playbookName); |
| 86 | + playbookId = queryResult.data?.playbookAdd.id; |
| 87 | + }); |
| 88 | + it('should list playbooks', async () => { |
| 89 | + const queryResult = await adminQueryWithSuccess({ query: LIST_PLAYBOOKS, variables: { first: 10 } }); |
| 90 | + expect(queryResult.data?.playbooks.edges.length).toEqual(1); |
| 91 | + }); |
| 92 | + it('should read playbook', async () => { |
| 93 | + const queryResult = await adminQueryWithSuccess({ query: READ_PLAYBOOK, variables: { id: playbookId } }); |
| 94 | + expect(queryResult.data?.playbook.name).toEqual(playbookName); |
| 95 | + expect(queryResult.data?.playbook.playbook_running).toEqual(false); |
| 96 | + }); |
| 97 | + it('should update playbook', async () => { |
| 98 | + const queryResult = await adminQueryWithSuccess({ |
| 99 | + query: UPDATE_PLAYBOOK, |
| 100 | + variables: { |
| 101 | + id: playbookId, |
| 102 | + input: [ |
| 103 | + { key: 'name', value: ['Playbook1 - updated'] }, |
| 104 | + ] |
| 105 | + } |
| 106 | + }); |
| 107 | + expect(queryResult.data?.playbookFieldPatch.name).toEqual('Playbook1 - updated'); |
| 108 | + }); |
| 109 | + it('should remove playbook', async () => { |
| 110 | + const queryResult = await adminQueryWithSuccess({ |
| 111 | + query: DELETE_PLAYBOOK, |
| 112 | + variables: { id: playbookId }, |
| 113 | + }); |
| 114 | + expect(queryResult.data?.playbookDelete).toEqual(playbookId); |
| 115 | + }); |
| 116 | +}); |
0 commit comments