-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(e2e): teamAdmin
permission tests
#2230
Changes from 15 commits
c28fdcb
d6a62b6
d0e0a8c
37dc489
b7d9043
a0e0ff6
af3f0ec
14f12f1
f5b5fbb
3e120bc
5af1451
31413e5
367744f
2df8311
6a562fc
d15795d
6ae654d
1833a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { DocumentNode, Kind } from "graphql/language"; | ||
import { $admin, getClient } from "../client"; | ||
import { CustomWorld } from "./steps"; | ||
import { queries } from "./queries"; | ||
import { createFlow, createTeam, createUser } from "../globalHelpers"; | ||
|
||
export type Action = "insert" | "update" | "delete" | "select"; | ||
export type Table = keyof typeof queries; | ||
|
||
interface PerformGQLQueryArgs { | ||
world: CustomWorld; | ||
action: string; | ||
table: string; | ||
action: Action; | ||
table: Table; | ||
} | ||
|
||
export const addUserToTeam = async (userId: number, teamId: number) => { | ||
|
@@ -24,26 +28,27 @@ | |
}; | ||
|
||
export const setup = async () => { | ||
const user1Id = await createUser({ email: "[email protected]" }); | ||
const teamId1 = await createTeam({ name: "E2E Team 1", slug: "e2e-team1" }); | ||
const team1FlowId = await createFlow({ | ||
teamId: teamId1, | ||
slug: "team-1-flow", | ||
}); | ||
|
||
const user2Id = await createUser({ email: "[email protected]" }); | ||
const teamId2 = await createTeam({ name: "E2E Team 2", slug: "e2e-team2" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double checking i understand this: in overall setup, we create two users who are by default not a platform admin and they also do not have roles on either i'm wondering a bit if it'd be clearer to setup more explicitly with something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I appreciate this is an unclear point - team1 and team2 are quite vague/meaningless names but I needed something to differentiate (I was also considering red/blue or something to make it slightly more distinct). The intention is that there are -
I'll add comments to explicitly explain the setup here 👍 |
||
const user1 = { | ||
id: await createUser({ email: "[email protected]" }), | ||
email: "[email protected]", | ||
}; | ||
const user2 = { | ||
id: await createUser({ email: "[email protected]" }), | ||
email: "[email protected]", | ||
}; | ||
const team1Flow = await createFlow({ teamId: teamId1, slug: "team-1-flow" }); | ||
const team2Flow = await createFlow({ teamId: teamId2, slug: "team-2-flow" }); | ||
const team2FlowId = await createFlow({ | ||
teamId: teamId2, | ||
slug: "team-2-flow", | ||
}); | ||
|
||
const world = { | ||
user1Id, | ||
teamId1, | ||
team1FlowId, | ||
user2Id, | ||
teamId2, | ||
user1, | ||
user2, | ||
team1Flow, | ||
team2Flow, | ||
team2FlowId, | ||
}; | ||
|
||
return world; | ||
|
@@ -55,7 +60,34 @@ | |
table, | ||
}: PerformGQLQueryArgs) => { | ||
const query = queries[table][action]; | ||
const client = (await getClient(world.activeUser.email)).client; | ||
const result = await client.request(query, { teamId1: world.teamId1 }); | ||
const variables = buildVariables(query, world); | ||
const client = (await getClient(world.activeUserEmail)).client; | ||
const { result } = await client.request<Record<"result", any>>( | ||
Check warning on line 65 in e2e/tests/api-driven/src/permissions/helpers.ts GitHub Actions / E2E tests
|
||
query, | ||
variables, | ||
); | ||
return result; | ||
}; | ||
|
||
/** | ||
* Parse GQL query to extract variables required for query | ||
* Match with values from our test world to construct variables for query | ||
*/ | ||
const buildVariables = (query: DocumentNode, world: CustomWorld) => { | ||
const variables = {}; | ||
const definitionNode = query.definitions[0]; | ||
|
||
if (definitionNode.kind !== Kind.OPERATION_DEFINITION) return variables; | ||
if (!definitionNode.variableDefinitions) return variables; | ||
|
||
Object.keys(world).forEach((key) => { | ||
const isVariableUsedInQuery = definitionNode.variableDefinitions!.find( | ||
(varDef) => varDef.variable.name.value === key, | ||
); | ||
if (isVariableUsedInQuery) { | ||
variables[key] = world[key]; | ||
} | ||
}); | ||
|
||
return variables; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
import { INSERT_FLOW_QUERY } from "./flows"; | ||
import { | ||
DELETE_FLOW_QUERY, | ||
INSERT_FLOW_QUERY, | ||
UPDATE_FLOW_QUERY, | ||
} from "./flows"; | ||
import { INSERT_OPERATION_QUERY, UPDATE_OPERATION_QUERY } from "./operations"; | ||
import { INSERT_PUBLISHED_FLOW_QUERY } from "./publishedFlows"; | ||
import { SELECT_TEAM_MEMBERS_QUERY } from "./teamMembers"; | ||
import { SELECT_USERS_QUERY } from "./users"; | ||
|
||
export const queries = { | ||
flows: { | ||
insert: INSERT_FLOW_QUERY, | ||
update: UPDATE_FLOW_QUERY, | ||
delete: DELETE_FLOW_QUERY, | ||
}, | ||
}; | ||
users: { | ||
select: SELECT_USERS_QUERY, | ||
}, | ||
published_flows: { | ||
insert: INSERT_PUBLISHED_FLOW_QUERY, | ||
}, | ||
team_members: { | ||
select: SELECT_TEAM_MEMBERS_QUERY, | ||
}, | ||
operations: { | ||
insert: INSERT_OPERATION_QUERY, | ||
update: UPDATE_OPERATION_QUERY, | ||
}, | ||
} as const; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { gql } from "graphql-tag"; | ||
|
||
export const INSERT_OPERATION_QUERY = gql` | ||
mutation InsertOperationE2E($team1FlowId: uuid!) { | ||
result: insert_operations_one( | ||
object: { data: "{}", flow_id: $team1FlowId } | ||
) { | ||
id | ||
} | ||
} | ||
`; | ||
|
||
export const UPDATE_OPERATION_QUERY = gql` | ||
mutation UpdateOperationE2E($team1FlowId: uuid!) { | ||
result: update_operations( | ||
where: { flow_id: { _eq: $team1FlowId } } | ||
_set: { data: "" } | ||
) { | ||
returning { | ||
id | ||
} | ||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import gql from "graphql-tag"; | ||
|
||
export const INSERT_PUBLISHED_FLOW_QUERY = gql` | ||
mutation InsertPublishedFlowsE2E($team1FlowId: uuid!, $activeUserId: Int) { | ||
result: insert_published_flows( | ||
objects: { | ||
data: "{}" | ||
flow_id: $team1FlowId | ||
publisher_id: $activeUserId | ||
} | ||
) { | ||
returning { | ||
id | ||
} | ||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import gql from "graphql-tag"; | ||
|
||
export const SELECT_TEAM_MEMBERS_QUERY = gql` | ||
query SelectTeamMembersE2E($user1Id: Int) { | ||
result: team_members(where: { user_id: { _eq: $user1Id } }) { | ||
id | ||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import gql from "graphql-tag"; | ||
|
||
export const SELECT_USERS_QUERY = gql` | ||
query SelectUsersE2E($user1Id: Int!) { | ||
result: users_by_pk(id: $user1Id) { | ||
id | ||
} | ||
} | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think helen & mel previously reported an annoying issue where e2e test emails using the @opensystemslab.io domain were causing bounced errors in the enquiries inbox? can we use a harmless @example.com or something instead?