refactor(backend): externalize gql queries in backend specs (#8881)

* externalize gql queries in backend specs

* externalize all queries & mutations where easily possible

missing change

* rename old queries & remove unnecessary function call

* fix tests - notifications

* fix tests - moderation

* remove _CreatePostMutation file

* remove _filterPosts & _postQuery files
This commit is contained in:
Ulf Gebhardt 2025-09-08 11:17:01 +01:00 committed by GitHub
parent dbae0862f9
commit 74f6c5b329
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
126 changed files with 2007 additions and 2140 deletions

View File

@ -8,13 +8,13 @@ import sample from 'lodash/sample'
import CONFIG from '@config/index'
import { categories } from '@constants/categories'
import { changeGroupMemberRoleMutation } from '@graphql/queries/changeGroupMemberRoleMutation'
import { createCommentMutation } from '@graphql/queries/createCommentMutation'
import { createGroupMutation } from '@graphql/queries/createGroupMutation'
import { ChangeGroupMemberRole } from '@graphql/queries/ChangeGroupMemberRole'
import { CreateComment } from '@graphql/queries/CreateComment'
import { CreateGroup } from '@graphql/queries/CreateGroup'
import { CreateMessage } from '@graphql/queries/CreateMessage'
import { createPostMutation } from '@graphql/queries/createPostMutation'
import { createRoomMutation } from '@graphql/queries/createRoomMutation'
import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
import { CreatePost } from '@graphql/queries/CreatePost'
import { CreateRoom } from '@graphql/queries/CreateRoom'
import { JoinGroup } from '@graphql/queries/JoinGroup'
import { createApolloTestSetup } from '@root/test/helpers'
import Factory from './factories'
@ -341,7 +341,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
console.log('seed', 'groups')
authenticatedUser = await peterLustig.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'g0',
name: 'Investigative Journalism',
@ -354,21 +354,21 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g0',
userId: 'u2',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g0',
userId: 'u4',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g0',
userId: 'u6',
@ -376,7 +376,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g0',
userId: 'u2',
@ -385,7 +385,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g0',
userId: 'u4',
@ -396,7 +396,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
// eslint-disable-next-line no-console
console.log('seed', 'group posts')
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p0-g0',
groupId: 'g0',
@ -408,7 +408,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = await bobDerBaumeister.toJson()
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p1-g0',
groupId: 'g0',
@ -420,7 +420,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = await jennyRostock.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'g1',
name: 'School For Citizens',
@ -433,35 +433,35 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g1',
userId: 'u1',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g1',
userId: 'u2',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g1',
userId: 'u5',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g1',
userId: 'u6',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g1',
userId: 'u7',
@ -469,7 +469,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g1',
userId: 'u1',
@ -477,7 +477,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g1',
userId: 'u5',
@ -485,7 +485,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g1',
userId: 'u6',
@ -493,7 +493,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p0-g1',
groupId: 'g1',
@ -504,7 +504,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
})
authenticatedUser = await peterLustig.toJson()
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p1-g1',
groupId: 'g1',
@ -516,7 +516,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = await bobDerBaumeister.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'g2',
name: 'Yoga Practice',
@ -528,35 +528,35 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g2',
userId: 'u3',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g2',
userId: 'u4',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g2',
userId: 'u5',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g2',
userId: 'u6',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g2',
userId: 'u7',
@ -564,7 +564,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g2',
userId: 'u3',
@ -572,7 +572,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g2',
userId: 'u4',
@ -580,7 +580,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g2',
userId: 'u5',
@ -588,7 +588,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g2',
userId: 'u6',
@ -598,7 +598,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = await louie.toJson()
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p0-g2',
groupId: 'g2',
@ -614,7 +614,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
const now = new Date()
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'e0',
title: 'Illegaler Kindergeburtstag',
@ -629,7 +629,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'e1',
title: 'Wir Schützen den Stuttgarter Schlossgarten',
@ -644,7 +644,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'e2',
title: 'IT 4 Change Treffen',
@ -848,7 +848,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
'The new physics of <a class="hashtag" data-hashtag-id="QuantenFlussTheorie" href="/?hashtag=QuantenFlussTheorie">#QuantenFlussTheorie</a> can explain <a class="hashtag" data-hashtag-id="QuantumGravity" href="/?hashtag=QuantumGravity">#QuantumGravity</a>! <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> got that already. ;-)'
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p2',
title: `Nature Philosophy Yoga`,
@ -857,7 +857,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p7',
title: 'This is post #7',
@ -866,7 +866,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p8',
title: `Quantum Flow Theory explains Quantum Gravity`,
@ -875,7 +875,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p12',
title: 'This is post #12',
@ -899,7 +899,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
const mentionInComment2 =
'Did <a class="mention" data-mention-id="u1" href="/profile/u1">@peter-lustig</a> tell you?'
await mutate({
mutation: createCommentMutation,
mutation: CreateComment,
variables: {
id: 'c4',
postId: 'p2',
@ -907,7 +907,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createCommentMutation,
mutation: CreateComment,
variables: {
id: 'c4-1',
postId: 'p2',
@ -915,7 +915,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
})
await mutate({
mutation: createCommentMutation,
mutation: CreateComment,
variables: {
postId: 'p14',
content: faker.lorem.paragraph(),
@ -1223,7 +1223,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = userObj
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'g2',
userId: userObj.id,
@ -1530,7 +1530,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
console.log('seed', 'chat')
authenticatedUser = await huey.toJson()
const { data: roomHueyPeter } = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: (await peterLustig.toJson()).id,
},
@ -1557,7 +1557,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
authenticatedUser = await huey.toJson()
const { data: roomHueyJenny } = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: (await jennyRostock.toJson()).id,
},
@ -1584,7 +1584,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
for (const user of additionalUsers.slice(0, 99)) {
authenticatedUser = await jennyRostock.toJson()
const { data: room } = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: (await user.toJson()).id,
},

View File

@ -0,0 +1,11 @@
import gql from 'graphql-tag'
export const AddEmailAddress = gql`
mutation ($email: String!) {
AddEmailAddress(email: $email) {
email
verifiedAt
createdAt
}
}
`

View File

@ -0,0 +1,15 @@
import gql from 'graphql-tag'
export const AddPostEmotions = gql`
mutation ($to: _PostInput!, $data: _EMOTEDInput!) {
AddPostEmotions(to: $to, data: $data) {
from {
id
}
to {
id
}
emotion
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const Category = gql`
query {
Category {
id
slug
name
icon
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const ChangeGroupMemberRole = gql`
mutation ($groupId: ID!, $userId: ID!, $roleInGroup: GroupMemberRole!) {
ChangeGroupMemberRole(groupId: $groupId, userId: $userId, roleInGroup: $roleInGroup) {
id
name
slug
myRoleInGroup
}
}
`

View File

@ -1,9 +1,13 @@
import gql from 'graphql-tag'
export const createCommentMutation = gql`
export const CreateComment = gql`
mutation ($id: ID, $postId: ID!, $content: String!) {
CreateComment(id: $id, postId: $postId, content: $content) {
id
content
author {
name
}
}
}
`

View File

@ -0,0 +1,53 @@
import gql from 'graphql-tag'
export const CreateGroup = gql`
mutation (
$id: ID
$name: String!
$slug: String
$about: String
$description: String!
$groupType: GroupType!
$actionRadius: GroupActionRadius!
$categoryIds: [ID]
$locationName: String # empty string '' sets it to null
) {
CreateGroup(
id: $id
name: $name
slug: $slug
about: $about
description: $description
groupType: $groupType
actionRadius: $actionRadius
categoryIds: $categoryIds
locationName: $locationName
) {
id
name
slug
createdAt
updatedAt
disabled
deleted
about
description
descriptionExcerpt
groupType
actionRadius
categories {
id
slug
name
icon
}
locationName
location {
name
nameDE
nameEN
}
myRole
}
}
`

View File

@ -0,0 +1,50 @@
import gql from 'graphql-tag'
export const CreatePost = gql`
mutation (
$id: ID
$title: String!
$slug: String
$content: String!
$categoryIds: [ID]
$groupId: ID
$postType: PostType
$eventInput: _EventInput
) {
CreatePost(
id: $id
title: $title
slug: $slug
content: $content
categoryIds: $categoryIds
groupId: $groupId
postType: $postType
eventInput: $eventInput
) {
id
slug
title
content
disabled
deleted
postType
author {
name
}
categories {
id
}
eventStart
eventEnd
eventLocationName
eventVenue
eventIsOnline
eventLocation {
lng
lat
}
isObservedByMe
observingUsersCount
}
}
`

View File

@ -0,0 +1,22 @@
import gql from 'graphql-tag'
export const CreateRoom = gql`
mutation ($userId: ID!) {
CreateRoom(userId: $userId) {
id
roomId
roomName
lastMessageAt
unreadCount
#avatar
users {
_id
id
name
avatar {
url
}
}
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const DeleteComment = gql`
mutation ($id: ID!) {
DeleteComment(id: $id) {
id
content
contentExcerpt
deleted
}
}
`

View File

@ -0,0 +1,20 @@
import gql from 'graphql-tag'
export const DeletePost = gql`
mutation ($id: ID!) {
DeletePost(id: $id) {
id
deleted
content
contentExcerpt
image {
url
}
comments {
deleted
content
contentExcerpt
}
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const DeleteSocialMedia = gql`
mutation ($id: ID!) {
DeleteSocialMedia(id: $id) {
id
url
}
}
`

View File

@ -0,0 +1,30 @@
import gql from 'graphql-tag'
export const DeleteUser = gql`
mutation ($id: ID!, $resource: [Deletable]) {
DeleteUser(id: $id, resource: $resource) {
id
name
about
deleted
contributions {
id
content
contentExcerpt
deleted
comments {
id
content
contentExcerpt
deleted
}
}
comments {
id
content
contentExcerpt
deleted
}
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const Donations = gql`
query {
Donations {
id
showDonations
goal
progress
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const JoinGroup = gql`
mutation ($groupId: ID!, $userId: ID!) {
JoinGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const LeaveGroup = gql`
mutation ($groupId: ID!, $userId: ID!) {
LeaveGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`

View File

@ -1,9 +1,12 @@
import gql from 'graphql-tag'
export const Post = gql`
query ($orderBy: [_PostOrdering]) {
Post(orderBy: $orderBy) {
query ($id: ID, $filter: _PostFilter, $first: Int, $offset: Int, $orderBy: [_PostOrdering]) {
Post(id: $id, filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
id
title
content
eventStart
pinned
createdAt
pinnedAt

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const PostsEmotionsByCurrentUser = gql`
query ($postId: ID!) {
PostsEmotionsByCurrentUser(postId: $postId)
}
`

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const PostsEmotionsCountByEmotion = gql`
query ($postId: ID!, $data: _EMOTEDInput!) {
PostsEmotionsCountByEmotion(postId: $postId, data: $data)
}
`

View File

@ -0,0 +1,15 @@
import gql from 'graphql-tag'
export const RemovePostEmotions = gql`
mutation ($to: _PostInput!, $data: _EMOTEDInput!) {
RemovePostEmotions(to: $to, data: $data) {
from {
id
}
to {
id
}
emotion
}
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const RemoveUserFromGroup = gql`
mutation ($groupId: ID!, $userId: ID!) {
RemoveUserFromGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`

View File

@ -0,0 +1,34 @@
import gql from 'graphql-tag'
export const Room = gql`
query Room($first: Int, $offset: Int, $id: ID) {
Room(first: $first, offset: $offset, id: $id, orderBy: lastMessageAt_desc) {
id
roomId
roomName
avatar
lastMessageAt
unreadCount
lastMessage {
_id
id
content
senderId
username
avatar
date
saved
distributed
seen
}
users {
_id
id
name
avatar {
url
}
}
}
}
`

View File

@ -0,0 +1,9 @@
import gql from 'graphql-tag'
export const Signup = gql`
mutation ($email: String!, $locale: String!, $inviteCode: String) {
Signup(email: $email, locale: $locale, inviteCode: $inviteCode) {
email
}
}
`

View File

@ -1,6 +1,6 @@
import gql from 'graphql-tag'
export const signupVerificationMutation = gql`
export const SignupVerification = gql`
mutation (
$password: String!
$email: String!

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const UnreadRooms = gql`
query {
UnreadRooms
}
`

View File

@ -0,0 +1,12 @@
import gql from 'graphql-tag'
export const UpdateComment = gql`
mutation ($content: String!, $id: ID!) {
UpdateComment(content: $content, id: $id) {
id
content
createdAt
updatedAt
}
}
`

View File

@ -0,0 +1,14 @@
import gql from 'graphql-tag'
export const UpdateDonations = gql`
mutation ($showDonations: Boolean, $goal: Int, $progress: Int) {
UpdateDonations(showDonations: $showDonations, goal: $goal, progress: $progress) {
id
showDonations
goal
progress
createdAt
updatedAt
}
}
`

View File

@ -0,0 +1,54 @@
import gql from 'graphql-tag'
export const UpdateGroup = gql`
mutation (
$id: ID!
$name: String
$slug: String
$about: String
$description: String
$actionRadius: GroupActionRadius
$categoryIds: [ID]
$avatar: ImageInput
$locationName: String # empty string '' sets it to null
) {
UpdateGroup(
id: $id
name: $name
slug: $slug
about: $about
description: $description
actionRadius: $actionRadius
categoryIds: $categoryIds
avatar: $avatar
locationName: $locationName
) {
id
name
slug
createdAt
updatedAt
disabled
deleted
about
description
descriptionExcerpt
groupType
actionRadius
categories {
id
slug
name
icon
}
# avatar # test this as result
locationName
location {
name
nameDE
nameEN
}
myRole
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const UpdatePost = gql`
mutation ($id: ID!, $title: String!, $postContent: String!, $categoryIds: [ID]!) {
UpdatePost(id: $id, content: $postContent, title: $title, categoryIds: $categoryIds) {
title
content
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const UpdateSocialMedia = gql`
mutation ($id: ID!, $url: String!) {
UpdateSocialMedia(id: $id, url: $url) {
id
url
}
}
`

View File

@ -0,0 +1,9 @@
import gql from 'graphql-tag'
export const UpdateUser = gql`
mutation ($id: ID!, $name: String) {
UpdateUser(id: $id, name: $name) {
name
}
}
`

View File

@ -0,0 +1,9 @@
import gql from 'graphql-tag'
export const User = gql`
query ($name: String) {
User(name: $name) {
email
}
}
`

View File

@ -0,0 +1,11 @@
import gql from 'graphql-tag'
export const VerifyEmailAddress = gql`
mutation ($email: String!, $nonce: String!) {
VerifyEmailAddress(email: $email, nonce: $nonce) {
email
createdAt
verifiedAt
}
}
`

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const VerifyNonce = gql`
query ($email: String!, $nonce: String!) {
VerifyNonce(email: $email, nonce: $nonce)
}
`

View File

@ -1,14 +0,0 @@
import gql from 'graphql-tag'
export const changeGroupMemberRoleMutation = () => {
return gql`
mutation ($groupId: ID!, $userId: ID!, $roleInGroup: GroupMemberRole!) {
ChangeGroupMemberRole(groupId: $groupId, userId: $userId, roleInGroup: $roleInGroup) {
id
name
slug
myRoleInGroup
}
}
`
}

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const changePassword = gql`
mutation ($oldPassword: String!, $newPassword: String!) {
changePassword(oldPassword: $oldPassword, newPassword: $newPassword)
}
`

View File

@ -1,55 +0,0 @@
import gql from 'graphql-tag'
export const createGroupMutation = () => {
return gql`
mutation (
$id: ID
$name: String!
$slug: String
$about: String
$description: String!
$groupType: GroupType!
$actionRadius: GroupActionRadius!
$categoryIds: [ID]
$locationName: String # empty string '' sets it to null
) {
CreateGroup(
id: $id
name: $name
slug: $slug
about: $about
description: $description
groupType: $groupType
actionRadius: $actionRadius
categoryIds: $categoryIds
locationName: $locationName
) {
id
name
slug
createdAt
updatedAt
disabled
deleted
about
description
descriptionExcerpt
groupType
actionRadius
categories {
id
slug
name
icon
}
locationName
location {
name
nameDE
nameEN
}
myRole
}
}
`
}

View File

@ -1,52 +0,0 @@
import gql from 'graphql-tag'
export const createPostMutation = () => {
return gql`
mutation (
$id: ID
$title: String!
$slug: String
$content: String!
$categoryIds: [ID]
$groupId: ID
$postType: PostType
$eventInput: _EventInput
) {
CreatePost(
id: $id
title: $title
slug: $slug
content: $content
categoryIds: $categoryIds
groupId: $groupId
postType: $postType
eventInput: $eventInput
) {
id
slug
title
content
disabled
deleted
postType
author {
name
}
categories {
id
}
eventStart
eventEnd
eventLocationName
eventVenue
eventIsOnline
eventLocation {
lng
lat
}
isObservedByMe
observingUsersCount
}
}
`
}

View File

@ -1,24 +0,0 @@
import gql from 'graphql-tag'
export const createRoomMutation = () => {
return gql`
mutation ($userId: ID!) {
CreateRoom(userId: $userId) {
id
roomId
roomName
lastMessageAt
unreadCount
#avatar
users {
_id
id
name
avatar {
url
}
}
}
}
`
}

View File

@ -0,0 +1,21 @@
import gql from 'graphql-tag'
export const embed = gql`
query ($url: String!) {
embed(url: $url) {
type
title
author
publisher
date
description
url
image
audio
video
lang
sources
html
}
}
`

View File

@ -0,0 +1,28 @@
import gql from 'graphql-tag'
export const fileReport = gql`
mutation ($resourceId: ID!, $reasonCategory: ReasonCategory!, $reasonDescription: String!) {
fileReport(
resourceId: $resourceId
reasonCategory: $reasonCategory
reasonDescription: $reasonDescription
) {
createdAt
reasonCategory
reasonDescription
reportId
resource {
__typename
... on User {
name
}
... on Post {
title
}
... on Comment {
content
}
}
}
}
`

View File

@ -1,14 +0,0 @@
import gql from 'graphql-tag'
export const filterPosts = () => {
return gql`
query Post($filter: _PostFilter, $first: Int, $offset: Int, $orderBy: [_PostOrdering]) {
Post(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
id
title
content
eventStart
}
}
`
}

View File

@ -0,0 +1,14 @@
import gql from 'graphql-tag'
export const followUser = gql`
mutation ($id: ID!) {
followUser(id: $id) {
name
followedBy {
id
name
}
followedByCurrentUser
}
}
`

View File

@ -1,14 +0,0 @@
import gql from 'graphql-tag'
export const joinGroupMutation = () => {
return gql`
mutation ($groupId: ID!, $userId: ID!) {
JoinGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`
}

View File

@ -1,14 +0,0 @@
import gql from 'graphql-tag'
export const leaveGroupMutation = () => {
return gql`
mutation ($groupId: ID!, $userId: ID!) {
LeaveGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`
}

View File

@ -1,6 +1,6 @@
import gql from 'graphql-tag'
export const loginMutation = gql`
export const login = gql`
mutation ($email: String!, $password: String!) {
login(email: $email, password: $password)
}

View File

@ -0,0 +1,19 @@
import gql from 'graphql-tag'
export const markAllAsRead = gql`
mutation {
markAllAsRead {
from {
__typename
... on Post {
content
}
... on Comment {
content
}
}
read
createdAt
}
}
`

View File

@ -1,21 +0,0 @@
import gql from 'graphql-tag'
export const markAllAsReadMutation = () => {
return gql`
mutation {
markAllAsRead {
from {
__typename
... on Post {
content
}
... on Comment {
content
}
}
read
createdAt
}
}
`
}

View File

@ -0,0 +1,19 @@
import gql from 'graphql-tag'
export const markAsRead = gql`
mutation ($id: ID!) {
markAsRead(id: $id) {
from {
__typename
... on Post {
content
}
... on Comment {
content
}
}
read
createdAt
}
}
`

View File

@ -1,21 +0,0 @@
import gql from 'graphql-tag'
export const markAsReadMutation = () => {
return gql`
mutation ($id: ID!) {
markAsRead(id: $id) {
from {
__typename
... on Post {
content
}
... on Comment {
content
}
}
read
createdAt
}
}
`
}

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const markTeaserAsViewed = gql`
mutation ($id: ID!) {
markTeaserAsViewed(id: $id) {
id
viewedTeaserCount
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const muteGroup = gql`
mutation ($groupId: ID!) {
muteGroup(groupId: $groupId) {
id
isMutedByMe
}
}
`

View File

@ -0,0 +1,11 @@
import gql from 'graphql-tag'
export const muteUser = gql`
mutation ($id: ID!) {
muteUser(id: $id) {
id
name
isMuted
}
}
`

View File

@ -0,0 +1,11 @@
import gql from 'graphql-tag'
export const mutedUsers = gql`
query {
mutedUsers {
id
name
isMuted
}
}
`

View File

@ -1,21 +0,0 @@
import gql from 'graphql-tag'
export const notificationQuery = () => {
return gql`
query ($read: Boolean, $orderBy: NotificationOrdering) {
notifications(read: $read, orderBy: $orderBy) {
from {
__typename
... on Post {
content
}
... on Comment {
content
}
}
read
createdAt
}
}
`
}

View File

@ -0,0 +1,19 @@
import gql from 'graphql-tag'
export const notifications = gql`
query ($read: Boolean, $orderBy: NotificationOrdering) {
notifications(read: $read, orderBy: $orderBy) {
from {
__typename
... on Post {
content
}
... on Comment {
content
}
}
read
createdAt
}
}
`

View File

@ -0,0 +1,24 @@
import gql from 'graphql-tag'
export const pinPost = gql`
mutation ($id: ID!) {
pinPost(id: $id) {
id
title
content
author {
name
slug
}
pinnedBy {
id
name
role
}
createdAt
updatedAt
pinnedAt
pinned
}
}
`

View File

@ -1,13 +0,0 @@
import gql from 'graphql-tag'
export const postQuery = () => {
return gql`
query Post($id: ID!) {
Post(id: $id) {
id
title
content
}
}
`
}

View File

@ -1,18 +1,16 @@
import gql from 'graphql-tag'
export const profilePagePosts = () => {
return gql`
query profilePagePosts(
$filter: _PostFilter
$first: Int
$offset: Int
$orderBy: [_PostOrdering]
) {
profilePagePosts(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
id
title
content
}
export const profilePagePosts = gql`
query profilePagePosts(
$filter: _PostFilter
$first: Int
$offset: Int
$orderBy: [_PostOrdering]
) {
profilePagePosts(filter: $filter, first: $first, offset: $offset, orderBy: $orderBy) {
id
title
content
}
`
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const queryLocations = gql`
query ($place: String!, $lang: String!) {
queryLocations(place: $place, lang: $lang) {
place_name
id
}
}
`

View File

@ -1,14 +0,0 @@
import gql from 'graphql-tag'
export const removeUserFromGroupMutation = () => {
return gql`
mutation ($groupId: ID!, $userId: ID!) {
RemoveUserFromGroup(groupId: $groupId, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`
}

View File

@ -0,0 +1,34 @@
import gql from 'graphql-tag'
export const reports = gql`
query ($closed: Boolean) {
reports(orderBy: createdAt_desc, closed: $closed) {
id
createdAt
updatedAt
rule
disable
closed
resource {
__typename
... on User {
id
}
... on Post {
id
}
... on Comment {
id
}
}
filed {
submitter {
id
}
createdAt
reasonCategory
reasonDescription
}
}
}
`

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const requestPasswordReset = gql`
mutation ($email: String!, $locale: String!) {
requestPasswordReset(email: $email, locale: $locale)
}
`

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const resetPassword = gql`
mutation ($nonce: String!, $email: String!, $newPassword: String!) {
resetPassword(nonce: $nonce, email: $email, newPassword: $newPassword)
}
`

View File

@ -0,0 +1,17 @@
import gql from 'graphql-tag'
export const resetTrophyBadgesSelected = gql`
mutation {
resetTrophyBadgesSelected {
badgeTrophiesCount
badgeTrophiesSelected {
id
isDefault
}
badgeTrophiesUnused {
id
}
badgeTrophiesUnusedCount
}
}
`

View File

@ -0,0 +1,37 @@
import gql from 'graphql-tag'
export const review = gql`
mutation ($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
review(resourceId: $resourceId, disable: $disable, closed: $closed) {
createdAt
updatedAt
resource {
__typename
... on User {
id
disabled
}
... on Post {
id
disabled
}
... on Comment {
id
disabled
}
}
report {
id
createdAt
updatedAt
closed
reviewed {
createdAt
moderator {
id
}
}
}
}
}
`

View File

@ -0,0 +1,20 @@
import gql from 'graphql-tag'
export const revokeBadge = gql`
mutation ($badgeId: ID!, $userId: ID!) {
revokeBadge(badgeId: $badgeId, userId: $userId) {
id
badgeTrophies {
id
}
badgeVerification {
id
isDefault
}
badgeTrophiesSelected {
id
isDefault
}
}
}
`

View File

@ -1,36 +0,0 @@
import gql from 'graphql-tag'
export const roomQuery = () => {
return gql`
query Room($first: Int, $offset: Int, $id: ID) {
Room(first: $first, offset: $offset, id: $id, orderBy: lastMessageAt_desc) {
id
roomId
roomName
avatar
lastMessageAt
unreadCount
lastMessage {
_id
id
content
senderId
username
avatar
date
saved
distributed
seen
}
users {
_id
id
name
avatar {
url
}
}
}
}
`
}

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const saveCategorySettings = gql`
mutation ($activeCategories: [String]) {
saveCategorySettings(activeCategories: $activeCategories)
}
`

View File

@ -1,16 +1,14 @@
import gql from 'graphql-tag'
export const searchPosts = () => {
return gql`
query ($query: String!, $firstPosts: Int, $postsOffset: Int) {
searchPosts(query: $query, firstPosts: $firstPosts, postsOffset: $postsOffset) {
postCount
posts {
id
title
content
}
export const searchPosts = gql`
query ($query: String!, $firstPosts: Int, $postsOffset: Int) {
searchPosts(query: $query, firstPosts: $firstPosts, postsOffset: $postsOffset) {
postCount
posts {
id
title
content
}
}
`
}
}
`

View File

@ -0,0 +1,22 @@
import gql from 'graphql-tag'
export const searchResults = gql`
query ($query: String!) {
searchResults(query: $query, limit: 5) {
__typename
... on Post {
id
title
content
}
... on User {
id
slug
name
}
... on Tag {
id
}
}
}
`

View File

@ -0,0 +1,16 @@
import gql from 'graphql-tag'
export const setVerificationBadge = gql`
mutation ($badgeId: ID!, $userId: ID!) {
setVerificationBadge(badgeId: $badgeId, userId: $userId) {
id
badgeVerification {
id
isDefault
}
badgeTrophies {
id
}
}
}
`

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const shout = gql`
mutation ($id: ID!) {
shout(id: $id, type: Post)
}
`

View File

@ -0,0 +1,13 @@
import gql from 'graphql-tag'
export const switchUserRole = gql`
mutation ($role: UserRole!, $id: ID!) {
switchUserRole(role: $role, id: $id) {
name
role
id
updatedAt
email
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const toggleObservePost = gql`
mutation ($id: ID!, $value: Boolean!) {
toggleObservePost(id: $id, value: $value) {
isObservedByMe
observingUsersCount
}
}
`

View File

@ -0,0 +1,14 @@
import gql from 'graphql-tag'
export const unfollowUser = gql`
mutation ($id: ID!) {
unfollowUser(id: $id) {
name
followedBy {
id
name
}
followedByCurrentUser
}
}
`

View File

@ -0,0 +1,10 @@
import gql from 'graphql-tag'
export const unmuteGroup = gql`
mutation ($groupId: ID!) {
unmuteGroup(groupId: $groupId) {
id
isMutedByMe
}
}
`

View File

@ -0,0 +1,11 @@
import gql from 'graphql-tag'
export const unmuteUser = gql`
mutation ($id: ID!) {
unmuteUser(id: $id) {
id
name
isMuted
}
}
`

View File

@ -0,0 +1,24 @@
import gql from 'graphql-tag'
export const unpinPost = gql`
mutation ($id: ID!) {
unpinPost(id: $id) {
id
title
content
author {
name
slug
}
pinnedBy {
id
name
role
}
createdAt
updatedAt
pinned
pinnedAt
}
}
`

View File

@ -1,9 +0,0 @@
import gql from 'graphql-tag'
export const unreadRoomsQuery = () => {
return gql`
query {
UnreadRooms
}
`
}

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const unshout = gql`
mutation ($id: ID!) {
unshout(id: $id, type: Post)
}
`

View File

@ -1,56 +0,0 @@
import gql from 'graphql-tag'
export const updateGroupMutation = () => {
return gql`
mutation (
$id: ID!
$name: String
$slug: String
$about: String
$description: String
$actionRadius: GroupActionRadius
$categoryIds: [ID]
$avatar: ImageInput
$locationName: String # empty string '' sets it to null
) {
UpdateGroup(
id: $id
name: $name
slug: $slug
about: $about
description: $description
actionRadius: $actionRadius
categoryIds: $categoryIds
avatar: $avatar
locationName: $locationName
) {
id
name
slug
createdAt
updatedAt
disabled
deleted
about
description
descriptionExcerpt
groupType
actionRadius
categories {
id
slug
name
icon
}
# avatar # test this as result
locationName
location {
name
nameDE
nameEN
}
myRole
}
}
`
}

View File

@ -0,0 +1,7 @@
import gql from 'graphql-tag'
export const updateOnlineStatus = gql`
mutation ($status: OnlineStatus!) {
updateOnlineStatus(status: $status)
}
`

View File

@ -0,0 +1,24 @@
import gql from 'graphql-tag'
export const userData = gql`
query ($id: ID!) {
userData(id: $id) {
user {
id
name
slug
}
posts {
id
title
content
comments {
content
author {
slug
}
}
}
}
}
`

View File

@ -13,7 +13,7 @@ import { UserInputError } from 'apollo-server'
import Factory, { cleanDatabase } from '@db/factories'
import File from '@db/models/File'
import { CreateMessage } from '@graphql/queries/CreateMessage'
import { createRoomMutation } from '@graphql/queries/createRoomMutation'
import { CreateRoom } from '@graphql/queries/CreateRoom'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { S3Config } from '@src/config'
@ -93,7 +93,7 @@ describe('delete Attachment', () => {
authenticatedUser = user
const { data: room } = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: chatPartner.id,
},

View File

@ -5,8 +5,10 @@ import gql from 'graphql-tag'
import { TROPHY_BADGES_SELECTED_MAX } from '@constants/badges'
import Factory, { cleanDatabase } from '@db/factories'
import { revokeBadge } from '@graphql/queries/revokeBadge'
import { rewardTrophyBadge } from '@graphql/queries/rewardTrophyBadge'
import { setTrophyBadgeSelected } from '@graphql/queries/setTrophyBadgeSelected'
import { setVerificationBadge } from '@graphql/queries/setVerificationBadge'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -93,27 +95,10 @@ describe('Badges', () => {
userId: 'regular-user-id',
}
const setVerificationBadgeMutation = gql`
mutation ($badgeId: ID!, $userId: ID!) {
setVerificationBadge(badgeId: $badgeId, userId: $userId) {
id
badgeVerification {
id
isDefault
}
badgeTrophies {
id
}
}
}
`
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
await expect(
mutate({ mutation: setVerificationBadgeMutation, variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: setVerificationBadge, variables })).resolves.toMatchObject({
data: { setVerificationBadge: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -128,7 +113,7 @@ describe('Badges', () => {
describe('rewards badge to user', () => {
it('throws authorization error', async () => {
await expect(
mutate({ mutation: setVerificationBadgeMutation, variables }),
mutate({ mutation: setVerificationBadge, variables }),
).resolves.toMatchObject({
data: { setVerificationBadge: null },
errors: [{ message: 'Not Authorized!' }],
@ -146,7 +131,7 @@ describe('Badges', () => {
it('rejects with an informative error message', async () => {
await expect(
mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables: { userId: 'regular-user-id', badgeId: 'non-existent-badge-id' },
}),
).resolves.toMatchObject({
@ -165,7 +150,7 @@ describe('Badges', () => {
it('rejects with a telling error message', async () => {
await expect(
mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables: { userId: 'non-existent-user-id', badgeId: 'verification_moderator' },
}),
).resolves.toMatchObject({
@ -184,7 +169,7 @@ describe('Badges', () => {
it('rejects with a telling error message', async () => {
await expect(
mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables: { userId: 'regular-user-id', badgeId: 'trophy_rhino' },
}),
).resolves.toMatchObject({
@ -210,9 +195,9 @@ describe('Badges', () => {
},
errors: undefined,
}
await expect(
mutate({ mutation: setVerificationBadgeMutation, variables }),
).resolves.toMatchObject(expected)
await expect(mutate({ mutation: setVerificationBadge, variables })).resolves.toMatchObject(
expected,
)
})
it('overrides the existing verification if a second verification badge is rewarded to the same user', async () => {
@ -233,7 +218,7 @@ describe('Badges', () => {
errors: undefined,
}
await mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables: {
userId: 'regular-user-id',
badgeId: 'verification_moderator',
@ -241,7 +226,7 @@ describe('Badges', () => {
})
await expect(
mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables: {
userId: 'regular-user-id',
badgeId: 'verification_admin',
@ -271,12 +256,12 @@ describe('Badges', () => {
},
)
await mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables,
})
await expect(
mutate({
mutation: setVerificationBadgeMutation,
mutation: setVerificationBadge,
variables: {
userId: 'regular-user-2-id',
badgeId: 'verification_moderator',
@ -812,25 +797,6 @@ describe('Badges', () => {
await regularUser.relateTo(badge, 'selected', { slot: 6 })
})
const revokeBadgeMutation = gql`
mutation ($badgeId: ID!, $userId: ID!) {
revokeBadge(badgeId: $badgeId, userId: $userId) {
id
badgeTrophies {
id
}
badgeVerification {
id
isDefault
}
badgeTrophiesSelected {
id
isDefault
}
}
}
`
describe('check test setup', () => {
it('user has one badge and has it selected', async () => {
authenticatedUser = await regularUser.toJson()
@ -912,7 +878,7 @@ describe('Badges', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
await expect(mutate({ mutation: revokeBadgeMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: revokeBadge, variables })).resolves.toMatchObject({
data: { revokeBadge: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -926,12 +892,10 @@ describe('Badges', () => {
describe('removes badge from user', () => {
it('throws authorization error', async () => {
await expect(mutate({ mutation: revokeBadgeMutation, variables })).resolves.toMatchObject(
{
data: { revokeBadge: null },
errors: [{ message: 'Not Authorized!' }],
},
)
await expect(mutate({ mutation: revokeBadge, variables })).resolves.toMatchObject({
data: { revokeBadge: null },
errors: [{ message: 'Not Authorized!' }],
})
})
})
})
@ -942,7 +906,7 @@ describe('Badges', () => {
})
it('removes a badge from user', async () => {
await expect(mutate({ mutation: revokeBadgeMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: revokeBadge, variables })).resolves.toMatchObject({
data: {
revokeBadge: {
id: 'regular-user-id',
@ -993,8 +957,8 @@ describe('Badges', () => {
})
it('does not crash when revoking multiple times', async () => {
await mutate({ mutation: revokeBadgeMutation, variables })
await expect(mutate({ mutation: revokeBadgeMutation, variables })).resolves.toMatchObject({
await mutate({ mutation: revokeBadge, variables })
await expect(mutate({ mutation: revokeBadge, variables })).resolves.toMatchObject({
data: {
revokeBadge: {
id: 'regular-user-id',
@ -1047,7 +1011,7 @@ describe('Badges', () => {
it('removes a verification from user', async () => {
await expect(
mutate({
mutation: revokeBadgeMutation,
mutation: revokeBadge,
variables: {
badgeId: 'verification_moderator',
userId: 'regular-user-id',
@ -1105,7 +1069,7 @@ describe('Badges', () => {
it('does not crash when removing verification multiple times', async () => {
await mutate({
mutation: revokeBadgeMutation,
mutation: revokeBadge,
variables: {
badgeId: 'verification_moderator',
userId: 'regular-user-id',
@ -1113,7 +1077,7 @@ describe('Badges', () => {
})
await expect(
mutate({
mutation: revokeBadgeMutation,
mutation: revokeBadge,
variables: {
badgeId: 'verification_moderator',
userId: 'regular-user-id',

View File

@ -2,9 +2,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { CreateComment } from '@graphql/queries/CreateComment'
import { DeleteComment } from '@graphql/queries/DeleteComment'
import { UpdateComment as updateComment } from '@graphql/queries/UpdateComment'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -46,17 +47,6 @@ afterEach(async () => {
await cleanDatabase()
})
const createCommentMutation = gql`
mutation ($id: ID, $postId: ID!, $content: String!) {
CreateComment(id: $id, postId: $postId, content: $content) {
id
content
author {
name
}
}
}
`
const setupPostAndComment = async () => {
commentAuthor = await Factory.build('user')
await Factory.build(
@ -95,7 +85,7 @@ describe('CreateComment', () => {
postId: 'p1',
content: "I'm not authorized to comment",
}
const { errors } = await mutate({ mutation: createCommentMutation, variables })
const { errors } = await mutate({ mutation: CreateComment, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -117,44 +107,29 @@ describe('CreateComment', () => {
})
it('creates a comment', async () => {
await expect(mutate({ mutation: createCommentMutation, variables })).resolves.toMatchObject(
{
data: { CreateComment: { content: "I'm authorized to comment" } },
errors: undefined,
},
)
await expect(mutate({ mutation: CreateComment, variables })).resolves.toMatchObject({
data: { CreateComment: { content: "I'm authorized to comment" } },
errors: undefined,
})
})
it('assigns the authenticated user as author', async () => {
await expect(mutate({ mutation: createCommentMutation, variables })).resolves.toMatchObject(
{
data: { CreateComment: { author: { name: 'Author' } } },
errors: undefined,
},
)
await expect(mutate({ mutation: CreateComment, variables })).resolves.toMatchObject({
data: { CreateComment: { author: { name: 'Author' } } },
errors: undefined,
})
})
})
})
})
describe('UpdateComment', () => {
const updateCommentMutation = gql`
mutation ($content: String!, $id: ID!) {
UpdateComment(content: $content, id: $id) {
id
content
createdAt
updatedAt
}
}
`
describe('given a post and a comment', () => {
beforeEach(setupPostAndComment)
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: updateCommentMutation, variables })
const { errors } = await mutate({ mutation: updateComment, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -166,7 +141,7 @@ describe('UpdateComment', () => {
})
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: updateCommentMutation, variables })
const { errors } = await mutate({ mutation: updateComment, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -181,7 +156,7 @@ describe('UpdateComment', () => {
data: { UpdateComment: { id: 'c456', content: 'The comment is updated' } },
errors: undefined,
}
await expect(mutate({ mutation: updateCommentMutation, variables })).resolves.toMatchObject(
await expect(mutate({ mutation: updateComment, variables })).resolves.toMatchObject(
expected,
)
})
@ -197,7 +172,7 @@ describe('UpdateComment', () => {
},
errors: undefined,
}
await expect(mutate({ mutation: updateCommentMutation, variables })).resolves.toMatchObject(
await expect(mutate({ mutation: updateComment, variables })).resolves.toMatchObject(
expected,
)
})
@ -206,7 +181,7 @@ describe('UpdateComment', () => {
newlyCreatedComment = await newlyCreatedComment.toJson()
const {
data: { UpdateComment },
} = (await mutate({ mutation: updateCommentMutation, variables })) as any // eslint-disable-line @typescript-eslint/no-explicit-any
} = (await mutate({ mutation: updateComment, variables })) as any // eslint-disable-line @typescript-eslint/no-explicit-any
expect(newlyCreatedComment.updatedAt).toBeTruthy()
expect(Date.parse(newlyCreatedComment.updatedAt)).toEqual(expect.any(Number))
expect(UpdateComment.updatedAt).toBeTruthy()
@ -220,7 +195,7 @@ describe('UpdateComment', () => {
})
it('returns null', async () => {
const { data, errors } = await mutate({ mutation: updateCommentMutation, variables })
const { data, errors } = await mutate({ mutation: updateComment, variables })
expect(data).toMatchObject({ UpdateComment: null })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
@ -230,23 +205,12 @@ describe('UpdateComment', () => {
})
describe('DeleteComment', () => {
const deleteCommentMutation = gql`
mutation ($id: ID!) {
DeleteComment(id: $id) {
id
content
contentExcerpt
deleted
}
}
`
describe('given a post and a comment', () => {
beforeEach(setupPostAndComment)
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const result = await mutate({ mutation: deleteCommentMutation, variables })
const result = await mutate({ mutation: DeleteComment, variables })
expect(result.errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -258,7 +222,7 @@ describe('DeleteComment', () => {
})
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: deleteCommentMutation, variables })
const { errors } = await mutate({ mutation: DeleteComment, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -269,7 +233,7 @@ describe('DeleteComment', () => {
})
it('marks the comment as deleted and blacks out content', async () => {
const { data } = await mutate({ mutation: deleteCommentMutation, variables })
const { data } = await mutate({ mutation: DeleteComment, variables })
const expected = {
DeleteComment: {
id: 'c456',

View File

@ -3,39 +3,17 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { createTestClient } from 'apollo-server-testing'
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getNeode, getDriver } from '@db/neo4j'
import { Donations } from '@graphql/queries/Donations'
import { UpdateDonations as updateDonations } from '@graphql/queries/UpdateDonations'
import createServer from '@src/server'
let mutate, query, authenticatedUser, variables
const instance = getNeode()
const driver = getDriver()
const updateDonationsMutation = gql`
mutation ($showDonations: Boolean, $goal: Int, $progress: Int) {
UpdateDonations(showDonations: $showDonations, goal: $goal, progress: $progress) {
id
showDonations
goal
progress
createdAt
updatedAt
}
}
`
const donationsQuery = gql`
query {
Donations {
id
showDonations
goal
progress
}
}
`
beforeAll(async () => {
await cleanDatabase()
})
@ -77,7 +55,7 @@ describe('donations', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = undefined
await expect(query({ query: donationsQuery, variables })).resolves.toMatchObject({
await expect(query({ query: Donations, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
@ -93,7 +71,7 @@ describe('donations', () => {
})
it('returns the current Donations info', async () => {
await expect(query({ query: donationsQuery, variables })).resolves.toMatchObject({
await expect(query({ query: Donations, variables })).resolves.toMatchObject({
data: { Donations: { showDonations: true, goal: 15000, progress: 7000 } },
errors: undefined,
})
@ -109,9 +87,7 @@ describe('donations', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = undefined
await expect(
mutate({ mutation: updateDonationsMutation, variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: updateDonations, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
@ -128,9 +104,7 @@ describe('donations', () => {
})
it('throws authorization error', async () => {
await expect(
mutate({ mutation: updateDonationsMutation, variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: updateDonations, variables })).resolves.toMatchObject({
data: { UpdateDonations: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -147,9 +121,7 @@ describe('donations', () => {
})
it('throws authorization error', async () => {
await expect(
mutate({ mutation: updateDonationsMutation, variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: updateDonations, variables })).resolves.toMatchObject({
data: { UpdateDonations: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -166,9 +138,7 @@ describe('donations', () => {
})
it('updates Donations info', async () => {
await expect(
mutate({ mutation: updateDonationsMutation, variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: updateDonations, variables })).resolves.toMatchObject({
data: { UpdateDonations: { showDonations: false, goal: 20000, progress: 3000 } },
errors: undefined,
})
@ -178,7 +148,7 @@ describe('donations', () => {
newlyCreatedDonations = await newlyCreatedDonations.toJson()
const {
data: { UpdateDonations },
} = await mutate({ mutation: updateDonationsMutation, variables })
} = await mutate({ mutation: updateDonations, variables })
expect(newlyCreatedDonations.updatedAt).toBeTruthy()
expect(Date.parse(newlyCreatedDonations.updatedAt)).toEqual(expect.any(Number))
expect(UpdateDonations.updatedAt).toBeTruthy()

View File

@ -4,10 +4,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { createTestClient } from 'apollo-server-testing'
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getDriver, getNeode } from '@db/neo4j'
import { AddEmailAddress } from '@graphql/queries/AddEmailAddress'
import { VerifyEmailAddress } from '@graphql/queries/VerifyEmailAddress'
import { VerifyNonce } from '@graphql/queries/VerifyNonce'
import createServer from '@src/server'
const neode = getNeode()
@ -49,15 +51,6 @@ afterEach(async () => {
})
describe('AddEmailAddress', () => {
const mutation = gql`
mutation ($email: String!) {
AddEmailAddress(email: $email) {
email
verifiedAt
createdAt
}
}
`
beforeEach(() => {
variables = { ...variables, email: 'new-email@example.org' }
})
@ -68,7 +61,7 @@ describe('AddEmailAddress', () => {
})
it('throws AuthorizationError', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: AddEmailAddress, variables })).resolves.toMatchObject({
data: { AddEmailAddress: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -87,7 +80,7 @@ describe('AddEmailAddress', () => {
})
it('throws UserInputError', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: AddEmailAddress, variables })).resolves.toMatchObject({
data: { AddEmailAddress: null },
errors: [{ message: 'must be a valid email' }],
})
@ -96,7 +89,7 @@ describe('AddEmailAddress', () => {
describe('email attribute is a valid email', () => {
it('creates a new unverified `EmailAddress` node', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: AddEmailAddress, variables })).resolves.toMatchObject({
data: {
AddEmailAddress: {
email: 'new-email@example.org',
@ -109,7 +102,7 @@ describe('AddEmailAddress', () => {
})
it('connects `UnverifiedEmailAddress` to the authenticated user', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: AddEmailAddress, variables })
const result = await neode.cypher(
`
MATCH(u:User)-[:PRIMARY_EMAIL]->(:EmailAddress {email: "user@example.org"})
@ -131,7 +124,7 @@ describe('AddEmailAddress', () => {
createdAt: '2019-09-24T14:00:01.565Z',
email: 'new-email@example.org',
})
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: AddEmailAddress, variables })).resolves.toMatchObject({
data: {
AddEmailAddress: {
email: 'new-email@example.org',
@ -146,7 +139,7 @@ describe('AddEmailAddress', () => {
describe('but if another user owns an `EmailAddress` already with that email', () => {
it('does not throw UserInputError', async () => {
await Factory.build('user', {}, { email: 'new-email@example.org' })
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: AddEmailAddress, variables })).resolves.toMatchObject({
data: {
AddEmailAddress: {
createdAt: expect.any(String),
@ -163,16 +156,6 @@ describe('AddEmailAddress', () => {
})
describe('VerifyEmailAddress', () => {
const mutation = gql`
mutation ($email: String!, $nonce: String!) {
VerifyEmailAddress(email: $email, nonce: $nonce) {
email
createdAt
verifiedAt
}
}
`
beforeEach(() => {
variables = { ...variables, email: 'to-be-verified@example.org', nonce: '12345' }
})
@ -183,7 +166,7 @@ describe('VerifyEmailAddress', () => {
})
it('throws AuthorizationError', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: VerifyEmailAddress, variables })).resolves.toMatchObject({
data: { VerifyEmailAddress: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -198,7 +181,7 @@ describe('VerifyEmailAddress', () => {
describe('if no unverified `EmailAddress` node exists', () => {
it('throws UserInputError', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: VerifyEmailAddress, variables })).resolves.toMatchObject({
data: { VerifyEmailAddress: null },
errors: [{ message: 'Invalid nonce or no email address found.' }],
})
@ -219,7 +202,7 @@ describe('VerifyEmailAddress', () => {
describe('given invalid nonce', () => {
it('throws UserInputError', async () => {
variables.nonce = 'asdfgh'
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: VerifyEmailAddress, variables })).resolves.toMatchObject({
data: { VerifyEmailAddress: null },
errors: [{ message: 'Invalid nonce or no email address found.' }],
})
@ -233,7 +216,9 @@ describe('VerifyEmailAddress', () => {
describe('but the address does not belong to the authenticated user', () => {
it('throws UserInputError', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(
mutate({ mutation: VerifyEmailAddress, variables }),
).resolves.toMatchObject({
data: { VerifyEmailAddress: null },
errors: [{ message: 'Invalid nonce or no email address found.' }],
})
@ -246,7 +231,9 @@ describe('VerifyEmailAddress', () => {
})
it('adds `verifiedAt`', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(
mutate({ mutation: VerifyEmailAddress, variables }),
).resolves.toMatchObject({
data: {
VerifyEmailAddress: {
email: 'to-be-verified@example.org',
@ -259,7 +246,7 @@ describe('VerifyEmailAddress', () => {
})
it('connects the new `EmailAddress` as PRIMARY', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: VerifyEmailAddress, variables })
const result = await neode.cypher(
`
MATCH(u:User {id: "567"})-[:PRIMARY_EMAIL]->(e:EmailAddress {email: "to-be-verified@example.org"})
@ -283,7 +270,7 @@ describe('VerifyEmailAddress', () => {
await expect(email.toJson()).resolves.toMatchObject({
email: 'user@example.org',
})
await mutate({ mutation, variables })
await mutate({ mutation: VerifyEmailAddress, variables })
result = await neode.cypher(cypherStatement, {})
email = neode.hydrateFirst(result, 'e', neode.model('EmailAddress'))
await expect(email).toBe(false)
@ -299,7 +286,7 @@ describe('VerifyEmailAddress', () => {
await expect(email.toJson()).resolves.toMatchObject({
email: 'user@example.org',
})
await mutate({ mutation, variables })
await mutate({ mutation: VerifyEmailAddress, variables })
result = await neode.cypher(cypherStatement, {})
email = neode.hydrateFirst(result, 'e', neode.model('EmailAddress'))
await expect(email).toBe(false)
@ -311,7 +298,9 @@ describe('VerifyEmailAddress', () => {
})
it('throws UserInputError because of unique constraints', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(
mutate({ mutation: VerifyEmailAddress, variables }),
).resolves.toMatchObject({
data: { VerifyEmailAddress: null },
errors: [{ message: 'A user account with this email already exists.' }],
})
@ -324,7 +313,7 @@ describe('VerifyEmailAddress', () => {
})
it('connects the new `EmailAddress` as PRIMARY', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: VerifyEmailAddress, variables })
const result = await neode.cypher(
`
MATCH(u:User {id: "567"})-[:PRIMARY_EMAIL]->(e:EmailAddress {email: "to-be-verified@example.org"})
@ -354,18 +343,12 @@ describe('VerifyNonce', () => {
})
})
const verifyNonceQuery = gql`
query ($email: String!, $nonce: String!) {
VerifyNonce(email: $email, nonce: $nonce)
}
`
it('returns true when nonce and email match', async () => {
variables = {
email: 'to-be-verified@example.org',
nonce: '12345',
}
await expect(query({ query: verifyNonceQuery, variables })).resolves.toMatchObject({
await expect(query({ query: VerifyNonce, variables })).resolves.toMatchObject({
data: { VerifyNonce: true },
})
})
@ -375,7 +358,7 @@ describe('VerifyNonce', () => {
email: 'to-be-verified@example.org',
nonce: '---',
}
await expect(query({ query: verifyNonceQuery, variables })).resolves.toMatchObject({
await expect(query({ query: VerifyNonce, variables })).resolves.toMatchObject({
data: { VerifyNonce: false },
})
})

View File

@ -5,9 +5,9 @@ import fs from 'node:fs'
import path from 'node:path'
import { createTestClient } from 'apollo-server-testing'
import gql from 'graphql-tag'
import fetch from 'node-fetch'
import { embed } from '@graphql/queries/embed'
import createServer from '@src/server'
jest.mock('node-fetch')
@ -65,25 +65,6 @@ describe('Query', () => {
context: () => {},
})
const { query } = createTestClient(server)
const embed = gql`
query ($url: String!) {
embed(url: $url) {
type
title
author
publisher
date
description
url
image
audio
video
lang
sources
html
}
}
`
return query({ query: embed, variables })
}
})

View File

@ -3,8 +3,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import Factory, { cleanDatabase } from '@db/factories'
import { createPostMutation } from '@graphql/queries/createPostMutation'
import { filterPosts } from '@graphql/queries/filterPosts'
import { CreatePost } from '@graphql/queries/CreatePost'
import { Post } from '@graphql/queries/Post'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -45,7 +45,7 @@ describe('Filter Posts', () => {
})
authenticatedUser = await user.toJson()
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'a1',
title: 'I am an article',
@ -53,7 +53,7 @@ describe('Filter Posts', () => {
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'a2',
title: 'I am anonther article',
@ -61,7 +61,7 @@ describe('Filter Posts', () => {
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'e1',
title: 'Illegaler Kindergeburtstag',
@ -74,7 +74,7 @@ describe('Filter Posts', () => {
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'e2',
title: 'Räuber-Treffen',
@ -92,7 +92,7 @@ describe('Filter Posts', () => {
it('finds all posts', async () => {
const {
data: { Post: result },
} = (await query({ query: filterPosts() })) as any
} = (await query({ query: Post })) as any
expect(result).toHaveLength(4)
expect(result).toEqual(
expect.arrayContaining([
@ -110,7 +110,7 @@ describe('Filter Posts', () => {
const {
data: { Post: result },
} = (await query({
query: filterPosts(),
query: Post,
variables: { filter: { postType_in: ['Article'] } },
})) as any
expect(result).toHaveLength(2)
@ -128,7 +128,7 @@ describe('Filter Posts', () => {
const {
data: { Post: result },
} = (await query({
query: filterPosts(),
query: Post,
variables: { filter: { postType_in: ['Event'] } },
})) as any
expect(result).toHaveLength(2)
@ -146,7 +146,7 @@ describe('Filter Posts', () => {
const {
data: { Post: result },
} = (await query({
query: filterPosts(),
query: Post,
variables: { filter: { postType_in: ['Article', 'Event'] } },
})) as any
expect(result).toHaveLength(4)
@ -166,7 +166,7 @@ describe('Filter Posts', () => {
const {
data: { Post: result },
} = (await query({
query: filterPosts(),
query: Post,
variables: { filter: { postType_in: ['Event'] }, orderBy: ['eventStart_desc'] },
})) as any
expect(result).toHaveLength(2)
@ -190,7 +190,7 @@ describe('Filter Posts', () => {
const {
data: { Post: result },
} = (await query({
query: filterPosts(),
query: Post,
variables: { filter: { postType_in: ['Event'] }, orderBy: ['eventStart_asc'] },
})) as any
expect(result).toHaveLength(2)
@ -214,7 +214,7 @@ describe('Filter Posts', () => {
const {
data: { Post: result },
} = (await query({
query: filterPosts(),
query: Post,
variables: {
filter: {
postType_in: ['Event'],

View File

@ -7,6 +7,8 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getDriver, getNeode } from '@db/neo4j'
import { followUser } from '@graphql/queries/followUser'
import { unfollowUser } from '@graphql/queries/unfollowUser'
import createServer from '@src/server'
const driver = getDriver()
@ -20,30 +22,6 @@ let user1
let user2
let variables
const mutationFollowUser = gql`
mutation ($id: ID!) {
followUser(id: $id) {
name
followedBy {
id
name
}
followedByCurrentUser
}
}
`
const mutationUnfollowUser = gql`
mutation ($id: ID!) {
unfollowUser(id: $id) {
name
followedBy {
id
name
}
followedByCurrentUser
}
}
`
const userQuery = gql`
query ($id: ID) {
User(id: $id) {
@ -119,7 +97,7 @@ describe('follow', () => {
authenticatedUser = null
await expect(
mutate({
mutation: mutationFollowUser,
mutation: followUser,
variables,
}),
).resolves.toMatchObject({
@ -137,7 +115,7 @@ describe('follow', () => {
}
await expect(
mutate({
mutation: mutationFollowUser,
mutation: followUser,
variables,
}),
).resolves.toMatchObject({
@ -148,7 +126,7 @@ describe('follow', () => {
test('adds `createdAt` to `FOLLOW` relationship', async () => {
await mutate({
mutation: mutationFollowUser,
mutation: followUser,
variables,
})
const relation = await neode.cypher(
@ -163,7 +141,7 @@ describe('follow', () => {
test('I can`t follow myself', async () => {
variables.id = user1.id
await expect(mutate({ mutation: mutationFollowUser, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: followUser, variables })).resolves.toMatchObject({
data: { followUser: null },
errors: undefined,
})
@ -189,13 +167,13 @@ describe('follow', () => {
describe('unfollow user', () => {
beforeEach(async () => {
variables = { id: user2.id }
await mutate({ mutation: mutationFollowUser, variables })
await mutate({ mutation: followUser, variables })
})
describe('unauthenticated follow', () => {
test('throws authorization error', async () => {
authenticatedUser = null
await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: unfollowUser, variables })).resolves.toMatchObject({
data: { unfollowUser: null },
errors: [{ message: 'Not Authorized!' }],
})
@ -208,7 +186,7 @@ describe('follow', () => {
followedBy: [],
followedByCurrentUser: false,
}
await expect(mutate({ mutation: mutationUnfollowUser, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: unfollowUser, variables })).resolves.toMatchObject({
data: { unfollowUser: expectedUser },
errors: undefined,
})

View File

@ -4,14 +4,14 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import Factory, { cleanDatabase } from '@db/factories'
import { changeGroupMemberRoleMutation } from '@graphql/queries/changeGroupMemberRoleMutation'
import { createGroupMutation } from '@graphql/queries/createGroupMutation'
import { ChangeGroupMemberRole } from '@graphql/queries/ChangeGroupMemberRole'
import { CreateGroup } from '@graphql/queries/CreateGroup'
import { Group as groupQuery } from '@graphql/queries/Group'
import { GroupMembers as groupMembersQuery } from '@graphql/queries/GroupMembers'
import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
import { leaveGroupMutation } from '@graphql/queries/leaveGroupMutation'
import { removeUserFromGroupMutation } from '@graphql/queries/removeUserFromGroupMutation'
import { updateGroupMutation } from '@graphql/queries/updateGroupMutation'
import { JoinGroup } from '@graphql/queries/JoinGroup'
import { LeaveGroup } from '@graphql/queries/LeaveGroup'
import { RemoveUserFromGroup } from '@graphql/queries/RemoveUserFromGroup'
import { UpdateGroup } from '@graphql/queries/UpdateGroup'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -156,7 +156,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
// public-group
authenticatedUser = await usualMemberUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'The Best Group',
@ -168,14 +168,14 @@ const seedComplexScenarioAndClearAuthentication = async () => {
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'owner-of-closed-group',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'owner-of-hidden-group',
@ -184,7 +184,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
// closed-group
authenticatedUser = await ownerMemberUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'Uninteresting Group',
@ -197,7 +197,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
})
// hidden-group
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Investigative Journalism Group',
@ -210,7 +210,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
})
// 'JoinGroup' mutation does not work in hidden groups so we join them by 'ChangeGroupMemberRole' through the owner
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'usual-member-user',
@ -219,7 +219,7 @@ const seedComplexScenarioAndClearAuthentication = async () => {
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'admin-member-user',
@ -274,7 +274,7 @@ describe('in mode', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: createGroupMutation(), variables })
const { errors } = await mutate({ mutation: CreateGroup, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -285,9 +285,7 @@ describe('in mode', () => {
})
it('creates a group', async () => {
await expect(
mutate({ mutation: createGroupMutation(), variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: CreateGroup, variables })).resolves.toMatchObject({
data: {
CreateGroup: {
name: 'The Best Group',
@ -310,9 +308,7 @@ describe('in mode', () => {
})
it('assigns the authenticated user as owner', async () => {
await expect(
mutate({ mutation: createGroupMutation(), variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: CreateGroup, variables })).resolves.toMatchObject({
data: {
CreateGroup: {
name: 'The Best Group',
@ -324,9 +320,7 @@ describe('in mode', () => {
})
it('has "disabled" and "deleted" default to "false"', async () => {
await expect(
mutate({ mutation: createGroupMutation(), variables }),
).resolves.toMatchObject({
await expect(mutate({ mutation: CreateGroup, variables })).resolves.toMatchObject({
data: { CreateGroup: { disabled: false, deleted: false } },
})
})
@ -336,7 +330,7 @@ describe('in mode', () => {
describe('less then 3 chars', () => {
it('throws error: "Description too short!"', async () => {
const { errors } = await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
...variables,
description:
@ -355,7 +349,7 @@ describe('in mode', () => {
it('has new categories', async () => {
await expect(
mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
...variables,
categoryIds: ['cat4', 'cat27'],
@ -380,7 +374,7 @@ describe('in mode', () => {
describe('by "categoryIds: null"', () => {
it('throws error: "Too few categories!"', async () => {
const { errors } = await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: { ...variables, categoryIds: null },
})
expect(errors?.[0]).toHaveProperty('message', 'Too few categories!')
@ -390,7 +384,7 @@ describe('in mode', () => {
describe('by "categoryIds: []"', () => {
it('throws error: "Too few categories!"', async () => {
const { errors } = await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: { ...variables, categoryIds: [] },
})
expect(errors?.[0]).toHaveProperty('message', 'Too few categories!')
@ -401,7 +395,7 @@ describe('in mode', () => {
describe('four', () => {
it('throws error: "Too many categories!"', async () => {
const { errors } = await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: { ...variables, categoryIds: ['cat9', 'cat4', 'cat15', 'cat27'] },
})
expect(errors?.[0]).toHaveProperty('message', 'Too many categories!')
@ -458,7 +452,7 @@ describe('in mode', () => {
)
authenticatedUser = await otherUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'others-group',
name: 'Uninteresting Group',
@ -471,7 +465,7 @@ describe('in mode', () => {
})
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Investigative Journalism Group',
@ -483,7 +477,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'second-hidden-group',
name: 'Second Investigative Journalism Group',
@ -495,7 +489,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'second-hidden-group',
userId: 'current-user',
@ -503,7 +497,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'third-hidden-group',
name: 'Third Investigative Journalism Group',
@ -515,7 +509,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'third-hidden-group',
userId: 'current-user',
@ -524,7 +518,7 @@ describe('in mode', () => {
})
authenticatedUser = await user.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'my-group',
name: 'The Best Group',
@ -802,7 +796,7 @@ describe('in mode', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'not-existing-group',
userId: 'current-user',
@ -844,7 +838,7 @@ describe('in mode', () => {
// public-group
authenticatedUser = await ownerOfClosedGroupUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'Uninteresting Group',
@ -857,7 +851,7 @@ describe('in mode', () => {
})
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Investigative Journalism Group',
@ -870,7 +864,7 @@ describe('in mode', () => {
})
authenticatedUser = await user.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'The Best Group',
@ -888,7 +882,7 @@ describe('in mode', () => {
it('has "usual" as membership role', async () => {
await expect(
mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'owner-of-closed-group',
@ -911,7 +905,7 @@ describe('in mode', () => {
it('has still "owner" as membership role', async () => {
await expect(
mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'current-user',
@ -936,7 +930,7 @@ describe('in mode', () => {
it('has "pending" as membership role', async () => {
await expect(
mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'current-user',
@ -959,7 +953,7 @@ describe('in mode', () => {
it('has still "owner" as membership role', async () => {
await expect(
mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'owner-of-closed-group',
@ -983,7 +977,7 @@ describe('in mode', () => {
describe('joined by "owner-of-closed-group"', () => {
it('throws authorization error', async () => {
const { errors } = await query({
query: joinGroupMutation(),
query: JoinGroup,
variables: {
groupId: 'hidden-group',
userId: 'owner-of-closed-group',
@ -998,7 +992,7 @@ describe('in mode', () => {
it('has still "owner" as membership role', async () => {
await expect(
mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'hidden-group',
userId: 'owner-of-hidden-group',
@ -1095,7 +1089,7 @@ describe('in mode', () => {
// public-group
authenticatedUser = await user.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'The Best Group',
@ -1107,14 +1101,14 @@ describe('in mode', () => {
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'owner-of-closed-group',
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'owner-of-hidden-group',
@ -1123,7 +1117,7 @@ describe('in mode', () => {
// closed-group
authenticatedUser = await ownerOfClosedGroupUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'Uninteresting Group',
@ -1135,14 +1129,14 @@ describe('in mode', () => {
},
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'current-user',
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'owner-of-hidden-group',
@ -1152,7 +1146,7 @@ describe('in mode', () => {
// hidden-group
authenticatedUser = await ownerOfHiddenGroupUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Investigative Journalism Group',
@ -1165,7 +1159,7 @@ describe('in mode', () => {
})
// 'JoinGroup' mutation does not work in hidden groups so we join them by 'ChangeGroupMemberRole' through the owner
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'pending-user',
@ -1173,7 +1167,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'current-user',
@ -1181,7 +1175,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'owner-of-closed-group',
@ -1556,7 +1550,7 @@ describe('in mode', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'not-existing-group',
userId: 'current-user',
@ -1600,7 +1594,7 @@ describe('in mode', () => {
it('has role usual', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -1638,7 +1632,7 @@ describe('in mode', () => {
it('has role admin', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -1673,7 +1667,7 @@ describe('in mode', () => {
it('has role owner', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -1715,7 +1709,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1741,7 +1735,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1759,7 +1753,7 @@ describe('in mode', () => {
it('has role owner still', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -1790,7 +1784,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1813,7 +1807,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1836,7 +1830,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1869,7 +1863,7 @@ describe('in mode', () => {
it('has role owner', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -1894,7 +1888,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1917,7 +1911,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1934,7 +1928,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1957,7 +1951,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1974,7 +1968,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -1997,7 +1991,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2014,7 +2008,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2047,7 +2041,7 @@ describe('in mode', () => {
it('has role admin', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -2073,7 +2067,7 @@ describe('in mode', () => {
it('has role usual again', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -2104,7 +2098,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2121,7 +2115,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2144,7 +2138,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2161,7 +2155,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2184,7 +2178,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2201,7 +2195,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2234,7 +2228,7 @@ describe('in mode', () => {
it('has role usual', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -2260,7 +2254,7 @@ describe('in mode', () => {
it('has role usual again', async () => {
await expect(
mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
}),
).resolves.toMatchObject({
@ -2291,7 +2285,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2314,7 +2308,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2337,7 +2331,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables,
})
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2356,7 +2350,7 @@ describe('in mode', () => {
// closed-group
authenticatedUser = await ownerMemberUser.toJson()
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'pending-member-user',
@ -2364,7 +2358,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'usual-member-user',
@ -2372,7 +2366,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'admin-member-user',
@ -2380,7 +2374,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'second-owner-member-user',
@ -2398,7 +2392,7 @@ describe('in mode', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
groupId: 'not-existing-group',
userId: 'current-user',
@ -2437,7 +2431,7 @@ describe('in mode', () => {
authenticatedUser = await pendingMemberUser.toJson()
await expect(
mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'pending-member-user',
@ -2464,7 +2458,7 @@ describe('in mode', () => {
authenticatedUser = await usualMemberUser.toJson()
await expect(
mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'usual-member-user',
@ -2491,7 +2485,7 @@ describe('in mode', () => {
authenticatedUser = await adminMemberUser.toJson()
await expect(
mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'admin-member-user',
@ -2515,7 +2509,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await ownerMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'owner-member-user',
@ -2529,7 +2523,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await secondOwnerMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'second-owner-member-user',
@ -2543,7 +2537,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await noMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'none-member-user',
@ -2557,7 +2551,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await ownerMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'usual-member-user',
@ -2571,7 +2565,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await usualMemberUser.toJson()
const { errors } = await mutate({
mutation: leaveGroupMutation(),
mutation: LeaveGroup,
variables: {
...variables,
userId: 'admin-member-user',
@ -2597,7 +2591,7 @@ describe('in mode', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
slug: 'my-best-group',
@ -2635,7 +2629,7 @@ describe('in mode', () => {
)
authenticatedUser = await noMemberUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'others-group',
name: 'Uninteresting Group',
@ -2648,7 +2642,7 @@ describe('in mode', () => {
})
authenticatedUser = await user.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'my-group',
name: 'The Best Group',
@ -2661,7 +2655,7 @@ describe('in mode', () => {
},
})
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'my-group',
userId: 'usual-member-user',
@ -2680,7 +2674,7 @@ describe('in mode', () => {
it('has updated the settings', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
name: 'The New Group For Our Country',
@ -2715,7 +2709,7 @@ describe('in mode', () => {
it('has left locaton unchanged as "Berlin"', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
},
@ -2742,7 +2736,7 @@ describe('in mode', () => {
it('has updated the location to unset location', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
locationName: null,
@ -2766,7 +2760,7 @@ describe('in mode', () => {
it('has updated the location to "Paris"', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
locationName: 'Paris, France',
@ -2794,7 +2788,7 @@ describe('in mode', () => {
it('has updated the location to "Hamburg"', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
locationName: 'Hamburg, Germany',
@ -2822,7 +2816,7 @@ describe('in mode', () => {
it('has updated the location to unset', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
locationName: '', // empty string '' sets it to null
@ -2848,7 +2842,7 @@ describe('in mode', () => {
describe('less then 3 chars', () => {
it('throws error: "Description too short!"', async () => {
const { errors } = await mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
description:
@ -2867,7 +2861,7 @@ describe('in mode', () => {
it('has new categories', async () => {
await expect(
mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
categoryIds: ['cat4', 'cat27'],
@ -2893,7 +2887,7 @@ describe('in mode', () => {
describe('by "categoryIds: []"', () => {
it('throws error: "Too few categories!"', async () => {
const { errors } = await mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
categoryIds: [],
@ -2907,7 +2901,7 @@ describe('in mode', () => {
describe('four', () => {
it('throws error: "Too many categories!"', async () => {
const { errors } = await mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
categoryIds: ['cat9', 'cat4', 'cat15', 'cat27'],
@ -2923,7 +2917,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await usualMemberUser.toJson()
const { errors } = await mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
name: 'The New Group For Our Country',
@ -2941,7 +2935,7 @@ describe('in mode', () => {
it('throws authorization error', async () => {
authenticatedUser = await noMemberUser.toJson()
const { errors } = await mutate({
mutation: updateGroupMutation(),
mutation: UpdateGroup,
variables: {
id: 'my-group',
name: 'The New Group For Our Country',
@ -2972,7 +2966,7 @@ describe('in mode', () => {
it('throws an error', async () => {
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'usual-member-user',
@ -2994,7 +2988,7 @@ describe('in mode', () => {
authenticatedUser = await usualMemberUser.toJson()
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'admin-member-user',
@ -3018,7 +3012,7 @@ describe('in mode', () => {
it('removes the user from the group', async () => {
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'usual-member-user',
@ -3038,7 +3032,7 @@ describe('in mode', () => {
it('cannot remove self', async () => {
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'owner-member-user',
@ -3058,7 +3052,7 @@ describe('in mode', () => {
beforeEach(async () => {
authenticatedUser = await adminMemberUser.toJson()
await mutate({
mutation: changeGroupMemberRoleMutation(),
mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'usual-member-user',
@ -3071,7 +3065,7 @@ describe('in mode', () => {
authenticatedUser = await usualMemberUser.toJson()
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'admin-member-user',
@ -3090,7 +3084,7 @@ describe('in mode', () => {
it('removes the user from the group', async () => {
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'usual-member-user',
@ -3110,7 +3104,7 @@ describe('in mode', () => {
it('cannot remove self', async () => {
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'admin-member-user',
@ -3128,7 +3122,7 @@ describe('in mode', () => {
it('cannot remove owner', async () => {
await expect(
mutate({
mutation: removeUserFromGroupMutation(),
mutation: RemoveUserFromGroup,
variables: {
groupId: 'hidden-group',
userId: 'owner-member-user',

View File

@ -3,14 +3,14 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Factory, { cleanDatabase } from '@db/factories'
import { createGroupMutation } from '@graphql/queries/createGroupMutation'
import { CreateGroup } from '@graphql/queries/CreateGroup'
import { currentUser } from '@graphql/queries/currentUser'
import { generateGroupInviteCode } from '@graphql/queries/generateGroupInviteCode'
import { generatePersonalInviteCode } from '@graphql/queries/generatePersonalInviteCode'
import { Group } from '@graphql/queries/Group'
import { GroupMembers } from '@graphql/queries/GroupMembers'
import { invalidateInviteCode } from '@graphql/queries/invalidateInviteCode'
import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
import { JoinGroup } from '@graphql/queries/JoinGroup'
import { redeemInviteCode } from '@graphql/queries/redeemInviteCode'
import {
authenticatedValidateInviteCode,
@ -59,7 +59,7 @@ describe('validateInviteCode', () => {
authenticatedUser = await invitingUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Hidden Group',
@ -73,7 +73,7 @@ describe('validateInviteCode', () => {
})
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'Public Group',
@ -524,7 +524,7 @@ describe('generateGroupInviteCode', () => {
authenticatedUser = await invitingUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Hidden Group',
@ -538,7 +538,7 @@ describe('generateGroupInviteCode', () => {
})
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'Public Group',
@ -551,7 +551,7 @@ describe('generateGroupInviteCode', () => {
})
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'Closed Group',
@ -564,7 +564,7 @@ describe('generateGroupInviteCode', () => {
})
await mutate({
mutation: joinGroupMutation(),
mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'pending-member-user',
@ -920,7 +920,7 @@ describe('redeemInviteCode', () => {
authenticatedUser = await invitingUser.toJson()
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'Hidden Group',
@ -934,7 +934,7 @@ describe('redeemInviteCode', () => {
})
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'Public Group',

View File

@ -10,10 +10,10 @@ import { Upload } from 'graphql-upload/public/index'
import pubsubContext from '@context/pubsub'
import Factory, { cleanDatabase } from '@db/factories'
import { CreateMessage } from '@graphql/queries/CreateMessage'
import { createRoomMutation } from '@graphql/queries/createRoomMutation'
import { CreateRoom } from '@graphql/queries/CreateRoom'
import { MarkMessagesAsSeen } from '@graphql/queries/MarkMessagesAsSeen'
import { Message } from '@graphql/queries/Message'
import { roomQuery } from '@graphql/queries/roomQuery'
import { Room } from '@graphql/queries/Room'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -123,7 +123,7 @@ describe('Message', () => {
beforeEach(async () => {
authenticatedUser = await chattingUser.toJson()
const room = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: 'other-chatting-user',
},
@ -171,7 +171,7 @@ describe('Message', () => {
describe('room is updated as well', () => {
it('has last message set', async () => {
const result = await query({ query: roomQuery() })
const result = await query({ query: Room })
await expect(result).toMatchObject({
errors: undefined,
data: {
@ -201,7 +201,7 @@ describe('Message', () => {
describe('unread count for other user', () => {
it('has unread count = 1', async () => {
authenticatedUser = await otherChattingUser.toJson()
await expect(query({ query: roomQuery() })).resolves.toMatchObject({
await expect(query({ query: Room })).resolves.toMatchObject({
errors: undefined,
data: {
Room: [
@ -405,7 +405,7 @@ describe('Message', () => {
beforeEach(async () => {
authenticatedUser = await chattingUser.toJson()
const room = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: 'other-chatting-user',
},
@ -637,7 +637,7 @@ describe('Message', () => {
beforeEach(async () => {
authenticatedUser = await chattingUser.toJson()
const room = await mutate({
mutation: createRoomMutation(),
mutation: CreateRoom,
variables: {
userId: 'other-chatting-user',
},

View File

@ -3,10 +3,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { createTestClient } from 'apollo-server-testing'
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getNeode, getDriver } from '@db/neo4j'
import { review } from '@graphql/queries/review'
import createServer from '@src/server'
const neode = getNeode()
@ -20,42 +20,6 @@ let mutate,
nonModerator,
closeReportVariables
const reviewMutation = gql`
mutation ($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
review(resourceId: $resourceId, disable: $disable, closed: $closed) {
createdAt
updatedAt
resource {
__typename
... on User {
id
disabled
}
... on Post {
id
disabled
}
... on Comment {
id
disabled
}
}
report {
id
createdAt
updatedAt
closed
reviewed {
createdAt
moderator {
id
}
}
}
}
}
`
describe('moderate resources', () => {
beforeAll(async () => {
await cleanDatabase()
@ -124,7 +88,7 @@ describe('moderate resources', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
@ -138,7 +102,7 @@ describe('moderate resources', () => {
it('non-moderator receives an authorization error', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
@ -169,7 +133,7 @@ describe('moderate resources', () => {
it('report can be closed without disabling resource', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: closeReportVariables }),
mutate({ mutation: review, variables: closeReportVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -184,11 +148,11 @@ describe('moderate resources', () => {
it('creates only one review for multiple reviews by the same moderator on same resource', async () => {
await Promise.all([
mutate({
mutation: reviewMutation,
mutation: review,
variables: { ...disableVariables, resourceId: 'should-i-be-disabled' },
}),
mutate({
mutation: reviewMutation,
mutation: review,
variables: { ...enableVariables, resourceId: 'should-i-be-disabled' },
}),
])
@ -201,11 +165,11 @@ describe('moderate resources', () => {
it('updates the updatedAt attribute', async () => {
const [firstReview, secondReview] = await Promise.all([
mutate({
mutation: reviewMutation,
mutation: review,
variables: { ...disableVariables, resourceId: 'should-i-be-disabled' },
}),
mutate({
mutation: reviewMutation,
mutation: review,
variables: { ...enableVariables, resourceId: 'should-i-be-disabled' },
}),
])
@ -222,7 +186,7 @@ describe('moderate resources', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
@ -236,7 +200,7 @@ describe('moderate resources', () => {
it('non-moderator receives an authorization error', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
@ -270,7 +234,7 @@ describe('moderate resources', () => {
it('returns disabled resource id', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'Comment', id: 'comment-id' } } },
errors: undefined,
@ -279,7 +243,7 @@ describe('moderate resources', () => {
it('returns .reviewed', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -298,7 +262,7 @@ describe('moderate resources', () => {
it('updates .disabled on comment', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: {
review: { resource: { __typename: 'Comment', id: 'comment-id', disabled: true } },
@ -313,7 +277,7 @@ describe('moderate resources', () => {
closed: true,
}
await expect(
mutate({ mutation: reviewMutation, variables: closeReportVariables }),
mutate({ mutation: review, variables: closeReportVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -348,7 +312,7 @@ describe('moderate resources', () => {
it('returns disabled resource id', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -361,7 +325,7 @@ describe('moderate resources', () => {
it('returns .reviewed', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -380,7 +344,7 @@ describe('moderate resources', () => {
it('updates .disabled on post', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'Post', id: 'post-id', disabled: true } } },
errors: undefined,
@ -393,7 +357,7 @@ describe('moderate resources', () => {
closed: true,
}
await expect(
mutate({ mutation: reviewMutation, variables: closeReportVariables }),
mutate({ mutation: review, variables: closeReportVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -428,7 +392,7 @@ describe('moderate resources', () => {
it('returns disabled resource id', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'User', id: 'user-id' } } },
errors: undefined,
@ -437,7 +401,7 @@ describe('moderate resources', () => {
it('returns .reviewed', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -456,7 +420,7 @@ describe('moderate resources', () => {
it('updates .disabled on user', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: disableVariables }),
mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'User', id: 'user-id', disabled: true } } },
errors: undefined,
@ -469,7 +433,7 @@ describe('moderate resources', () => {
closed: true,
}
await expect(
mutate({ mutation: reviewMutation, variables: closeReportVariables }),
mutate({ mutation: review, variables: closeReportVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -492,7 +456,7 @@ describe('moderate resources', () => {
resourceId: 'post-id',
}
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
@ -511,7 +475,7 @@ describe('moderate resources', () => {
resourceId: 'post-id',
}
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
@ -552,7 +516,7 @@ describe('moderate resources', () => {
it('returns enabled resource id', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'Comment', id: 'comment-id' } } },
})
@ -560,7 +524,7 @@ describe('moderate resources', () => {
it('returns .reviewed', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -578,7 +542,7 @@ describe('moderate resources', () => {
it('updates .disabled on comment', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: {
review: { resource: { __typename: 'Comment', id: 'comment-id', disabled: false } },
@ -617,7 +581,7 @@ describe('moderate resources', () => {
it('returns enabled resource id', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'Post', id: 'post-id' } } },
})
@ -625,7 +589,7 @@ describe('moderate resources', () => {
it('returns .reviewed', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -643,7 +607,7 @@ describe('moderate resources', () => {
it('updates .disabled on post', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: {
review: { resource: { __typename: 'Post', id: 'post-id', disabled: false } },
@ -681,7 +645,7 @@ describe('moderate resources', () => {
it('returns enabled resource id', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: { review: { resource: { __typename: 'User', id: 'user-id' } } },
})
@ -689,7 +653,7 @@ describe('moderate resources', () => {
it('returns .reviewed', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: {
review: {
@ -707,7 +671,7 @@ describe('moderate resources', () => {
it('updates .disabled on user', async () => {
await expect(
mutate({ mutation: reviewMutation, variables: enableVariables }),
mutate({ mutation: review, variables: enableVariables }),
).resolves.toMatchObject({
data: {
review: { resource: { __typename: 'User', id: 'user-id', disabled: false } },

View File

@ -3,12 +3,11 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { markAllAsReadMutation } from '@graphql/queries/markAllAsReadMutation'
import { markAsReadMutation } from '@graphql/queries/markAsReadMutation'
import { notificationQuery } from '@graphql/queries/notificationQuery'
import { DeletePost } from '@graphql/queries/DeletePost'
import { markAllAsRead } from '@graphql/queries/markAllAsRead'
import { markAsRead } from '@graphql/queries/markAsRead'
import { notifications } from '@graphql/queries/notifications'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -154,7 +153,7 @@ describe('given some notifications', () => {
describe('notifications', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await query({ query: notificationQuery() })
const { errors } = await query({ query: notifications })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -201,7 +200,7 @@ describe('given some notifications', () => {
},
]
await expect(query({ query: notificationQuery(), variables })).resolves.toMatchObject({
await expect(query({ query: notifications, variables })).resolves.toMatchObject({
data: {
notifications: expect.arrayContaining(expected),
},
@ -235,7 +234,7 @@ describe('given some notifications', () => {
},
})
const response = await query({
query: notificationQuery(),
query: notifications,
variables: { ...variables, read: false },
})
await expect(response).toMatchObject(expected)
@ -245,16 +244,8 @@ describe('given some notifications', () => {
describe('if a resource gets deleted', () => {
const deletePostAction = async () => {
authenticatedUser = await author.toJson()
const deletePostMutation = gql`
mutation ($id: ID!) {
DeletePost(id: $id) {
id
deleted
}
}
`
await expect(
mutate({ mutation: deletePostMutation, variables: { id: 'p3' } }),
mutate({ mutation: DeletePost, variables: { id: 'p3' } }),
).resolves.toMatchObject({
data: { DeletePost: { id: 'p3', deleted: true } },
errors: undefined,
@ -264,14 +255,14 @@ describe('given some notifications', () => {
it('reduces notifications list', async () => {
await expect(
query({ query: notificationQuery(), variables: { ...variables, read: false } }),
query({ query: notifications, variables: { ...variables, read: false } }),
).resolves.toMatchObject({
data: { notifications: [expect.any(Object), expect.any(Object)] },
errors: undefined,
})
await deletePostAction()
await expect(
query({ query: notificationQuery(), variables: { ...variables, read: false } }),
query({ query: notifications, variables: { ...variables, read: false } }),
).resolves.toMatchObject({ data: { notifications: [] }, errors: undefined })
})
})
@ -283,7 +274,7 @@ describe('given some notifications', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const result = await mutate({
mutation: markAsReadMutation(),
mutation: markAsRead,
variables: { ...variables, id: 'p1' },
})
expect(result.errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -304,7 +295,7 @@ describe('given some notifications', () => {
})
it('returns null', async () => {
const response = await mutate({ mutation: markAsReadMutation(), variables })
const response = await mutate({ mutation: markAsRead, variables })
expect(response.data?.markAsRead).toEqual(null)
expect(response.errors).toBeUndefined()
})
@ -320,7 +311,7 @@ describe('given some notifications', () => {
})
it('updates `read` attribute and returns NOTIFIED relationship', async () => {
const { data } = await mutate({ mutation: markAsReadMutation(), variables })
const { data } = await mutate({ mutation: markAsRead, variables })
expect(data).toEqual({
markAsRead: {
from: {
@ -341,7 +332,7 @@ describe('given some notifications', () => {
}
})
it('returns null', async () => {
const response = await mutate({ mutation: markAsReadMutation(), variables })
const response = await mutate({ mutation: markAsRead, variables })
expect(response.data?.markAsRead).toEqual(null)
expect(response.errors).toBeUndefined()
})
@ -357,7 +348,7 @@ describe('given some notifications', () => {
})
it('updates `read` attribute and returns NOTIFIED relationship', async () => {
const { data } = await mutate({ mutation: markAsReadMutation(), variables })
const { data } = await mutate({ mutation: markAsRead, variables })
expect(data).toEqual({
markAsRead: {
from: {
@ -378,7 +369,7 @@ describe('given some notifications', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const result = await mutate({
mutation: markAllAsReadMutation(),
mutation: markAllAsRead,
})
expect(result.errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
@ -397,7 +388,7 @@ describe('given some notifications', () => {
})
it('returns all as read', async () => {
const response = await mutate({ mutation: markAllAsReadMutation(), variables })
const response = await mutate({ mutation: markAllAsRead, variables })
expect(response.data?.markAllAsRead).toEqual(
expect.arrayContaining([
{

View File

@ -4,7 +4,8 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { createPostMutation } from '@graphql/queries/createPostMutation'
import { CreatePost } from '@graphql/queries/CreatePost'
import { toggleObservePost } from '@graphql/queries/toggleObservePost'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@ -73,7 +74,7 @@ describe('observing posts', () => {
it('has the author of the post observing the post', async () => {
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post the author should observe',
@ -158,20 +159,11 @@ describe('observing posts', () => {
authenticatedUser = await otherUser.toJson()
})
const toggleObservePostMutation = gql`
mutation ($id: ID!, $value: Boolean!) {
toggleObservePost(id: $id, value: $value) {
isObservedByMe
observingUsersCount
}
}
`
describe('switch off observation', () => {
it('does not observe the post anymore', async () => {
await expect(
mutate({
mutation: toggleObservePostMutation,
mutation: toggleObservePost,
variables: {
id: 'p2',
value: false,
@ -232,7 +224,7 @@ describe('observing posts', () => {
it('does observe the post again', async () => {
await expect(
mutate({
mutation: toggleObservePostMutation,
mutation: toggleObservePost,
variables: {
id: 'p2',
value: true,

View File

@ -1,10 +1,11 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import gql from 'graphql-tag'
import registrationConstants from '@constants/registrationBranded'
import Factory, { cleanDatabase } from '@db/factories'
import { login } from '@graphql/queries/login'
import { requestPasswordReset } from '@graphql/queries/requestPasswordReset'
import { resetPassword } from '@graphql/queries/resetPassword'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
@ -64,25 +65,21 @@ describe('passwordReset', () => {
})
describe('requestPasswordReset', () => {
const mutation = gql`
mutation ($email: String!, $locale: String!) {
requestPasswordReset(email: $email, locale: $locale)
}
`
describe('with invalid email', () => {
beforeEach(() => {
variables = { ...variables, email: 'non-existent@example.org', locale: 'de' }
})
it('resolves anyways', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(
mutate({ mutation: requestPasswordReset, variables }),
).resolves.toMatchObject({
data: { requestPasswordReset: true },
})
})
it('creates no node', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: requestPasswordReset, variables })
const resets = await getAllPasswordResets()
expect(resets).toHaveLength(0)
})
@ -94,7 +91,9 @@ describe('passwordReset', () => {
})
it('resolves', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(
mutate({ mutation: requestPasswordReset, variables }),
).resolves.toMatchObject({
data: { requestPasswordReset: true },
})
})
@ -102,13 +101,13 @@ describe('passwordReset', () => {
it('creates node with label `PasswordReset`', async () => {
let resets = await getAllPasswordResets()
expect(resets).toHaveLength(0)
await mutate({ mutation, variables })
await mutate({ mutation: requestPasswordReset, variables })
resets = await getAllPasswordResets()
expect(resets).toHaveLength(1)
})
it('creates a reset nonce', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: requestPasswordReset, variables })
const resets = await getAllPasswordResets()
const [reset] = resets
const { nonce } = reset.properties
@ -125,12 +124,6 @@ describe('resetPassword', () => {
const { email = 'user@example.org', issuedAt = new Date(), nonce = '12345' } = options
await createPasswordReset({ driver: database.driver, email, issuedAt, nonce })
}
const mutation = gql`
mutation ($nonce: String!, $email: String!, $newPassword: String!) {
resetPassword(nonce: $nonce, email: $email, newPassword: $newPassword)
}
`
beforeEach(() => {
variables = { ...variables, newPassword: 'supersecret' }
})
@ -153,7 +146,7 @@ describe('resetPassword', () => {
it('resolves to false', async () => {
await setup()
variables = { ...variables, email: 'non-existent@example.org', nonce: '12345' }
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: resetPassword, variables })).resolves.toMatchObject({
data: { resetPassword: false },
})
})
@ -171,7 +164,7 @@ describe('resetPassword', () => {
it('resolves to false', async () => {
await setup()
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: resetPassword, variables })).resolves.toMatchObject({
data: { resetPassword: false },
})
})
@ -191,13 +184,13 @@ describe('resetPassword', () => {
})
it('resolves to true', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: resetPassword, variables })).resolves.toMatchObject({
data: { resetPassword: true },
})
})
it('updates PasswordReset `usedAt` property', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: resetPassword, variables })
const requests = await getAllPasswordResets()
const [request] = requests
const { usedAt } = request.properties
@ -205,16 +198,11 @@ describe('resetPassword', () => {
})
it('updates password of the user', async () => {
await mutate({ mutation, variables })
const checkLoginMutation = gql`
mutation ($email: String!, $password: String!) {
login(email: $email, password: $password)
}
`
await mutate({ mutation: resetPassword, variables })
variables = { ...variables, email: 'user@example.org', password: 'supersecret' }
await expect(
mutate({ mutation: checkLoginMutation, variables }),
).resolves.toMatchObject({ data: { login: expect.any(String) } })
await expect(mutate({ mutation: login, variables })).resolves.toMatchObject({
data: { login: expect.any(String) },
})
})
})
@ -226,13 +214,13 @@ describe('resetPassword', () => {
})
it('resolves to false', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: resetPassword, variables })).resolves.toMatchObject({
data: { resetPassword: false },
})
})
it('does not update PasswordReset `usedAt` property', async () => {
await mutate({ mutation, variables })
await mutate({ mutation: resetPassword, variables })
const requests = await getAllPasswordResets()
const [request] = requests
const { usedAt } = request.properties

View File

@ -6,10 +6,17 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import Image from '@db/models/Image'
import { createGroupMutation } from '@graphql/queries/createGroupMutation'
import { createPostMutation } from '@graphql/queries/createPostMutation'
import { AddPostEmotions } from '@graphql/queries/AddPostEmotions'
import { CreateGroup } from '@graphql/queries/CreateGroup'
import { CreatePost } from '@graphql/queries/CreatePost'
import { DeletePost } from '@graphql/queries/DeletePost'
import { pinPost } from '@graphql/queries/pinPost'
import { Post } from '@graphql/queries/Post'
import { PostsEmotionsByCurrentUser } from '@graphql/queries/PostsEmotionsByCurrentUser'
import { PostsEmotionsCountByEmotion } from '@graphql/queries/PostsEmotionsCountByEmotion'
import { pushPost } from '@graphql/queries/pushPost'
import { RemovePostEmotions } from '@graphql/queries/RemovePostEmotions'
import { unpinPost } from '@graphql/queries/unpinPost'
import { unpushPost } from '@graphql/queries/unpushPost'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
@ -269,7 +276,7 @@ describe('CreatePost', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: createPostMutation(), variables })
const { errors } = await mutate({ mutation: CreatePost, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -284,9 +291,7 @@ describe('CreatePost', () => {
data: { CreatePost: { title: 'I am a title', content: 'Some content' } },
errors: undefined,
}
await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: CreatePost, variables })).resolves.toMatchObject(expected)
})
it('assigns the authenticated user as author', async () => {
@ -301,20 +306,16 @@ describe('CreatePost', () => {
},
errors: undefined,
}
await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: CreatePost, variables })).resolves.toMatchObject(expected)
})
it('`disabled` and `deleted` default to `false`', async () => {
const expected = { data: { CreatePost: { disabled: false, deleted: false } } }
await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: CreatePost, variables })).resolves.toMatchObject(expected)
})
it('has label "Article" as default', async () => {
await expect(mutate({ mutation: createPostMutation(), variables })).resolves.toMatchObject({
await expect(mutate({ mutation: CreatePost, variables })).resolves.toMatchObject({
data: { CreatePost: { postType: ['Article'] } },
})
})
@ -323,7 +324,7 @@ describe('CreatePost', () => {
it('throws an error', async () => {
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: { ...variables, postType: 'not-valid' },
}),
).resolves.toMatchObject({
@ -342,7 +343,7 @@ describe('CreatePost', () => {
it('throws an error', async () => {
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -362,7 +363,7 @@ describe('CreatePost', () => {
it('throws an error', async () => {
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -387,7 +388,7 @@ describe('CreatePost', () => {
const eventStart = new Date(now.getFullYear(), now.getMonth() - 1).toISOString()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -411,7 +412,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -435,7 +436,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -461,7 +462,7 @@ describe('CreatePost', () => {
const eventEnd = new Date(now.getFullYear(), now.getMonth() + 2).toISOString()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -486,7 +487,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -511,7 +512,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -540,7 +541,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -568,7 +569,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -593,7 +594,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -620,7 +621,7 @@ describe('CreatePost', () => {
const now = new Date()
await expect(
mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
...variables,
postType: 'Event',
@ -700,7 +701,7 @@ describe('UpdatePost', () => {
author = await Factory.build('user', { slug: 'the-author' })
authenticatedUser = await author.toJson()
const { data } = await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
title: 'Old title',
content: 'Old content',
@ -1288,28 +1289,6 @@ describe('unpush posts', () => {
describe('pin posts', () => {
let author
const pinPostMutation = gql`
mutation ($id: ID!) {
pinPost(id: $id) {
id
title
content
author {
name
slug
}
pinnedBy {
id
name
role
}
createdAt
updatedAt
pinnedAt
pinned
}
}
`
beforeEach(async () => {
author = await Factory.build('user', { slug: 'the-author' })
await Factory.build(
@ -1332,7 +1311,7 @@ describe('pin posts', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { pinPost: null },
})
@ -1341,7 +1320,7 @@ describe('pin posts', () => {
describe('ordinary users', () => {
it('throws authorization error', async () => {
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { pinPost: null },
})
@ -1356,7 +1335,7 @@ describe('pin posts', () => {
})
it('throws authorization error', async () => {
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { pinPost: null },
})
@ -1391,7 +1370,7 @@ describe('pin posts', () => {
})
it('throws with error that pinning posts is not allowed', async () => {
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
data: { pinPost: null },
errors: [{ message: 'Pinned posts are not allowed!' }],
})
@ -1435,9 +1414,7 @@ describe('pin posts', () => {
errors: undefined,
}
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject(expected)
})
it('sets createdAt date for PINNED', async () => {
@ -1450,9 +1427,7 @@ describe('pin posts', () => {
},
errors: undefined,
}
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject(expected)
})
it('sets redundant `pinned` property for performant ordering', async () => {
@ -1461,9 +1436,7 @@ describe('pin posts', () => {
data: { pinPost: { pinned: true } },
errors: undefined,
}
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject(expected)
})
})
@ -1506,9 +1479,7 @@ describe('pin posts', () => {
errors: undefined,
}
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject(expected)
})
})
@ -1531,9 +1502,7 @@ describe('pin posts', () => {
errors: undefined,
}
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject(expected)
})
})
@ -1549,7 +1518,7 @@ describe('pin posts', () => {
author: admin,
},
)
await mutate({ mutation: pinPostMutation, variables })
await mutate({ mutation: pinPost, variables })
})
it('removes previous `pinned` attribute', async () => {
@ -1557,14 +1526,14 @@ describe('pin posts', () => {
pinnedPost = await database.neode.cypher(cypher, {})
expect(pinnedPost.records).toHaveLength(1)
variables = { ...variables, id: 'only-pinned-post' }
await mutate({ mutation: pinPostMutation, variables })
await mutate({ mutation: pinPost, variables })
pinnedPost = await database.neode.cypher(cypher, {})
expect(pinnedPost.records).toHaveLength(1)
})
it('removes previous PINNED relationship', async () => {
variables = { ...variables, id: 'only-pinned-post' }
await mutate({ mutation: pinPostMutation, variables })
await mutate({ mutation: pinPost, variables })
pinnedPost = await database.neode.cypher(
`MATCH (:User)-[pinned:PINNED]->(post:Post) RETURN post, pinned`,
{},
@ -1576,7 +1545,7 @@ describe('pin posts', () => {
describe('post in public group', () => {
beforeEach(async () => {
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
name: 'Public Group',
id: 'public-group',
@ -1589,7 +1558,7 @@ describe('pin posts', () => {
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'public-group-post',
title: 'Public group post',
@ -1602,7 +1571,7 @@ describe('pin posts', () => {
})
it('can be pinned', async () => {
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
data: {
pinPost: {
id: 'public-group-post',
@ -1624,7 +1593,7 @@ describe('pin posts', () => {
describe('post in closed group', () => {
beforeEach(async () => {
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
name: 'Closed Group',
id: 'closed-group',
@ -1637,7 +1606,7 @@ describe('pin posts', () => {
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'closed-group-post',
title: 'Closed group post',
@ -1650,7 +1619,7 @@ describe('pin posts', () => {
})
it('can not be pinned', async () => {
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
data: {
pinPost: null,
},
@ -1662,7 +1631,7 @@ describe('pin posts', () => {
describe('post in hidden group', () => {
beforeEach(async () => {
await mutate({
mutation: createGroupMutation(),
mutation: CreateGroup,
variables: {
name: 'Hidden Group',
id: 'hidden-group',
@ -1675,7 +1644,7 @@ describe('pin posts', () => {
},
})
await mutate({
mutation: createPostMutation(),
mutation: CreatePost,
variables: {
id: 'hidden-group-post',
title: 'Hidden group post',
@ -1688,7 +1657,7 @@ describe('pin posts', () => {
})
it('can not be pinned', async () => {
await expect(mutate({ mutation: pinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: pinPost, variables })).resolves.toMatchObject({
data: {
pinPost: null,
},
@ -1800,7 +1769,7 @@ describe('pin posts', () => {
beforeEach(async () => {
variables = { ...variables, id: 'first-post' }
result = await mutate({ mutation: pinPostMutation, variables })
result = await mutate({ mutation: pinPost, variables })
})
it('pins the first post', () => {
@ -1836,7 +1805,7 @@ describe('pin posts', () => {
describe('second post', () => {
beforeEach(async () => {
variables = { ...variables, id: 'second-post' }
result = await mutate({ mutation: pinPostMutation, variables })
result = await mutate({ mutation: pinPost, variables })
})
it('pins the second post', () => {
@ -1872,7 +1841,7 @@ describe('pin posts', () => {
describe('third post', () => {
beforeEach(async () => {
variables = { ...variables, id: 'third-post' }
result = await mutate({ mutation: pinPostMutation, variables })
result = await mutate({ mutation: pinPost, variables })
})
it('pins the second post', () => {
@ -1908,7 +1877,7 @@ describe('pin posts', () => {
describe('another post', () => {
beforeEach(async () => {
variables = { ...variables, id: 'another-post' }
result = await mutate({ mutation: pinPostMutation, variables })
result = await mutate({ mutation: pinPost, variables })
})
it('throws with max pinned posts is reached', () => {
@ -1974,28 +1943,6 @@ describe('pin posts', () => {
describe('unpin posts', () => {
let pinnedPost
const unpinPostMutation = gql`
mutation ($id: ID!) {
unpinPost(id: $id) {
id
title
content
author {
name
slug
}
pinnedBy {
id
name
role
}
createdAt
updatedAt
pinned
pinnedAt
}
}
`
beforeEach(async () => {
pinnedPost = await Factory.build('post', { id: 'post-to-be-unpinned' })
variables = {
@ -2006,7 +1953,7 @@ describe('unpin posts', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
await expect(mutate({ mutation: unpinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: unpinPost, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { unpinPost: null },
})
@ -2015,7 +1962,7 @@ describe('unpin posts', () => {
describe('users cannot unpin posts', () => {
it('throws authorization error', async () => {
await expect(mutate({ mutation: unpinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: unpinPost, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { unpinPost: null },
})
@ -2030,7 +1977,7 @@ describe('unpin posts', () => {
})
it('throws authorization error', async () => {
await expect(mutate({ mutation: unpinPostMutation, variables })).resolves.toMatchObject({
await expect(mutate({ mutation: unpinPost, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { unpinPost: null },
})
@ -2062,9 +2009,7 @@ describe('unpin posts', () => {
errors: undefined,
}
await expect(mutate({ mutation: unpinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: unpinPost, variables })).resolves.toMatchObject(expected)
})
it('unsets `pinned` property', async () => {
@ -2077,33 +2022,13 @@ describe('unpin posts', () => {
},
errors: undefined,
}
await expect(mutate({ mutation: unpinPostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: unpinPost, variables })).resolves.toMatchObject(expected)
})
})
})
describe('DeletePost', () => {
let author
const deletePostMutation = gql`
mutation ($id: ID!) {
DeletePost(id: $id) {
id
deleted
content
contentExcerpt
image {
url
}
comments {
deleted
content
contentExcerpt
}
}
}
`
beforeEach(async () => {
author = await Factory.build('user')
@ -2127,7 +2052,7 @@ describe('DeletePost', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: deletePostMutation, variables })
const { errors } = await mutate({ mutation: DeletePost, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -2138,7 +2063,7 @@ describe('DeletePost', () => {
})
it('throws authorization error', async () => {
const { errors } = await mutate({ mutation: deletePostMutation, variables })
const { errors } = await mutate({ mutation: DeletePost, variables })
expect(errors?.[0]).toHaveProperty('message', 'Not Authorized!')
})
})
@ -2161,9 +2086,7 @@ describe('DeletePost', () => {
},
},
}
await expect(mutate({ mutation: deletePostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: DeletePost, variables })).resolves.toMatchObject(expected)
})
describe('if there are comments on the post', () => {
@ -2200,9 +2123,7 @@ describe('DeletePost', () => {
},
},
}
await expect(mutate({ mutation: deletePostMutation, variables })).resolves.toMatchObject(
expected,
)
await expect(mutate({ mutation: DeletePost, variables })).resolves.toMatchObject(expected)
})
})
})
@ -2251,19 +2172,6 @@ describe('emotions', () => {
})
describe('AddPostEmotions', () => {
const addPostEmotionsMutation = gql`
mutation ($to: _PostInput!, $data: _EMOTEDInput!) {
AddPostEmotions(to: $to, data: $data) {
from {
id
}
to {
id
}
emotion
}
}
`
let postsEmotionsQueryVariables
beforeEach(() => {
@ -2277,7 +2185,7 @@ describe('emotions', () => {
it('throws authorization error', async () => {
const addPostEmotions = await mutate({
mutation: addPostEmotionsMutation,
mutation: AddPostEmotions,
variables,
})
@ -2300,7 +2208,7 @@ describe('emotions', () => {
},
},
}
await expect(mutate({ mutation: addPostEmotionsMutation, variables })).resolves.toEqual(
await expect(mutate({ mutation: AddPostEmotions, variables })).resolves.toEqual(
expect.objectContaining(expected),
)
})
@ -2315,8 +2223,8 @@ describe('emotions', () => {
],
},
}
await mutate({ mutation: addPostEmotionsMutation, variables })
await mutate({ mutation: addPostEmotionsMutation, variables })
await mutate({ mutation: AddPostEmotions, variables })
await mutate({ mutation: AddPostEmotions, variables })
await expect(
query({ query: PostsEmotionsCountQuery, variables: postsEmotionsQueryVariables }),
).resolves.toEqual(expect.objectContaining(expected))
@ -2335,9 +2243,9 @@ describe('emotions', () => {
],
},
}
await mutate({ mutation: addPostEmotionsMutation, variables })
await mutate({ mutation: AddPostEmotions, variables })
variables = { ...variables, data: { emotion: 'surprised' } }
await mutate({ mutation: addPostEmotionsMutation, variables })
await mutate({ mutation: AddPostEmotions, variables })
await expect(
query({ query: PostsEmotionsQuery, variables: postsEmotionsQueryVariables }),
).resolves.toEqual(expect.objectContaining(expected))
@ -2359,7 +2267,7 @@ describe('emotions', () => {
},
},
}
await expect(mutate({ mutation: addPostEmotionsMutation, variables })).resolves.toEqual(
await expect(mutate({ mutation: AddPostEmotions, variables })).resolves.toEqual(
expect.objectContaining(expected),
)
})
@ -2368,19 +2276,6 @@ describe('emotions', () => {
describe('RemovePostEmotions', () => {
let removePostEmotionsVariables, postsEmotionsQueryVariables
const removePostEmotionsMutation = gql`
mutation ($to: _PostInput!, $data: _EMOTEDInput!) {
RemovePostEmotions(to: $to, data: $data) {
from {
id
}
to {
id
}
emotion
}
}
`
beforeEach(async () => {
await author.relateTo(postToEmote, 'emoted', { emotion: 'happy' })
await user.relateTo(postToEmote, 'emoted', { emotion: 'cry' })
@ -2399,7 +2294,7 @@ describe('emotions', () => {
it('throws authorization error', async () => {
const removePostEmotions = await mutate({
mutation: removePostEmotionsMutation,
mutation: RemovePostEmotions,
variables: removePostEmotionsVariables,
})
expect(removePostEmotions.errors?.[0]).toHaveProperty('message', 'Not Authorized!')
@ -2414,7 +2309,7 @@ describe('emotions', () => {
it('returns null if the emotion could not be found', async () => {
const removePostEmotions = await mutate({
mutation: removePostEmotionsMutation,
mutation: RemovePostEmotions,
variables: removePostEmotionsVariables,
})
expect(removePostEmotions).toEqual(
@ -2440,7 +2335,7 @@ describe('emotions', () => {
}
await expect(
mutate({
mutation: removePostEmotionsMutation,
mutation: RemovePostEmotions,
variables: removePostEmotionsVariables,
}),
).resolves.toEqual(expect.objectContaining(expected))
@ -2452,7 +2347,7 @@ describe('emotions', () => {
data: { Post: [{ emotions: expect.arrayContaining(expectedEmotions) }] },
}
await mutate({
mutation: removePostEmotionsMutation,
mutation: RemovePostEmotions,
variables: removePostEmotionsVariables,
})
await expect(
@ -2467,17 +2362,6 @@ describe('emotions', () => {
let PostsEmotionsCountByEmotionVariables
let PostsEmotionsByCurrentUserVariables
const PostsEmotionsCountByEmotionQuery = gql`
query ($postId: ID!, $data: _EMOTEDInput!) {
PostsEmotionsCountByEmotion(postId: $postId, data: $data)
}
`
const PostsEmotionsByCurrentUserQuery = gql`
query ($postId: ID!) {
PostsEmotionsByCurrentUser(postId: $postId)
}
`
beforeEach(async () => {
await user.relateTo(postToEmote, 'emoted', { emotion: 'cry' })
@ -2493,7 +2377,7 @@ describe('emotions', () => {
const expectedResponse = { data: { PostsEmotionsCountByEmotion: 1 } }
await expect(
query({
query: PostsEmotionsCountByEmotionQuery,
query: PostsEmotionsCountByEmotion,
variables: PostsEmotionsCountByEmotionVariables,
}),
).resolves.toEqual(expect.objectContaining(expectedResponse))
@ -2510,7 +2394,7 @@ describe('emotions', () => {
const expectedResponse = { data: { PostsEmotionsByCurrentUser: ['cry'] } }
await expect(
query({
query: PostsEmotionsByCurrentUserQuery,
query: PostsEmotionsByCurrentUser,
variables: PostsEmotionsByCurrentUserVariables,
}),
).resolves.toEqual(expect.objectContaining(expectedResponse))

Some files were not shown because too many files have changed in this diff Show More