Skip to content

Commit

Permalink
Add query tests to checklists field
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarvarela committed Dec 10, 2024
1 parent 14efffb commit 8b6cabc
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
163 changes: 163 additions & 0 deletions site/gatsby-site/server/tests/fixtures/checklists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { ObjectId } from 'bson';
import { Fixture } from "../utils";
import { Checklist, ChecklistInsertType, ChecklistUpdateType } from "../../generated/graphql";

const checklist1 = {
_id: new ObjectId("6537e59e9208f3f75b2db1f7"),
owner_id: "63601cdc29e6840df23ad3e5",
tags_methods: ["GMF:Known AI Technology:Language Modeling"],
tags_goals: ["GMF:Known AI Goal:Chatbot"],
about: "",
risks: [
{
id: "09511dbb-6bd8-42de-bc7b-bbac8864455b",
tags: [
"GMF:Known AI Technical Failure:Unsafe Exposure or Access"
],
severity: "",
title: "Unsafe Exposure or Access",
generated: false,
risk_status: "Not Mitigated",
likelihood: "",
touched: false,
risk_notes: ""
}
],
tags_other: ["CSETv1:Entertainment Industry:yes"],
id: "849bd303-261f-4abe-8746-77dad5841dbe",
name: "Test Checklist"
}

const checklist2 = {
_id: new ObjectId("6537e59e9208f3f75b2db1f8"),
owner_id: "63601cdc29e6840df23ad3e5",
tags_methods: ["GMF:Known AI Technology:Transformer"],
tags_goals: ["GMF:Known AI Goal:Chatbot"],
about: "",
risks: [
{
id: "09511dbb-6bd8-42de-bc7b-bbac8864455b",
tags: [
"GMF:Known AI Technical Failure:Unsafe Exposure or Access"
],
severity: "",
title: "Unsafe Exposure or Access",
generated: false,
risk_status: "Not Mitigated",
likelihood: "",
touched: false,
risk_notes: ""
}
],
tags_other: ["CSETv1:Entertainment Industry:yes"],
id: "849bd303-261f-4abe-8746-77dad5841dbe",
name: "Test Checklist 2"
}

const subscriber = {
_id: new ObjectId('60a7c5b7b4f5b8a6d8f9c7e6'),
first_name: 'Subscriber',
last_name: 'One',
roles: ['subscriber'],
userId: 'subscriber1',
}

const admin = {
_id: new ObjectId('60a7c5b7b4f5b8a6d8f9c7e5'),
first_name: 'Super',
last_name: 'Man',
roles: ['admin'],
userId: 'admin',
}

const anonymous = {
_id: new ObjectId('60a7c5b7b4f5b8a6d8f9c7e9'),
first_name: 'Anon',
last_name: 'Anon',
roles: [],
userId: 'anon',
}

const fixture: Fixture<Checklist, ChecklistUpdateType, ChecklistInsertType> = {
name: 'checklists',
query: `
_id
owner_id
tags_methods
tags_goals
about
risks {
id
}
tags_other
id
name
`,
seeds: {
customData: {
users: [
subscriber,
admin,
anonymous,
],
},
aiidprod: {
checklists: [checklist1, checklist2]
}
},
testSingular: {
allowed: [anonymous, subscriber, admin],
denied: [],
filter: { _id: { EQ: new ObjectId("6537e59e9208f3f75b2db1f7") } },
result: {
id: "849bd303-261f-4abe-8746-77dad5841dbe",
name: "Test Checklist",
},
},
testPluralFilter: {
allowed: [anonymous, subscriber, admin],
denied: [],
filter: {
_id: { EQ: new ObjectId("6537e59e9208f3f75b2db1f7") },
},
result: [
{
id: "849bd303-261f-4abe-8746-77dad5841dbe",
name: "Test Checklist",
}
]
},
testPluralSort: {
allowed: [anonymous, subscriber, admin],
denied: [],
sort: { name: "ASC" },
result: [
{
name: "Test Checklist",
},
{
name: "Test Checklist 2",
},
],
},
testPluralPagination: {
allowed: [subscriber],
denied: [],
pagination: { limit: 1, skip: 1 },
sort: { name: "ASC" },
result: [
{
name: "Test Checklist 2",
},
]
},
testUpdateOne: null,
testUpdateMany: null,
testInsertOne: null,
testInsertMany: null,
testDeleteOne: null,
testDeleteMany: null,
testUpsertOne: null,
}

export default fixture;
2 changes: 2 additions & 0 deletions site/gatsby-site/server/tests/query-fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import subscriptionsFixture from './fixtures/subscriptions';
import duplicatesFixture from './fixtures/duplicates';
import reportsHistoryFixture from './fixtures/reportsHistory';
import incidentsHistoryFixture from './fixtures/incidentsHistory';
import checklistsFixture from './fixtures/checklists';

import * as context from '../context';

Expand All @@ -29,6 +30,7 @@ const fixtures = [
duplicatesFixture,
reportsHistoryFixture,
incidentsHistoryFixture,
checklistsFixture,
]

fixtures.forEach((collection) => {
Expand Down

0 comments on commit 8b6cabc

Please sign in to comment.