diff --git a/src/requests/flow.ts b/src/requests/flow.ts index 8f7757cb..74e37006 100644 --- a/src/requests/flow.ts +++ b/src/requests/flow.ts @@ -26,10 +26,20 @@ export class FlowClient { return publishFlow(this.client, args); } + /** + * Only used in test environments + */ async _destroy(flowId: string): Promise { return _destroyFlow(this.client, flowId); } + /** + * Only used in test environments + */ + async _destroyAll(): Promise { + return _destroyAllFlows(this.client); + } + async _destroyPublished(publishedFlowId: number): Promise { return _destroyPublishedFlow(this.client, publishedFlowId); } @@ -223,6 +233,20 @@ export async function _destroyFlow( return Boolean(response.delete_flows_by_pk?.id); } +export async function _destroyAllFlows( + client: GraphQLClient, +): Promise { + const response: { deleteFlows: { affectedRows: string } } = + await client.request(gql` + mutation DestroyAllFlows { + deleteFlows: delete_flows { + affectedRows: affected_rows + } + } + `); + return Boolean(response.deleteFlows.affectedRows); +} + export async function _destroyPublishedFlow( client: GraphQLClient, publishedFlowId: number, diff --git a/src/requests/team.ts b/src/requests/team.ts index afabda3d..d2ab2744 100644 --- a/src/requests/team.ts +++ b/src/requests/team.ts @@ -44,9 +44,19 @@ export class TeamClient { return removeMember(this.client, args); } + /** + * Only used in test environments + */ async _destroy(teamId: number): Promise { return _destroyTeam(this.client, teamId); } + + /** + * Only used in test environments + */ + async _destroyAll(): Promise { + return _destroyAllTeams(this.client); + } } const defaultNotifyPersonalisation = { @@ -145,6 +155,20 @@ export async function _destroyTeam( return Boolean(response.delete_teams_by_pk?.id); } +export async function _destroyAllTeams( + client: GraphQLClient, +): Promise { + const response: { deleteTeams: { affectedRows: number } } = + await client.request(gql` + mutation DestroyAllTeams { + deleteTeams: delete_teams(where: { id: { _is_null: false } }) { + affectedRows: affected_rows + } + } + `); + return Boolean(response.deleteTeams.affectedRows); +} + export async function upsertMember( client: GraphQLClient, args: UpsertMember, diff --git a/src/requests/user.ts b/src/requests/user.ts index 8d4de977..0991324a 100644 --- a/src/requests/user.ts +++ b/src/requests/user.ts @@ -21,8 +21,18 @@ export class UserClient { return createUser(this.client, args); } + /** + * Only used in test environments + */ async _destroy(userId: number): Promise { - return _destroyUser(this.client, userId); + return _destroyUserByPK(this.client, userId); + } + + /** + * Only used in test environments + */ + async _destroyAll(): Promise { + return _destroyAllUsers(this.client); } async getByEmail(email: string): Promise { @@ -64,7 +74,7 @@ export async function createUser( return response.insert_users_one.id; } -export async function _destroyUser( +export async function _destroyUserByPK( client: GraphQLClient, userId: number, ): Promise { @@ -82,6 +92,20 @@ export async function _destroyUser( return Boolean(response.delete_users_by_pk?.id); } +export async function _destroyAllUsers( + client: GraphQLClient, +): Promise { + const response: { deleteUsers: { affectedRows: number } } = + await client.request(gql` + mutation DestroyAllUsers { + deleteUsers: delete_users(where: { id: { _is_null: false } }) { + affectedRows: affected_rows + } + } + `); + return Boolean(response.deleteUsers.affectedRows); +} + async function getByEmail( client: GraphQLClient, email: string,