Skip to content

Commit

Permalink
[backend] WIP Update model (#4538)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goumies authored and marieflorescontact committed Jul 15, 2024
1 parent e9a3fe4 commit 6a76582
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions opencti-platform/opencti-graphql/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,7 @@ export type CaseEdge = {

export type CaseIncident = BasicObject & Case & Container & StixCoreObject & StixDomainObject & StixObject & {
__typename?: 'CaseIncident';
authorized_members?: Maybe<Array<MemberAccess>>;
avatar?: Maybe<OpenCtiFile>;
cases?: Maybe<CaseConnection>;
confidence?: Maybe<Scalars['Int']['output']>;
Expand Down Expand Up @@ -30960,6 +30961,7 @@ export type CaseEdgeResolvers<ContextType = any, ParentType extends ResolversPar
}>;

export type CaseIncidentResolvers<ContextType = any, ParentType extends ResolversParentTypes['CaseIncident'] = ResolversParentTypes['CaseIncident']> = ResolversObject<{
authorized_members?: Resolver<Maybe<Array<ResolversTypes['MemberAccess']>>, ParentType, ContextType>;
avatar?: Resolver<Maybe<ResolversTypes['OpenCtiFile']>, ParentType, ContextType>;
cases?: Resolver<Maybe<ResolversTypes['CaseConnection']>, ParentType, ContextType, Partial<CaseIncidentCasesArgs>>;
confidence?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { buildRefRelationKey } from '../../../schema/general';
import { RELATION_OBJECT_ASSIGNEE } from '../../../schema/stixRefRelationship';
import { stixDomainObjectDelete } from '../../../domain/stixDomainObject';
import { addCaseIncident, caseIncidentContainsStixObjectOrStixRelationship, findAll, findById } from './case-incident-domain';
import { getAuthorizedMembers } from '../../../utils/authorizedMembers';

const caseIncidentResolvers: Resolvers = {
Query: {
Expand All @@ -12,6 +13,9 @@ const caseIncidentResolvers: Resolvers = {
return caseIncidentContainsStixObjectOrStixRelationship(context, context.user, args.id, args.stixObjectOrStixRelationshipId);
},
},
CaseIncident: {
authorized_members: (caseIncidentResponse, _, context) => getAuthorizedMembers(context, context.user, caseIncidentResponse),
},
CaseIncidentsOrdering: {
creator: 'creator_id',
objectAssignee: buildRefRelationKey(RELATION_OBJECT_ASSIGNEE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type CaseIncident implements BasicObject & StixObject & StixCoreObject & StixDom
response_types: [String!]
severity: String
priority: String
authorized_members: [MemberAccess!]
}

# Ordering
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { describe, it, expect } from 'vitest';
import gql from 'graphql-tag';
import { queryAsAdmin } from '../../utils/testQuery';

describe('Case Incident Response resolver standard behavior', () => {
let caseIncidentResponseId = '';

const READ_QUERY = gql`
query caseIncident($id: String!) {
caseIncident(id: $id) {
id
standard_id
name
description
toStix
authorized_members {
id
}
}
}
`;

it('should case incident response created', async () => {
const CREATE_QUERY = gql`
mutation CaseIncidentAdd($input: CaseIncidentAddInput!) {
caseIncidentAdd(input: $input){
id
standard_id
name
description
authorized_members {
id
}
}
}
`;
const caseIncidentResponseData = await queryAsAdmin({
query: CREATE_QUERY,
variables: {
input: {
name: 'Case Incident Response'
}
}
});
expect(caseIncidentResponseData).not.toBeNull();
expect(caseIncidentResponseData?.data?.caseIncidentAdd.authorized_members).not.toBeUndefined();
caseIncidentResponseId = caseIncidentResponseData?.data?.caseIncidentAdd.id;
});
it('should Case Incident Response deleted', async () => {
const DELETE_QUERY = gql`
mutation CaseIncidentDelete($id: ID!) {
caseIncidentDelete(id: $id)
}
`;
// Delete the case
await queryAsAdmin({
query: DELETE_QUERY,
variables: { id: caseIncidentResponseId },
});
// Verify is no longer found
const queryResult = await queryAsAdmin({ query: READ_QUERY, variables: { id: caseIncidentResponseId } });
expect(queryResult).not.toBeNull();
expect(queryResult?.data?.caseIncident).toBeNull();
});
});

0 comments on commit 6a76582

Please sign in to comment.