-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] add playbook resolver test (#8793)
Co-authored-by: Celine Sebe <[email protected]> Co-authored-by: marie flores <[email protected]>
- Loading branch information
1 parent
b43162b
commit 9fd883c
Showing
1 changed file
with
116 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
opencti-platform/opencti-graphql/tests/02-integration/02-resolvers/playbook-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |