diff --git a/backend/src/db/seed.ts b/backend/src/db/seed.ts
index d9db21b54..238f5a9c9 100644
--- a/backend/src/db/seed.ts
+++ b/backend/src/db/seed.ts
@@ -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 #QuantenFlussTheorie can explain #QuantumGravity! @peter-lustig 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 @peter-lustig 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,
},
diff --git a/backend/src/graphql/queries/AddEmailAddress.ts b/backend/src/graphql/queries/AddEmailAddress.ts
new file mode 100644
index 000000000..9b84fea90
--- /dev/null
+++ b/backend/src/graphql/queries/AddEmailAddress.ts
@@ -0,0 +1,11 @@
+import gql from 'graphql-tag'
+
+export const AddEmailAddress = gql`
+ mutation ($email: String!) {
+ AddEmailAddress(email: $email) {
+ email
+ verifiedAt
+ createdAt
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/AddPostEmotions.ts b/backend/src/graphql/queries/AddPostEmotions.ts
new file mode 100644
index 000000000..88c97da3c
--- /dev/null
+++ b/backend/src/graphql/queries/AddPostEmotions.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/Category.ts b/backend/src/graphql/queries/Category.ts
new file mode 100644
index 000000000..202ba2165
--- /dev/null
+++ b/backend/src/graphql/queries/Category.ts
@@ -0,0 +1,12 @@
+import gql from 'graphql-tag'
+
+export const Category = gql`
+ query {
+ Category {
+ id
+ slug
+ name
+ icon
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/ChangeGroupMemberRole.ts b/backend/src/graphql/queries/ChangeGroupMemberRole.ts
new file mode 100644
index 000000000..7c54be38f
--- /dev/null
+++ b/backend/src/graphql/queries/ChangeGroupMemberRole.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/createCommentMutation.ts b/backend/src/graphql/queries/CreateComment.ts
similarity index 67%
rename from backend/src/graphql/queries/createCommentMutation.ts
rename to backend/src/graphql/queries/CreateComment.ts
index c3824e1d0..c236b9826 100644
--- a/backend/src/graphql/queries/createCommentMutation.ts
+++ b/backend/src/graphql/queries/CreateComment.ts
@@ -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
+ }
}
}
`
diff --git a/backend/src/graphql/queries/CreateGroup.ts b/backend/src/graphql/queries/CreateGroup.ts
new file mode 100644
index 000000000..3423b386e
--- /dev/null
+++ b/backend/src/graphql/queries/CreateGroup.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/CreatePost.ts b/backend/src/graphql/queries/CreatePost.ts
new file mode 100644
index 000000000..3c0ed8384
--- /dev/null
+++ b/backend/src/graphql/queries/CreatePost.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/CreateRoom.ts b/backend/src/graphql/queries/CreateRoom.ts
new file mode 100644
index 000000000..dd52e5ebe
--- /dev/null
+++ b/backend/src/graphql/queries/CreateRoom.ts
@@ -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
+ }
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/DeleteComment.ts b/backend/src/graphql/queries/DeleteComment.ts
new file mode 100644
index 000000000..033357b79
--- /dev/null
+++ b/backend/src/graphql/queries/DeleteComment.ts
@@ -0,0 +1,12 @@
+import gql from 'graphql-tag'
+
+export const DeleteComment = gql`
+ mutation ($id: ID!) {
+ DeleteComment(id: $id) {
+ id
+ content
+ contentExcerpt
+ deleted
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/DeletePost.ts b/backend/src/graphql/queries/DeletePost.ts
new file mode 100644
index 000000000..fc02f1747
--- /dev/null
+++ b/backend/src/graphql/queries/DeletePost.ts
@@ -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
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/DeleteSocialMedia.ts b/backend/src/graphql/queries/DeleteSocialMedia.ts
new file mode 100644
index 000000000..1d2d17565
--- /dev/null
+++ b/backend/src/graphql/queries/DeleteSocialMedia.ts
@@ -0,0 +1,10 @@
+import gql from 'graphql-tag'
+
+export const DeleteSocialMedia = gql`
+ mutation ($id: ID!) {
+ DeleteSocialMedia(id: $id) {
+ id
+ url
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/DeleteUser.ts b/backend/src/graphql/queries/DeleteUser.ts
new file mode 100644
index 000000000..aa1176392
--- /dev/null
+++ b/backend/src/graphql/queries/DeleteUser.ts
@@ -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
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/Donations.ts b/backend/src/graphql/queries/Donations.ts
new file mode 100644
index 000000000..eaee90af6
--- /dev/null
+++ b/backend/src/graphql/queries/Donations.ts
@@ -0,0 +1,12 @@
+import gql from 'graphql-tag'
+
+export const Donations = gql`
+ query {
+ Donations {
+ id
+ showDonations
+ goal
+ progress
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/JoinGroup.ts b/backend/src/graphql/queries/JoinGroup.ts
new file mode 100644
index 000000000..d7bcdc6c3
--- /dev/null
+++ b/backend/src/graphql/queries/JoinGroup.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/LeaveGroup.ts b/backend/src/graphql/queries/LeaveGroup.ts
new file mode 100644
index 000000000..ce0973e6d
--- /dev/null
+++ b/backend/src/graphql/queries/LeaveGroup.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/Post.ts b/backend/src/graphql/queries/Post.ts
index f737bac86..7bebcdcf1 100644
--- a/backend/src/graphql/queries/Post.ts
+++ b/backend/src/graphql/queries/Post.ts
@@ -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
diff --git a/backend/src/graphql/queries/PostsEmotionsByCurrentUser.ts b/backend/src/graphql/queries/PostsEmotionsByCurrentUser.ts
new file mode 100644
index 000000000..8eeff6425
--- /dev/null
+++ b/backend/src/graphql/queries/PostsEmotionsByCurrentUser.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const PostsEmotionsByCurrentUser = gql`
+ query ($postId: ID!) {
+ PostsEmotionsByCurrentUser(postId: $postId)
+ }
+`
diff --git a/backend/src/graphql/queries/PostsEmotionsCountByEmotion.ts b/backend/src/graphql/queries/PostsEmotionsCountByEmotion.ts
new file mode 100644
index 000000000..d97eaa66f
--- /dev/null
+++ b/backend/src/graphql/queries/PostsEmotionsCountByEmotion.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const PostsEmotionsCountByEmotion = gql`
+ query ($postId: ID!, $data: _EMOTEDInput!) {
+ PostsEmotionsCountByEmotion(postId: $postId, data: $data)
+ }
+`
diff --git a/backend/src/graphql/queries/RemovePostEmotions.ts b/backend/src/graphql/queries/RemovePostEmotions.ts
new file mode 100644
index 000000000..0b0906d79
--- /dev/null
+++ b/backend/src/graphql/queries/RemovePostEmotions.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/RemoveUserFromGroup.ts b/backend/src/graphql/queries/RemoveUserFromGroup.ts
new file mode 100644
index 000000000..e827807df
--- /dev/null
+++ b/backend/src/graphql/queries/RemoveUserFromGroup.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/Room.ts b/backend/src/graphql/queries/Room.ts
new file mode 100644
index 000000000..32f53411d
--- /dev/null
+++ b/backend/src/graphql/queries/Room.ts
@@ -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
+ }
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/Signup.ts b/backend/src/graphql/queries/Signup.ts
new file mode 100644
index 000000000..1d3319b31
--- /dev/null
+++ b/backend/src/graphql/queries/Signup.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/signupVerificationMutation.ts b/backend/src/graphql/queries/SignupVerification.ts
similarity index 90%
rename from backend/src/graphql/queries/signupVerificationMutation.ts
rename to backend/src/graphql/queries/SignupVerification.ts
index f504da0ce..a3fb9bec4 100644
--- a/backend/src/graphql/queries/signupVerificationMutation.ts
+++ b/backend/src/graphql/queries/SignupVerification.ts
@@ -1,6 +1,6 @@
import gql from 'graphql-tag'
-export const signupVerificationMutation = gql`
+export const SignupVerification = gql`
mutation (
$password: String!
$email: String!
diff --git a/backend/src/graphql/queries/UnreadRooms.ts b/backend/src/graphql/queries/UnreadRooms.ts
new file mode 100644
index 000000000..7cd0e8e1b
--- /dev/null
+++ b/backend/src/graphql/queries/UnreadRooms.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const UnreadRooms = gql`
+ query {
+ UnreadRooms
+ }
+`
diff --git a/backend/src/graphql/queries/UpdateComment.ts b/backend/src/graphql/queries/UpdateComment.ts
new file mode 100644
index 000000000..27d04ae8e
--- /dev/null
+++ b/backend/src/graphql/queries/UpdateComment.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/UpdateDonations.ts b/backend/src/graphql/queries/UpdateDonations.ts
new file mode 100644
index 000000000..bb5ccdc3d
--- /dev/null
+++ b/backend/src/graphql/queries/UpdateDonations.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/UpdateGroup.ts b/backend/src/graphql/queries/UpdateGroup.ts
new file mode 100644
index 000000000..ccad22eec
--- /dev/null
+++ b/backend/src/graphql/queries/UpdateGroup.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/UpdatePost.ts b/backend/src/graphql/queries/UpdatePost.ts
new file mode 100644
index 000000000..978ca8a04
--- /dev/null
+++ b/backend/src/graphql/queries/UpdatePost.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/UpdateSocialMedia.ts b/backend/src/graphql/queries/UpdateSocialMedia.ts
new file mode 100644
index 000000000..dfbfeb22e
--- /dev/null
+++ b/backend/src/graphql/queries/UpdateSocialMedia.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/UpdateUser.ts b/backend/src/graphql/queries/UpdateUser.ts
new file mode 100644
index 000000000..cb201f0cb
--- /dev/null
+++ b/backend/src/graphql/queries/UpdateUser.ts
@@ -0,0 +1,9 @@
+import gql from 'graphql-tag'
+
+export const UpdateUser = gql`
+ mutation ($id: ID!, $name: String) {
+ UpdateUser(id: $id, name: $name) {
+ name
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/User.ts b/backend/src/graphql/queries/User.ts
new file mode 100644
index 000000000..567ea8386
--- /dev/null
+++ b/backend/src/graphql/queries/User.ts
@@ -0,0 +1,9 @@
+import gql from 'graphql-tag'
+
+export const User = gql`
+ query ($name: String) {
+ User(name: $name) {
+ email
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/VerifyEmailAddress.ts b/backend/src/graphql/queries/VerifyEmailAddress.ts
new file mode 100644
index 000000000..48e7093e0
--- /dev/null
+++ b/backend/src/graphql/queries/VerifyEmailAddress.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/VerifyNonce.ts b/backend/src/graphql/queries/VerifyNonce.ts
new file mode 100644
index 000000000..6511d1f29
--- /dev/null
+++ b/backend/src/graphql/queries/VerifyNonce.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const VerifyNonce = gql`
+ query ($email: String!, $nonce: String!) {
+ VerifyNonce(email: $email, nonce: $nonce)
+ }
+`
diff --git a/backend/src/graphql/queries/changeGroupMemberRoleMutation.ts b/backend/src/graphql/queries/changeGroupMemberRoleMutation.ts
deleted file mode 100644
index a01c19cfb..000000000
--- a/backend/src/graphql/queries/changeGroupMemberRoleMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/changePassword.ts b/backend/src/graphql/queries/changePassword.ts
new file mode 100644
index 000000000..f53e701ef
--- /dev/null
+++ b/backend/src/graphql/queries/changePassword.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const changePassword = gql`
+ mutation ($oldPassword: String!, $newPassword: String!) {
+ changePassword(oldPassword: $oldPassword, newPassword: $newPassword)
+ }
+`
diff --git a/backend/src/graphql/queries/createGroupMutation.ts b/backend/src/graphql/queries/createGroupMutation.ts
deleted file mode 100644
index 20cd93323..000000000
--- a/backend/src/graphql/queries/createGroupMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/createPostMutation.ts b/backend/src/graphql/queries/createPostMutation.ts
deleted file mode 100644
index f0a01b303..000000000
--- a/backend/src/graphql/queries/createPostMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/createRoomMutation.ts b/backend/src/graphql/queries/createRoomMutation.ts
deleted file mode 100644
index 3a791d294..000000000
--- a/backend/src/graphql/queries/createRoomMutation.ts
+++ /dev/null
@@ -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
- }
- }
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/embed.ts b/backend/src/graphql/queries/embed.ts
new file mode 100644
index 000000000..12df35406
--- /dev/null
+++ b/backend/src/graphql/queries/embed.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/fileReport.ts b/backend/src/graphql/queries/fileReport.ts
new file mode 100644
index 000000000..87410c662
--- /dev/null
+++ b/backend/src/graphql/queries/fileReport.ts
@@ -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
+ }
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/filterPosts.ts b/backend/src/graphql/queries/filterPosts.ts
deleted file mode 100644
index 7e6d5059f..000000000
--- a/backend/src/graphql/queries/filterPosts.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/followUser.ts b/backend/src/graphql/queries/followUser.ts
new file mode 100644
index 000000000..f82656e6e
--- /dev/null
+++ b/backend/src/graphql/queries/followUser.ts
@@ -0,0 +1,14 @@
+import gql from 'graphql-tag'
+
+export const followUser = gql`
+ mutation ($id: ID!) {
+ followUser(id: $id) {
+ name
+ followedBy {
+ id
+ name
+ }
+ followedByCurrentUser
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/joinGroupMutation.ts b/backend/src/graphql/queries/joinGroupMutation.ts
deleted file mode 100644
index ce627b1ef..000000000
--- a/backend/src/graphql/queries/joinGroupMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/leaveGroupMutation.ts b/backend/src/graphql/queries/leaveGroupMutation.ts
deleted file mode 100644
index 470bd6a7a..000000000
--- a/backend/src/graphql/queries/leaveGroupMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/loginMutation.ts b/backend/src/graphql/queries/login.ts
similarity index 79%
rename from backend/src/graphql/queries/loginMutation.ts
rename to backend/src/graphql/queries/login.ts
index 8c7b36f12..c296d05e5 100644
--- a/backend/src/graphql/queries/loginMutation.ts
+++ b/backend/src/graphql/queries/login.ts
@@ -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)
}
diff --git a/backend/src/graphql/queries/markAllAsRead.ts b/backend/src/graphql/queries/markAllAsRead.ts
new file mode 100644
index 000000000..47b6c0779
--- /dev/null
+++ b/backend/src/graphql/queries/markAllAsRead.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/markAllAsReadMutation.ts b/backend/src/graphql/queries/markAllAsReadMutation.ts
deleted file mode 100644
index d1f19e369..000000000
--- a/backend/src/graphql/queries/markAllAsReadMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/markAsRead.ts b/backend/src/graphql/queries/markAsRead.ts
new file mode 100644
index 000000000..23f8125fd
--- /dev/null
+++ b/backend/src/graphql/queries/markAsRead.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/markAsReadMutation.ts b/backend/src/graphql/queries/markAsReadMutation.ts
deleted file mode 100644
index fd855665a..000000000
--- a/backend/src/graphql/queries/markAsReadMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/markTeaserAsViewed.ts b/backend/src/graphql/queries/markTeaserAsViewed.ts
new file mode 100644
index 000000000..241ea168c
--- /dev/null
+++ b/backend/src/graphql/queries/markTeaserAsViewed.ts
@@ -0,0 +1,10 @@
+import gql from 'graphql-tag'
+
+export const markTeaserAsViewed = gql`
+ mutation ($id: ID!) {
+ markTeaserAsViewed(id: $id) {
+ id
+ viewedTeaserCount
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/muteGroup.ts b/backend/src/graphql/queries/muteGroup.ts
new file mode 100644
index 000000000..269b39762
--- /dev/null
+++ b/backend/src/graphql/queries/muteGroup.ts
@@ -0,0 +1,10 @@
+import gql from 'graphql-tag'
+
+export const muteGroup = gql`
+ mutation ($groupId: ID!) {
+ muteGroup(groupId: $groupId) {
+ id
+ isMutedByMe
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/muteUser.ts b/backend/src/graphql/queries/muteUser.ts
new file mode 100644
index 000000000..0adb3469c
--- /dev/null
+++ b/backend/src/graphql/queries/muteUser.ts
@@ -0,0 +1,11 @@
+import gql from 'graphql-tag'
+
+export const muteUser = gql`
+ mutation ($id: ID!) {
+ muteUser(id: $id) {
+ id
+ name
+ isMuted
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/mutedUsers.ts b/backend/src/graphql/queries/mutedUsers.ts
new file mode 100644
index 000000000..5e00153c9
--- /dev/null
+++ b/backend/src/graphql/queries/mutedUsers.ts
@@ -0,0 +1,11 @@
+import gql from 'graphql-tag'
+
+export const mutedUsers = gql`
+ query {
+ mutedUsers {
+ id
+ name
+ isMuted
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/notificationQuery.ts b/backend/src/graphql/queries/notificationQuery.ts
deleted file mode 100644
index 965fb9ce9..000000000
--- a/backend/src/graphql/queries/notificationQuery.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/notifications.ts b/backend/src/graphql/queries/notifications.ts
new file mode 100644
index 000000000..dc1aadc0d
--- /dev/null
+++ b/backend/src/graphql/queries/notifications.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/pinPost.ts b/backend/src/graphql/queries/pinPost.ts
new file mode 100644
index 000000000..6976bbc3d
--- /dev/null
+++ b/backend/src/graphql/queries/pinPost.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/postQuery.ts b/backend/src/graphql/queries/postQuery.ts
deleted file mode 100644
index ff8faf311..000000000
--- a/backend/src/graphql/queries/postQuery.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import gql from 'graphql-tag'
-
-export const postQuery = () => {
- return gql`
- query Post($id: ID!) {
- Post(id: $id) {
- id
- title
- content
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/profilePagePosts.ts b/backend/src/graphql/queries/profilePagePosts.ts
index 5d713a23c..07ce18f40 100644
--- a/backend/src/graphql/queries/profilePagePosts.ts
+++ b/backend/src/graphql/queries/profilePagePosts.ts
@@ -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
}
- `
-}
+ }
+`
diff --git a/backend/src/graphql/queries/queryLocations.ts b/backend/src/graphql/queries/queryLocations.ts
new file mode 100644
index 000000000..fef21a9ad
--- /dev/null
+++ b/backend/src/graphql/queries/queryLocations.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/removeUserFromGroupMutation.ts b/backend/src/graphql/queries/removeUserFromGroupMutation.ts
deleted file mode 100644
index bdb9792d9..000000000
--- a/backend/src/graphql/queries/removeUserFromGroupMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/reports.ts b/backend/src/graphql/queries/reports.ts
new file mode 100644
index 000000000..13849d3e4
--- /dev/null
+++ b/backend/src/graphql/queries/reports.ts
@@ -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
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/requestPasswordReset.ts b/backend/src/graphql/queries/requestPasswordReset.ts
new file mode 100644
index 000000000..6d6325131
--- /dev/null
+++ b/backend/src/graphql/queries/requestPasswordReset.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const requestPasswordReset = gql`
+ mutation ($email: String!, $locale: String!) {
+ requestPasswordReset(email: $email, locale: $locale)
+ }
+`
diff --git a/backend/src/graphql/queries/resetPassword.ts b/backend/src/graphql/queries/resetPassword.ts
new file mode 100644
index 000000000..280a059c7
--- /dev/null
+++ b/backend/src/graphql/queries/resetPassword.ts
@@ -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)
+ }
+`
diff --git a/backend/src/graphql/queries/resetTrophyBadgesSelected.ts b/backend/src/graphql/queries/resetTrophyBadgesSelected.ts
new file mode 100644
index 000000000..add29f17d
--- /dev/null
+++ b/backend/src/graphql/queries/resetTrophyBadgesSelected.ts
@@ -0,0 +1,17 @@
+import gql from 'graphql-tag'
+
+export const resetTrophyBadgesSelected = gql`
+ mutation {
+ resetTrophyBadgesSelected {
+ badgeTrophiesCount
+ badgeTrophiesSelected {
+ id
+ isDefault
+ }
+ badgeTrophiesUnused {
+ id
+ }
+ badgeTrophiesUnusedCount
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/review.ts b/backend/src/graphql/queries/review.ts
new file mode 100644
index 000000000..dcb65c7ad
--- /dev/null
+++ b/backend/src/graphql/queries/review.ts
@@ -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
+ }
+ }
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/revokeBadge.ts b/backend/src/graphql/queries/revokeBadge.ts
new file mode 100644
index 000000000..809464b99
--- /dev/null
+++ b/backend/src/graphql/queries/revokeBadge.ts
@@ -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
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/roomQuery.ts b/backend/src/graphql/queries/roomQuery.ts
deleted file mode 100644
index 01b24654e..000000000
--- a/backend/src/graphql/queries/roomQuery.ts
+++ /dev/null
@@ -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
- }
- }
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/saveCategorySettings.ts b/backend/src/graphql/queries/saveCategorySettings.ts
new file mode 100644
index 000000000..8f5d72f04
--- /dev/null
+++ b/backend/src/graphql/queries/saveCategorySettings.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const saveCategorySettings = gql`
+ mutation ($activeCategories: [String]) {
+ saveCategorySettings(activeCategories: $activeCategories)
+ }
+`
diff --git a/backend/src/graphql/queries/searchPosts.ts b/backend/src/graphql/queries/searchPosts.ts
index ed9e9a641..121d4783f 100644
--- a/backend/src/graphql/queries/searchPosts.ts
+++ b/backend/src/graphql/queries/searchPosts.ts
@@ -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
}
}
- `
-}
+ }
+`
diff --git a/backend/src/graphql/queries/searchResults.ts b/backend/src/graphql/queries/searchResults.ts
new file mode 100644
index 000000000..0065a5347
--- /dev/null
+++ b/backend/src/graphql/queries/searchResults.ts
@@ -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
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/setVerificationBadge.ts b/backend/src/graphql/queries/setVerificationBadge.ts
new file mode 100644
index 000000000..b37ca5535
--- /dev/null
+++ b/backend/src/graphql/queries/setVerificationBadge.ts
@@ -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
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/shout.ts b/backend/src/graphql/queries/shout.ts
new file mode 100644
index 000000000..6861fffec
--- /dev/null
+++ b/backend/src/graphql/queries/shout.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const shout = gql`
+ mutation ($id: ID!) {
+ shout(id: $id, type: Post)
+ }
+`
diff --git a/backend/src/graphql/queries/switchUserRole.ts b/backend/src/graphql/queries/switchUserRole.ts
new file mode 100644
index 000000000..55d41abc0
--- /dev/null
+++ b/backend/src/graphql/queries/switchUserRole.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/toggleObservePost.ts b/backend/src/graphql/queries/toggleObservePost.ts
new file mode 100644
index 000000000..a75950c63
--- /dev/null
+++ b/backend/src/graphql/queries/toggleObservePost.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/unfollowUser.ts b/backend/src/graphql/queries/unfollowUser.ts
new file mode 100644
index 000000000..aa2acb371
--- /dev/null
+++ b/backend/src/graphql/queries/unfollowUser.ts
@@ -0,0 +1,14 @@
+import gql from 'graphql-tag'
+
+export const unfollowUser = gql`
+ mutation ($id: ID!) {
+ unfollowUser(id: $id) {
+ name
+ followedBy {
+ id
+ name
+ }
+ followedByCurrentUser
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/unmuteGroup.ts b/backend/src/graphql/queries/unmuteGroup.ts
new file mode 100644
index 000000000..53b335201
--- /dev/null
+++ b/backend/src/graphql/queries/unmuteGroup.ts
@@ -0,0 +1,10 @@
+import gql from 'graphql-tag'
+
+export const unmuteGroup = gql`
+ mutation ($groupId: ID!) {
+ unmuteGroup(groupId: $groupId) {
+ id
+ isMutedByMe
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/unmuteUser.ts b/backend/src/graphql/queries/unmuteUser.ts
new file mode 100644
index 000000000..0078b6091
--- /dev/null
+++ b/backend/src/graphql/queries/unmuteUser.ts
@@ -0,0 +1,11 @@
+import gql from 'graphql-tag'
+
+export const unmuteUser = gql`
+ mutation ($id: ID!) {
+ unmuteUser(id: $id) {
+ id
+ name
+ isMuted
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/unpinPost.ts b/backend/src/graphql/queries/unpinPost.ts
new file mode 100644
index 000000000..3130e1de7
--- /dev/null
+++ b/backend/src/graphql/queries/unpinPost.ts
@@ -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
+ }
+ }
+`
diff --git a/backend/src/graphql/queries/unreadRoomsQuery.ts b/backend/src/graphql/queries/unreadRoomsQuery.ts
deleted file mode 100644
index d5612dcad..000000000
--- a/backend/src/graphql/queries/unreadRoomsQuery.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import gql from 'graphql-tag'
-
-export const unreadRoomsQuery = () => {
- return gql`
- query {
- UnreadRooms
- }
- `
-}
diff --git a/backend/src/graphql/queries/unshout.ts b/backend/src/graphql/queries/unshout.ts
new file mode 100644
index 000000000..6ad27180f
--- /dev/null
+++ b/backend/src/graphql/queries/unshout.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const unshout = gql`
+ mutation ($id: ID!) {
+ unshout(id: $id, type: Post)
+ }
+`
diff --git a/backend/src/graphql/queries/updateGroupMutation.ts b/backend/src/graphql/queries/updateGroupMutation.ts
deleted file mode 100644
index 826a9c9d4..000000000
--- a/backend/src/graphql/queries/updateGroupMutation.ts
+++ /dev/null
@@ -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
- }
- }
- `
-}
diff --git a/backend/src/graphql/queries/updateOnlineStatus.ts b/backend/src/graphql/queries/updateOnlineStatus.ts
new file mode 100644
index 000000000..ee39b0667
--- /dev/null
+++ b/backend/src/graphql/queries/updateOnlineStatus.ts
@@ -0,0 +1,7 @@
+import gql from 'graphql-tag'
+
+export const updateOnlineStatus = gql`
+ mutation ($status: OnlineStatus!) {
+ updateOnlineStatus(status: $status)
+ }
+`
diff --git a/backend/src/graphql/queries/userData.ts b/backend/src/graphql/queries/userData.ts
new file mode 100644
index 000000000..542c7edbb
--- /dev/null
+++ b/backend/src/graphql/queries/userData.ts
@@ -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
+ }
+ }
+ }
+ }
+ }
+`
diff --git a/backend/src/graphql/resolvers/attachments/attachments.spec.ts b/backend/src/graphql/resolvers/attachments/attachments.spec.ts
index 2b4a06a83..805e3a38c 100644
--- a/backend/src/graphql/resolvers/attachments/attachments.spec.ts
+++ b/backend/src/graphql/resolvers/attachments/attachments.spec.ts
@@ -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,
},
diff --git a/backend/src/graphql/resolvers/badges.spec.ts b/backend/src/graphql/resolvers/badges.spec.ts
index 6303ce35b..a351fd2cf 100644
--- a/backend/src/graphql/resolvers/badges.spec.ts
+++ b/backend/src/graphql/resolvers/badges.spec.ts
@@ -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',
diff --git a/backend/src/graphql/resolvers/comments.spec.ts b/backend/src/graphql/resolvers/comments.spec.ts
index 08d18c67c..48923c1b7 100644
--- a/backend/src/graphql/resolvers/comments.spec.ts
+++ b/backend/src/graphql/resolvers/comments.spec.ts
@@ -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',
diff --git a/backend/src/graphql/resolvers/donations.spec.ts b/backend/src/graphql/resolvers/donations.spec.ts
index 8fc23d4e9..a9b8f0eba 100644
--- a/backend/src/graphql/resolvers/donations.spec.ts
+++ b/backend/src/graphql/resolvers/donations.spec.ts
@@ -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()
diff --git a/backend/src/graphql/resolvers/emails.spec.ts b/backend/src/graphql/resolvers/emails.spec.ts
index f77602463..b274fab55 100644
--- a/backend/src/graphql/resolvers/emails.spec.ts
+++ b/backend/src/graphql/resolvers/emails.spec.ts
@@ -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 },
})
})
diff --git a/backend/src/graphql/resolvers/embeds.spec.ts b/backend/src/graphql/resolvers/embeds.spec.ts
index f6de4d13e..82d61275f 100644
--- a/backend/src/graphql/resolvers/embeds.spec.ts
+++ b/backend/src/graphql/resolvers/embeds.spec.ts
@@ -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 })
}
})
diff --git a/backend/src/graphql/resolvers/filter-posts.spec.ts b/backend/src/graphql/resolvers/filter-posts.spec.ts
index 9c1d0a304..8d0064313 100644
--- a/backend/src/graphql/resolvers/filter-posts.spec.ts
+++ b/backend/src/graphql/resolvers/filter-posts.spec.ts
@@ -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'],
diff --git a/backend/src/graphql/resolvers/follow.spec.ts b/backend/src/graphql/resolvers/follow.spec.ts
index e846eb56f..311524caf 100644
--- a/backend/src/graphql/resolvers/follow.spec.ts
+++ b/backend/src/graphql/resolvers/follow.spec.ts
@@ -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,
})
diff --git a/backend/src/graphql/resolvers/groups.spec.ts b/backend/src/graphql/resolvers/groups.spec.ts
index 744503a9d..aaf9eeae9 100644
--- a/backend/src/graphql/resolvers/groups.spec.ts
+++ b/backend/src/graphql/resolvers/groups.spec.ts
@@ -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',
diff --git a/backend/src/graphql/resolvers/inviteCodes.spec.ts b/backend/src/graphql/resolvers/inviteCodes.spec.ts
index fba67147f..f40fd1b27 100644
--- a/backend/src/graphql/resolvers/inviteCodes.spec.ts
+++ b/backend/src/graphql/resolvers/inviteCodes.spec.ts
@@ -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',
diff --git a/backend/src/graphql/resolvers/messages.spec.ts b/backend/src/graphql/resolvers/messages.spec.ts
index 063b9c1f5..f2301fc69 100644
--- a/backend/src/graphql/resolvers/messages.spec.ts
+++ b/backend/src/graphql/resolvers/messages.spec.ts
@@ -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',
},
diff --git a/backend/src/graphql/resolvers/moderation.spec.ts b/backend/src/graphql/resolvers/moderation.spec.ts
index f3224421e..805aba04b 100644
--- a/backend/src/graphql/resolvers/moderation.spec.ts
+++ b/backend/src/graphql/resolvers/moderation.spec.ts
@@ -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 } },
diff --git a/backend/src/graphql/resolvers/notifications.spec.ts b/backend/src/graphql/resolvers/notifications.spec.ts
index cda75bbbc..b12dfd41b 100644
--- a/backend/src/graphql/resolvers/notifications.spec.ts
+++ b/backend/src/graphql/resolvers/notifications.spec.ts
@@ -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([
{
diff --git a/backend/src/graphql/resolvers/observePosts.spec.ts b/backend/src/graphql/resolvers/observePosts.spec.ts
index c4c31d8ea..e183a03ee 100644
--- a/backend/src/graphql/resolvers/observePosts.spec.ts
+++ b/backend/src/graphql/resolvers/observePosts.spec.ts
@@ -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,
diff --git a/backend/src/graphql/resolvers/passwordReset.spec.ts b/backend/src/graphql/resolvers/passwordReset.spec.ts
index e583fc5c5..967164eb3 100644
--- a/backend/src/graphql/resolvers/passwordReset.spec.ts
+++ b/backend/src/graphql/resolvers/passwordReset.spec.ts
@@ -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
diff --git a/backend/src/graphql/resolvers/posts.spec.ts b/backend/src/graphql/resolvers/posts.spec.ts
index e72581119..8cccf3523 100644
--- a/backend/src/graphql/resolvers/posts.spec.ts
+++ b/backend/src/graphql/resolvers/posts.spec.ts
@@ -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))
diff --git a/backend/src/graphql/resolvers/postsInGroups.spec.ts b/backend/src/graphql/resolvers/postsInGroups.spec.ts
index 9222d4e75..26abc6f88 100644
--- a/backend/src/graphql/resolvers/postsInGroups.spec.ts
+++ b/backend/src/graphql/resolvers/postsInGroups.spec.ts
@@ -3,16 +3,15 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Factory, { cleanDatabase } from '@db/factories'
-import { changeGroupMemberRoleMutation } from '@graphql/queries/changeGroupMemberRoleMutation'
-import { createCommentMutation } from '@graphql/queries/createCommentMutation'
-import { createGroupMutation } from '@graphql/queries/createGroupMutation'
-import { createPostMutation } from '@graphql/queries/createPostMutation'
-import { filterPosts } from '@graphql/queries/filterPosts'
-import { leaveGroupMutation } from '@graphql/queries/leaveGroupMutation'
-import { postQuery } from '@graphql/queries/postQuery'
+import { ChangeGroupMemberRole } from '@graphql/queries/ChangeGroupMemberRole'
+import { CreateComment } from '@graphql/queries/CreateComment'
+import { CreateGroup } from '@graphql/queries/CreateGroup'
+import { CreatePost } from '@graphql/queries/CreatePost'
+import { LeaveGroup } from '@graphql/queries/LeaveGroup'
+import { Post } from '@graphql/queries/Post'
import { profilePagePosts } from '@graphql/queries/profilePagePosts'
import { searchPosts } from '@graphql/queries/searchPosts'
-import { signupVerificationMutation } from '@graphql/queries/signupVerificationMutation'
+import { SignupVerification } from '@graphql/queries/SignupVerification'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -93,7 +92,7 @@ describe('Posts in Groups', () => {
authenticatedUser = await publicUser.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'The Public Group',
@@ -104,7 +103,7 @@ describe('Posts in Groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'public-group',
userId: 'pending-user',
@@ -112,7 +111,7 @@ describe('Posts in Groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'public-group',
userId: 'all-groups-user',
@@ -121,7 +120,7 @@ describe('Posts in Groups', () => {
})
authenticatedUser = await closedUser.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'The Closed Group',
@@ -132,7 +131,7 @@ describe('Posts in Groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'pending-user',
@@ -140,7 +139,7 @@ describe('Posts in Groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'all-groups-user',
@@ -149,7 +148,7 @@ describe('Posts in Groups', () => {
})
authenticatedUser = await hiddenUser.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'The Hidden Group',
@@ -160,7 +159,7 @@ describe('Posts in Groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'pending-user',
@@ -168,7 +167,7 @@ describe('Posts in Groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'all-groups-user',
@@ -177,7 +176,7 @@ describe('Posts in Groups', () => {
})
authenticatedUser = await anyUser.toJson()
await mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'post-without-group',
title: 'A post without a group',
@@ -195,7 +194,7 @@ describe('Posts in Groups', () => {
it('throws an error for public groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post to a pubic group',
@@ -211,7 +210,7 @@ describe('Posts in Groups', () => {
it('throws an error for closed groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post to a closed group',
@@ -227,7 +226,7 @@ describe('Posts in Groups', () => {
it('throws an error for hidden groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post to a closed group',
@@ -249,7 +248,7 @@ describe('Posts in Groups', () => {
it('throws an error for public groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post to a pubic group',
@@ -265,7 +264,7 @@ describe('Posts in Groups', () => {
it('throws an error for closed groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post to a closed group',
@@ -281,7 +280,7 @@ describe('Posts in Groups', () => {
it('throws an error for hidden groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'p2',
title: 'A post to a closed group',
@@ -303,7 +302,7 @@ describe('Posts in Groups', () => {
it('creates a post for public groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'post-to-public-group',
title: 'A post to a public group',
@@ -326,7 +325,7 @@ describe('Posts in Groups', () => {
it('creates a post for closed groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'post-to-closed-group',
title: 'A post to a closed group',
@@ -349,7 +348,7 @@ describe('Posts in Groups', () => {
it('creates a post for hidden groups', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
@@ -380,7 +379,7 @@ describe('Posts in Groups', () => {
it('throws an error for public groups', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-public-group',
content:
@@ -395,7 +394,7 @@ describe('Posts in Groups', () => {
it('throws an error for closed groups', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-closed-group',
content:
@@ -410,7 +409,7 @@ describe('Posts in Groups', () => {
it('throws an error for hidden groups', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-hidden-group',
content:
@@ -431,7 +430,7 @@ describe('Posts in Groups', () => {
it('throws an error for public groups', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-public-group',
content: 'I am commenting a post in a public group as a pending member of the group',
@@ -445,7 +444,7 @@ describe('Posts in Groups', () => {
it('throws an error for closed groups', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-closed-group',
content: 'I am commenting a post in a closed group as a pending member of the group',
@@ -459,7 +458,7 @@ describe('Posts in Groups', () => {
it('throws an error for hidden groups', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-hidden-group',
content: 'I am commenting a post in a hidden group as a pending member of the group',
@@ -479,7 +478,7 @@ describe('Posts in Groups', () => {
it('comments a post in a public group', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-public-group',
content: 'I am commenting a post in a public group as a member of the group',
@@ -498,7 +497,7 @@ describe('Posts in Groups', () => {
it('comments a post in a closed group', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-closed-group',
content: 'I am commenting a post in a closed group as a member of the group',
@@ -517,7 +516,7 @@ describe('Posts in Groups', () => {
it('comments a post in a hidden group', async () => {
await expect(
mutate({
- mutation: createCommentMutation,
+ mutation: CreateComment,
variables: {
postId: 'post-to-hidden-group',
content: 'I am commenting a post in a hidden group as a member of the group',
@@ -544,15 +543,15 @@ describe('Posts in Groups', () => {
it('shows a post of the public group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-public-group' } }),
+ query({ query: Post, variables: { id: 'post-to-public-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -561,7 +560,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a closed group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-closed-group' } }),
+ query({ query: Post, variables: { id: 'post-to-closed-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -572,7 +571,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a hidden group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-hidden-group' } }),
+ query({ query: Post, variables: { id: 'post-to-hidden-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -590,7 +589,7 @@ describe('Posts in Groups', () => {
verifiedAt: null,
})
const result = await mutate({
- mutation: signupVerificationMutation,
+ mutation: SignupVerification,
variables: {
name: 'New User',
slug: 'new-user',
@@ -607,15 +606,15 @@ describe('Posts in Groups', () => {
it('shows a post of the public group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-public-group' } }),
+ query({ query: Post, variables: { id: 'post-to-public-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -624,7 +623,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a closed group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-closed-group' } }),
+ query({ query: Post, variables: { id: 'post-to-closed-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -635,7 +634,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a hidden group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-hidden-group' } }),
+ query({ query: Post, variables: { id: 'post-to-hidden-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -652,15 +651,15 @@ describe('Posts in Groups', () => {
it('shows a post of the public group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-public-group' } }),
+ query({ query: Post, variables: { id: 'post-to-public-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -669,7 +668,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a closed group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-closed-group' } }),
+ query({ query: Post, variables: { id: 'post-to-closed-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -680,7 +679,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a hidden group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-hidden-group' } }),
+ query({ query: Post, variables: { id: 'post-to-hidden-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -697,15 +696,15 @@ describe('Posts in Groups', () => {
it('shows a post of the public group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-public-group' } }),
+ query({ query: Post, variables: { id: 'post-to-public-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -714,7 +713,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a closed group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-closed-group' } }),
+ query({ query: Post, variables: { id: 'post-to-closed-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -725,7 +724,7 @@ describe('Posts in Groups', () => {
it('does not show a post of a hidden group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-hidden-group' } }),
+ query({ query: Post, variables: { id: 'post-to-hidden-group' } }),
).resolves.toMatchObject({
data: {
Post: [],
@@ -742,15 +741,15 @@ describe('Posts in Groups', () => {
it('shows post of the public group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-public-group' } }),
+ query({ query: Post, variables: { id: 'post-to-public-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -759,15 +758,15 @@ describe('Posts in Groups', () => {
it('shows post of a closed group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-closed-group' } }),
+ query({ query: Post, variables: { id: 'post-to-closed-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -776,15 +775,15 @@ describe('Posts in Groups', () => {
it('shows post of a hidden group', async () => {
await expect(
- query({ query: postQuery(), variables: { id: 'post-to-hidden-group' } }),
+ query({ query: Post, variables: { id: 'post-to-hidden-group' } }),
).resolves.toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -800,23 +799,23 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(2)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -830,23 +829,23 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(2)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -860,23 +859,23 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(2)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -890,23 +889,23 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(2)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -920,35 +919,35 @@ describe('Posts in Groups', () => {
})
it('shows all posts', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -964,21 +963,21 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: profilePagePosts(), variables: {} })
+ const result = await query({ query: profilePagePosts, variables: {} })
expect(result.data?.profilePagePosts).toHaveLength(2)
expect(result).toMatchObject({
data: {
profilePagePosts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
errors: undefined,
@@ -992,21 +991,21 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: profilePagePosts(), variables: {} })
+ const result = await query({ query: profilePagePosts, variables: {} })
expect(result.data?.profilePagePosts).toHaveLength(2)
expect(result).toMatchObject({
data: {
profilePagePosts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
errors: undefined,
@@ -1020,21 +1019,21 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: profilePagePosts(), variables: {} })
+ const result = await query({ query: profilePagePosts, variables: {} })
expect(result.data?.profilePagePosts).toHaveLength(2)
expect(result).toMatchObject({
data: {
profilePagePosts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
errors: undefined,
@@ -1048,21 +1047,21 @@ describe('Posts in Groups', () => {
})
it('shows the post of the public group and the post without group', async () => {
- const result = await query({ query: profilePagePosts(), variables: {} })
+ const result = await query({ query: profilePagePosts, variables: {} })
expect(result.data?.profilePagePosts).toHaveLength(2)
expect(result).toMatchObject({
data: {
profilePagePosts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
errors: undefined,
@@ -1076,31 +1075,31 @@ describe('Posts in Groups', () => {
})
it('shows all posts', async () => {
- const result = await query({ query: profilePagePosts(), variables: {} })
+ const result = await query({ query: profilePagePosts, variables: {} })
expect(result.data?.profilePagePosts).toHaveLength(4)
expect(result).toMatchObject({
data: {
profilePagePosts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
- },
+ }),
]),
},
errors: undefined,
@@ -1117,7 +1116,7 @@ describe('Posts in Groups', () => {
it('finds nothing', async () => {
const result = await query({
- query: searchPosts(),
+ query: searchPosts,
variables: {
query: 'post',
postsOffset: 0,
@@ -1143,7 +1142,7 @@ describe('Posts in Groups', () => {
it('finds the post of the public group and the post without group', async () => {
const result = await query({
- query: searchPosts(),
+ query: searchPosts,
variables: {
query: 'post',
postsOffset: 0,
@@ -1156,16 +1155,16 @@ describe('Posts in Groups', () => {
searchPosts: {
postCount: 2,
posts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
},
@@ -1180,7 +1179,7 @@ describe('Posts in Groups', () => {
it('finds the post of the public group and the post without group', async () => {
const result = await query({
- query: searchPosts(),
+ query: searchPosts,
variables: {
query: 'post',
postsOffset: 0,
@@ -1193,16 +1192,16 @@ describe('Posts in Groups', () => {
searchPosts: {
postCount: 2,
posts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
},
@@ -1217,7 +1216,7 @@ describe('Posts in Groups', () => {
it('finds the post of the public group and the post without group', async () => {
const result = await query({
- query: searchPosts(),
+ query: searchPosts,
variables: {
query: 'post',
postsOffset: 0,
@@ -1230,16 +1229,16 @@ describe('Posts in Groups', () => {
searchPosts: {
postCount: 2,
posts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
+ }),
]),
},
},
@@ -1254,7 +1253,7 @@ describe('Posts in Groups', () => {
it('finds all posts', async () => {
const result = await query({
- query: searchPosts(),
+ query: searchPosts,
variables: {
query: 'post',
postsOffset: 0,
@@ -1267,26 +1266,26 @@ describe('Posts in Groups', () => {
searchPosts: {
postCount: 4,
posts: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
- },
+ }),
]),
},
},
@@ -1302,7 +1301,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await closedUser.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'pending-user',
@@ -1313,29 +1312,29 @@ describe('Posts in Groups', () => {
})
it('shows the posts of the closed group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(3)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1347,7 +1346,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await hiddenUser.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'pending-user',
@@ -1358,35 +1357,35 @@ describe('Posts in Groups', () => {
})
it('shows all the posts', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1400,7 +1399,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await closedUser.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'pending-user',
@@ -1411,29 +1410,29 @@ describe('Posts in Groups', () => {
})
it('does not show the posts of the closed group anymore', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(3)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1445,7 +1444,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await hiddenUser.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'pending-user',
@@ -1456,23 +1455,23 @@ describe('Posts in Groups', () => {
})
it('shows only the public posts', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(2)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1486,7 +1485,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await allGroupsUser.toJson()
await mutate({
- mutation: leaveGroupMutation(),
+ mutation: LeaveGroup,
variables: {
groupId: 'public-group',
userId: 'all-groups-user',
@@ -1495,35 +1494,35 @@ describe('Posts in Groups', () => {
})
it('still shows the posts of the public group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1535,7 +1534,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await allGroupsUser.toJson()
await mutate({
- mutation: leaveGroupMutation(),
+ mutation: LeaveGroup,
variables: {
groupId: 'closed-group',
userId: 'all-groups-user',
@@ -1544,35 +1543,35 @@ describe('Posts in Groups', () => {
})
it('stil shows the posts of the closed group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1584,7 +1583,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await allGroupsUser.toJson()
await mutate({
- mutation: leaveGroupMutation(),
+ mutation: LeaveGroup,
variables: {
groupId: 'hidden-group',
userId: 'all-groups-user',
@@ -1593,35 +1592,35 @@ describe('Posts in Groups', () => {
})
it('still shows the post of the hidden group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1635,7 +1634,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await closedUser.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'all-groups-user',
@@ -1646,35 +1645,35 @@ describe('Posts in Groups', () => {
})
it('shows the posts of the closed group', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1686,7 +1685,7 @@ describe('Posts in Groups', () => {
beforeAll(async () => {
authenticatedUser = await hiddenUser.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'all-groups-user',
@@ -1697,35 +1696,35 @@ describe('Posts in Groups', () => {
})
it('shows all posts', async () => {
- const result = await query({ query: filterPosts(), variables: {} })
+ const result = await query({ query: Post, variables: {} })
expect(result.data?.Post).toHaveLength(4)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-public-group',
title: 'A post to a public group',
content: 'I am posting into a public group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-without-group',
title: 'A post without a group',
content: 'I am a user who does not belong to a group yet.',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
@@ -1742,7 +1741,7 @@ describe('Posts in Groups', () => {
it('finds no posts', async () => {
const result = await query({
- query: filterPosts(),
+ query: Post,
variables: { filter: { postsInMyGroups: true } },
})
expect(result.data?.Post).toHaveLength(0)
@@ -1763,25 +1762,25 @@ describe('Posts in Groups', () => {
it('finds two posts', async () => {
const result = await query({
- query: filterPosts(),
+ query: Post,
variables: { filter: { postsInMyGroups: true } },
})
expect(result.data?.Post).toHaveLength(2)
expect(result).toMatchObject({
data: {
Post: expect.arrayContaining([
- {
+ expect.objectContaining({
id: 'post-to-closed-group',
title: 'A post to a closed group',
content: 'I am posting into a closed group as a member of the group',
eventStart: null,
- },
- {
+ }),
+ expect.objectContaining({
id: 'post-to-hidden-group',
title: 'A post to a hidden group',
content: 'I am posting into a hidden group as a member of the group',
eventStart: null,
- },
+ }),
]),
},
errors: undefined,
diff --git a/backend/src/graphql/resolvers/registration.spec.ts b/backend/src/graphql/resolvers/registration.spec.ts
index 2f8fbfd4d..a86ea2d64 100644
--- a/backend/src/graphql/resolvers/registration.spec.ts
+++ b/backend/src/graphql/resolvers/registration.spec.ts
@@ -6,6 +6,7 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import EmailAddress from '@db/models/EmailAddress'
import User from '@db/models/User'
+import { Signup } from '@graphql/queries/Signup'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -43,13 +44,6 @@ afterEach(async () => {
})
describe('Signup', () => {
- const mutation = gql`
- mutation ($email: String!, $locale: String!, $inviteCode: String) {
- Signup(email: $email, locale: $locale, inviteCode: $inviteCode) {
- email
- }
- }
- `
beforeEach(() => {
variables = { ...variables, email: 'someuser@example.org', locale: 'de' }
})
@@ -64,7 +58,7 @@ describe('Signup', () => {
})
it('throws AuthorizationError', async () => {
- await expect(mutate({ mutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
@@ -85,7 +79,7 @@ describe('Signup', () => {
})
it('is allowed to signup users by email', async () => {
- await expect(mutate({ mutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
data: { Signup: { email: 'someuser@example.org' } },
errors: undefined,
})
@@ -93,7 +87,7 @@ describe('Signup', () => {
describe('creates a EmailAddress node', () => {
it('with `createdAt` attribute', async () => {
- await mutate({ mutation, variables })
+ await mutate({ mutation: Signup, variables })
const emailAddress = await database.neode.first(
'EmailAddress',
{ email: 'someuser@example.org' },
@@ -107,7 +101,7 @@ describe('Signup', () => {
})
it('with a cryptographic `nonce`', async () => {
- await mutate({ mutation, variables })
+ await mutate({ mutation: Signup, variables })
const emailAddress = await database.neode.first(
'EmailAddress',
{ email: 'someuser@example.org' },
@@ -133,7 +127,7 @@ describe('Signup', () => {
})
it('does not throw UserInputError error', async () => {
- await expect(mutate({ mutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
data: { Signup: { email: 'someuser@example.org' } },
})
})
@@ -141,7 +135,7 @@ describe('Signup', () => {
describe('but the user has not yet registered', () => {
it('resolves with the already existing email', async () => {
- await expect(mutate({ mutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
data: { Signup: { email: 'someuser@example.org' } },
errors: undefined,
})
@@ -150,7 +144,7 @@ describe('Signup', () => {
it('creates no additional `EmailAddress` node', async () => {
// admin account and the already existing user
await expect(database.neode.all('EmailAddress')).resolves.toHaveLength(2)
- await expect(mutate({ mutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
data: { Signup: { email: 'someuser@example.org' } },
errors: undefined,
})
diff --git a/backend/src/graphql/resolvers/reports.spec.ts b/backend/src/graphql/resolvers/reports.spec.ts
index bcbe1df4e..5b51b1073 100644
--- a/backend/src/graphql/resolvers/reports.spec.ts
+++ b/backend/src/graphql/resolvers/reports.spec.ts
@@ -3,10 +3,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 { fileReport } from '@graphql/queries/fileReport'
+import { reports } from '@graphql/queries/reports'
+import { review } from '@graphql/queries/review'
import createServer from '@src/server'
const instance = getNeode()
@@ -15,94 +17,11 @@ const driver = getDriver()
describe('file a report on a resource', () => {
let authenticatedUser, currentUser, mutate, query, moderator, abusiveUser, otherReportingUser
const categoryIds = ['cat9']
- const fileReportMutation = 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
- }
- }
- }
- }
- `
const variables = {
resourceId: 'invalid',
reasonCategory: 'other',
reasonDescription: 'Violates code of conduct !!!',
}
- const reportsQuery = 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
- }
- }
- }
- `
- const reviewMutation = gql`
- mutation ($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
- review(resourceId: $resourceId, disable: $disable, closed: $closed) {
- createdAt
- resource {
- __typename
- ... on User {
- id
- disabled
- }
- ... on Post {
- id
- disabled
- }
- ... on Comment {
- id
- disabled
- }
- }
- report {
- disable
- }
- }
- }
- `
beforeAll(async () => {
await cleanDatabase()
@@ -134,7 +53,7 @@ describe('file a report on a resource', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
- await expect(mutate({ mutation: fileReportMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: fileReport, variables })).resolves.toMatchObject({
data: { fileReport: null },
errors: [{ message: 'Not Authorized!' }],
})
@@ -198,7 +117,7 @@ describe('file a report on a resource', () => {
describe('invalid resource id', () => {
it('returns null', async () => {
- await expect(mutate({ mutation: fileReportMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: fileReport, variables })).resolves.toMatchObject({
data: { fileReport: null },
errors: undefined,
})
@@ -210,7 +129,7 @@ describe('file a report on a resource', () => {
it('which belongs to resource', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
}),
).resolves.toMatchObject({
@@ -228,12 +147,12 @@ describe('file a report on a resource', () => {
it('only one report for multiple reports on the same resource', async () => {
const firstReport = await mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
})
authenticatedUser = await otherReportingUser.toJson()
const secondReport = await mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
})
@@ -248,7 +167,7 @@ describe('file a report on a resource', () => {
it('with the rule for how the report will be decided', async () => {
await mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
})
@@ -266,7 +185,7 @@ describe('file a report on a resource', () => {
describe('with overtaken disabled from resource in disable property', () => {
it('disable is false', async () => {
await mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
})
@@ -284,12 +203,12 @@ describe('file a report on a resource', () => {
it('disable is true', async () => {
// first time filling a report to enable a moderator the disable the resource
await mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
})
authenticatedUser = await moderator.toJson()
await mutate({
- mutation: reviewMutation,
+ mutation: review,
variables: {
resourceId: 'abusive-user-id',
disable: true,
@@ -299,7 +218,7 @@ describe('file a report on a resource', () => {
authenticatedUser = await currentUser.toJson()
// second time filling a report to see if the "disable is true" of the resource is overtaken
await mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
})
@@ -323,7 +242,7 @@ describe('file a report on a resource', () => {
it('returns __typename "User"', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
}),
).resolves.toMatchObject({
@@ -341,7 +260,7 @@ describe('file a report on a resource', () => {
it('returns user attribute info', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
}),
).resolves.toMatchObject({
@@ -360,7 +279,7 @@ describe('file a report on a resource', () => {
it('returns a createdAt', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: { ...variables, resourceId: 'abusive-user-id' },
}),
).resolves.toMatchObject({
@@ -376,7 +295,7 @@ describe('file a report on a resource', () => {
it('returns the reason category', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'abusive-user-id',
@@ -396,7 +315,7 @@ describe('file a report on a resource', () => {
it('gives an error if the reason category is not in enum "ReasonCategory"', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'abusive-user-id',
@@ -417,7 +336,7 @@ describe('file a report on a resource', () => {
it('returns the reason description', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'abusive-user-id',
@@ -437,7 +356,7 @@ describe('file a report on a resource', () => {
it('sanitizes the reason description', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'abusive-user-id',
@@ -473,7 +392,7 @@ describe('file a report on a resource', () => {
it('returns type "Post"', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'post-to-report-id',
@@ -494,7 +413,7 @@ describe('file a report on a resource', () => {
it('returns resource in post attribute', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'post-to-report-id',
@@ -544,7 +463,7 @@ describe('file a report on a resource', () => {
it('returns type "Comment"', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'comment-to-report-id',
@@ -565,7 +484,7 @@ describe('file a report on a resource', () => {
it('returns resource in comment attribute', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'comment-to-report-id',
@@ -595,7 +514,7 @@ describe('file a report on a resource', () => {
it('returns null', async () => {
await expect(
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
...variables,
resourceId: 'tag-to-report-id',
@@ -703,7 +622,7 @@ describe('file a report on a resource', () => {
authenticatedUser = await currentUser.toJson()
await Promise.all([
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
resourceId: 'abusive-post-1',
reasonCategory: 'other',
@@ -711,7 +630,7 @@ describe('file a report on a resource', () => {
},
}),
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
resourceId: 'abusive-comment-1',
reasonCategory: 'discrimination_etc',
@@ -719,7 +638,7 @@ describe('file a report on a resource', () => {
},
}),
mutate({
- mutation: fileReportMutation,
+ mutation: fileReport,
variables: {
resourceId: 'abusive-user-1',
reasonCategory: 'doxing',
@@ -733,7 +652,7 @@ describe('file a report on a resource', () => {
describe('unauthenticated', () => {
it('throws authorization error', async () => {
authenticatedUser = null
- await expect(query({ query: reportsQuery })).resolves.toMatchObject({
+ await expect(query({ query: reports })).resolves.toMatchObject({
data: { reports: null },
errors: [{ message: 'Not Authorized!' }],
})
@@ -743,7 +662,7 @@ describe('file a report on a resource', () => {
describe('authenticated', () => {
it('role "user" gets no reports', async () => {
authenticatedUser = await currentUser.toJson()
- await expect(query({ query: reportsQuery })).resolves.toMatchObject({
+ await expect(query({ query: reports })).resolves.toMatchObject({
data: { reports: null },
errors: [{ message: 'Not Authorized!' }],
})
@@ -815,7 +734,7 @@ describe('file a report on a resource', () => {
]),
}
authenticatedUser = await moderator.toJson()
- const { data } = await query({ query: reportsQuery })
+ const { data } = await query({ query: reports })
expect(data).toEqual(expected)
})
})
diff --git a/backend/src/graphql/resolvers/rooms.spec.ts b/backend/src/graphql/resolvers/rooms.spec.ts
index 64f390780..5998eb598 100644
--- a/backend/src/graphql/resolvers/rooms.spec.ts
+++ b/backend/src/graphql/resolvers/rooms.spec.ts
@@ -4,9 +4,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import Factory, { cleanDatabase } from '@db/factories'
import { CreateMessage } from '@graphql/queries/CreateMessage'
-import { createRoomMutation } from '@graphql/queries/createRoomMutation'
-import { roomQuery } from '@graphql/queries/roomQuery'
-import { unreadRoomsQuery } from '@graphql/queries/unreadRoomsQuery'
+import { CreateRoom } from '@graphql/queries/CreateRoom'
+import { Room } from '@graphql/queries/Room'
+import { UnreadRooms } from '@graphql/queries/UnreadRooms'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -72,7 +72,7 @@ describe('Room', () => {
it('throws authorization error', async () => {
await expect(
mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'some-id',
},
@@ -92,7 +92,7 @@ describe('Room', () => {
it('returns null', async () => {
await expect(
mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'not-existing-user',
},
@@ -110,7 +110,7 @@ describe('Room', () => {
it('throws error', async () => {
await expect(
mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'chatting-user',
},
@@ -124,7 +124,7 @@ describe('Room', () => {
describe('user id exists', () => {
it('returns the id of the room', async () => {
const result = await mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'other-chatting-user',
},
@@ -166,7 +166,7 @@ describe('Room', () => {
it('returns the id of the room', async () => {
await expect(
mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'other-chatting-user',
},
@@ -191,7 +191,7 @@ describe('Room', () => {
})
it('throws authorization error', async () => {
- await expect(query({ query: roomQuery() })).resolves.toMatchObject({
+ await expect(query({ query: Room })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
@@ -204,7 +204,7 @@ describe('Room', () => {
})
it('returns the room', async () => {
- const result = await query({ query: roomQuery() })
+ const result = await query({ query: Room })
expect(result).toMatchObject({
errors: undefined,
data: {
@@ -244,7 +244,7 @@ describe('Room', () => {
})
it('returns the room', async () => {
- const result = await query({ query: roomQuery() })
+ const result = await query({ query: Room })
expect(result).toMatchObject({
errors: undefined,
data: {
@@ -285,7 +285,7 @@ describe('Room', () => {
})
it('returns no rooms', async () => {
- await expect(query({ query: roomQuery() })).resolves.toMatchObject({
+ await expect(query({ query: Room })).resolves.toMatchObject({
errors: undefined,
data: {
Room: [],
@@ -302,7 +302,7 @@ describe('Room', () => {
authenticatedUser = null
await expect(
query({
- query: unreadRoomsQuery(),
+ query: UnreadRooms,
}),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
@@ -316,7 +316,7 @@ describe('Room', () => {
beforeAll(async () => {
authenticatedUser = await chattingUser.toJson()
const result = await mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'not-chatting-user',
},
@@ -345,7 +345,7 @@ describe('Room', () => {
})
authenticatedUser = await otherChattingUser.toJson()
const result2 = await mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'not-chatting-user',
},
@@ -365,7 +365,7 @@ describe('Room', () => {
authenticatedUser = await chattingUser.toJson()
await expect(
query({
- query: unreadRoomsQuery(),
+ query: UnreadRooms,
}),
).resolves.toMatchObject({
data: {
@@ -380,7 +380,7 @@ describe('Room', () => {
authenticatedUser = await otherChattingUser.toJson()
await expect(
query({
- query: unreadRoomsQuery(),
+ query: UnreadRooms,
}),
).resolves.toMatchObject({
data: {
@@ -394,7 +394,7 @@ describe('Room', () => {
await otherChattingUser.relateTo(chattingUser, 'blocked')
await expect(
query({
- query: unreadRoomsQuery(),
+ query: UnreadRooms,
}),
).resolves.toMatchObject({
data: {
@@ -408,7 +408,7 @@ describe('Room', () => {
await otherChattingUser.relateTo(chattingUser, 'muted')
await expect(
query({
- query: unreadRoomsQuery(),
+ query: UnreadRooms,
}),
).resolves.toMatchObject({
data: {
@@ -423,7 +423,7 @@ describe('Room', () => {
authenticatedUser = await notChattingUser.toJson()
await expect(
query({
- query: unreadRoomsQuery(),
+ query: UnreadRooms,
}),
).resolves.toMatchObject({
data: {
@@ -439,13 +439,13 @@ describe('Room', () => {
beforeAll(async () => {
authenticatedUser = await chattingUser.toJson()
await mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'second-chatting-user',
},
})
await mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'third-chatting-user',
},
@@ -454,7 +454,7 @@ describe('Room', () => {
it('returns the rooms paginated', async () => {
await expect(
- query({ query: roomQuery(), variables: { first: 3, offset: 0 } }),
+ query({ query: Room, variables: { first: 3, offset: 0 } }),
).resolves.toMatchObject({
errors: undefined,
data: {
@@ -552,7 +552,7 @@ describe('Room', () => {
},
})
await expect(
- query({ query: roomQuery(), variables: { first: 3, offset: 3 } }),
+ query({ query: Room, variables: { first: 3, offset: 3 } }),
).resolves.toMatchObject({
errors: undefined,
data: {
@@ -591,14 +591,14 @@ describe('Room', () => {
beforeAll(async () => {
authenticatedUser = await chattingUser.toJson()
- result = await query({ query: roomQuery() })
+ result = await query({ query: Room })
})
describe('as chatter of room', () => {
it('returns the room', async () => {
expect(
await query({
- query: roomQuery(),
+ query: Room,
variables: { first: 2, offset: 0, id: result.data.Room[0].id },
}),
).toMatchObject({
@@ -625,7 +625,7 @@ describe('Room', () => {
authenticatedUser = await notChattingUser.toJson()
expect(
await query({
- query: roomQuery(),
+ query: Room,
variables: { first: 2, offset: 0, id: result.data.Room[0].id },
}),
).toMatchObject({
diff --git a/backend/src/graphql/resolvers/searches.spec.ts b/backend/src/graphql/resolvers/searches.spec.ts
index 8a94fbf21..0c515c610 100644
--- a/backend/src/graphql/resolvers/searches.spec.ts
+++ b/backend/src/graphql/resolvers/searches.spec.ts
@@ -6,6 +6,7 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getNeode, getDriver } from '@db/neo4j'
+import { searchResults } from '@graphql/queries/searchResults'
import createServer from '@src/server'
let query, authenticatedUser, user
@@ -33,28 +34,6 @@ afterAll(async () => {
await driver.close()
neode.close()
})
-
-const searchQuery = gql`
- query ($query: String!) {
- searchResults(query: $query, limit: 5) {
- __typename
- ... on Post {
- id
- title
- content
- }
- ... on User {
- id
- slug
- name
- }
- ... on Tag {
- id
- }
- }
- }
-`
-
const searchPostQuery = gql`
query ($query: String!, $firstPosts: Int, $postsOffset: Int) {
searchPosts(query: $query, firstPosts: $firstPosts, postsOffset: $postsOffset) {
@@ -85,7 +64,7 @@ describe('resolvers/searches', () => {
describe('query contains first name of user', () => {
it('finds the user', async () => {
variables = { query: 'John' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -115,7 +94,7 @@ describe('resolvers/searches', () => {
describe('query contains title of post', () => {
it('finds the post', async () => {
variables = { query: 'beitrag' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -134,7 +113,7 @@ describe('resolvers/searches', () => {
describe('casing', () => {
it('does not matter', async () => {
variables = { query: 'BEITRAG' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -153,7 +132,7 @@ describe('resolvers/searches', () => {
describe('query consists of words not present in the corpus', () => {
it('returns empty search results', async () => {
await expect(
- query({ query: searchQuery, variables: { query: 'Unfug' } }),
+ query({ query: searchResults, variables: { query: 'Unfug' } }),
).resolves.toMatchObject({ data: { searchResults: [] } })
})
})
@@ -209,7 +188,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query contains the title of the first post', () => {
it('finds both posts', async () => {
variables = { query: 'beitrag' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.arrayContaining([
{
@@ -236,7 +215,7 @@ und hinter tausend Stäben keine Welt.`,
describe('hyphens in query', () => {
it('will be treated as ordinary characters', async () => {
variables = { query: 'tee-ei' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -255,7 +234,7 @@ und hinter tausend Stäben keine Welt.`,
describe('German quotation marks in query to test unicode characters (\u201E ... \u201C)', () => {
it('will be treated as ordinary characters', async () => {
variables = { query: '„teeei“' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -276,7 +255,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query a part of the mathematical expression', () => {
it('finds that post', async () => {
variables = { query: '(a - b)²' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -297,7 +276,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query the same part of the mathematical expression without spaces', () => {
it('finds that post', async () => {
variables = { query: '(a-b)²' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -318,7 +297,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query the mathematical expression over line break', () => {
it('finds that post', async () => {
variables = { query: '+ b² 2.' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -341,7 +320,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query for more than one word, e.g. the title of the poem', () => {
it('finds the poem and another post that contains only one word but with lower score', async () => {
variables = { query: 'der panther' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
@@ -369,7 +348,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query for the first four letters of two longer words', () => {
it('finds the posts that contain words starting with these four letters', async () => {
variables = { query: 'Vorü Subs' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.arrayContaining([
{
@@ -415,7 +394,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query the word that both slugs contain', () => {
it('finds both users', async () => {
variables = { query: '-maria-' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.arrayContaining([
{
@@ -453,7 +432,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query the word that contains the post, the hashtag and the name of the user', () => {
it('finds the user, the post and the hashtag', async () => {
variables = { query: 'panther' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.arrayContaining([
{
@@ -485,7 +464,7 @@ und hinter tausend Stäben keine Welt.`,
describe('@query the word that contains the post, the hashtag and the name of the user', () => {
it('only finds the user', async () => {
variables = { query: '@panther' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.not.arrayContaining([
{
@@ -511,7 +490,7 @@ und hinter tausend Stäben keine Welt.`,
describe('!query the word that contains the post, the hashtag and the name of the user', () => {
it('only finds the post', async () => {
variables = { query: '!panther' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.not.arrayContaining([
{
@@ -534,7 +513,7 @@ und hinter tausend Stäben keine Welt.`,
describe('#query the word that contains the post, the hashtag and the name of the user', () => {
it('only finds the hashtag', async () => {
variables = { query: '#panther' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.not.arrayContaining([
{
@@ -582,7 +561,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query for text in a post written by a muted user', () => {
it('does not include the post of the muted user in the results', async () => {
variables = { query: 'beitrag' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: expect.not.arrayContaining([
{
@@ -607,7 +586,7 @@ und hinter tausend Stäben keine Welt.`,
describe('query the first four characters of the tag', () => {
it('finds the tag', async () => {
variables = { query: 'myha' }
- await expect(query({ query: searchQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: searchResults, variables })).resolves.toMatchObject({
data: {
searchResults: [
{
diff --git a/backend/src/graphql/resolvers/shout.spec.ts b/backend/src/graphql/resolvers/shout.spec.ts
index 9023284c6..d3a34638c 100644
--- a/backend/src/graphql/resolvers/shout.spec.ts
+++ b/backend/src/graphql/resolvers/shout.spec.ts
@@ -7,22 +7,13 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getNeode, getDriver } from '@db/neo4j'
+import { shout } from '@graphql/queries/shout'
+import { unshout } from '@graphql/queries/unshout'
import createServer from '@src/server'
let mutate, query, authenticatedUser, variables
const instance = getNeode()
const driver = getDriver()
-
-const mutationShoutPost = gql`
- mutation ($id: ID!) {
- shout(id: $id, type: Post)
- }
-`
-const mutationUnshoutPost = gql`
- mutation ($id: ID!) {
- unshout(id: $id, type: Post)
- }
-`
const queryPost = gql`
query ($id: ID!) {
Post(id: $id) {
@@ -95,7 +86,7 @@ describe('shout and unshout posts', () => {
it('throws authorization error', async () => {
variables = { id: 'post-to-shout-id' }
authenticatedUser = undefined
- await expect(mutate({ mutation: mutationShoutPost, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: shout, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
@@ -128,7 +119,7 @@ describe('shout and unshout posts', () => {
it("can shout another user's post", async () => {
variables = { id: 'another-user-post-id' }
- await expect(mutate({ mutation: mutationShoutPost, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: shout, variables })).resolves.toMatchObject({
data: { shout: true },
})
await expect(query({ query: queryPost, variables })).resolves.toMatchObject({
@@ -139,7 +130,7 @@ describe('shout and unshout posts', () => {
it('adds `createdAt` to `SHOUT` relationship', async () => {
variables = { id: 'another-user-post-id' }
- await mutate({ mutation: mutationShoutPost, variables })
+ await mutate({ mutation: shout, variables })
const relation = await instance.cypher(
'MATCH (user:User {id: $userId1})-[relationship:SHOUTED]->(node {id: $userId2}) WHERE relationship.createdAt IS NOT NULL RETURN relationship',
{
@@ -155,7 +146,7 @@ describe('shout and unshout posts', () => {
it('can not shout my own post', async () => {
variables = { id: 'current-user-post-id' }
- await expect(mutate({ mutation: mutationShoutPost, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: shout, variables })).resolves.toMatchObject({
data: { shout: false },
})
await expect(query({ query: queryPost, variables })).resolves.toMatchObject({
@@ -170,7 +161,7 @@ describe('shout and unshout posts', () => {
it('throws authorization error', async () => {
authenticatedUser = undefined
variables = { id: 'post-to-shout-id' }
- await expect(mutate({ mutation: mutationUnshoutPost, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: unshout, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
})
})
@@ -190,14 +181,14 @@ describe('shout and unshout posts', () => {
},
)
await mutate({
- mutation: mutationShoutPost,
+ mutation: shout,
variables: { id: 'posted-by-another-user' },
})
})
it("can unshout another user's post", async () => {
variables = { id: 'posted-by-another-user' }
- await expect(mutate({ mutation: mutationUnshoutPost, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: unshout, variables })).resolves.toMatchObject({
data: { unshout: true },
})
await expect(query({ query: queryPost, variables })).resolves.toMatchObject({
diff --git a/backend/src/graphql/resolvers/socialMedia.spec.ts b/backend/src/graphql/resolvers/socialMedia.spec.ts
index 168360a3b..0ef4a1e18 100644
--- a/backend/src/graphql/resolvers/socialMedia.spec.ts
+++ b/backend/src/graphql/resolvers/socialMedia.spec.ts
@@ -8,6 +8,8 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getDriver } from '@db/neo4j'
+import { DeleteSocialMedia } from '@graphql/queries/DeleteSocialMedia'
+import { UpdateSocialMedia } from '@graphql/queries/UpdateSocialMedia'
import createServer from '@src/server'
const driver = getDriver()
@@ -172,26 +174,17 @@ describe('SocialMedia', () => {
})
describe('update social media', () => {
- let mutation, variables
+ let variables
beforeEach(async () => {
const socialMedia = await setUpSocialMedia()
-
- mutation = gql`
- mutation ($id: ID!, $url: String!) {
- UpdateSocialMedia(id: $id, url: $url) {
- id
- url
- }
- }
- `
variables = { url: newUrl, id: socialMedia.id }
})
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const user = null
- const result = await socialMediaAction(user, mutation, variables)
+ const result = await socialMediaAction(user, UpdateSocialMedia, variables)
expect(result.errors[0]).toHaveProperty('message', 'Not Authorized!')
})
@@ -200,7 +193,7 @@ describe('SocialMedia', () => {
describe('authenticated as other user', () => {
it('throws authorization error', async () => {
const user = someUser
- const result = await socialMediaAction(user, mutation, variables)
+ const result = await socialMediaAction(user, UpdateSocialMedia, variables)
expect(result.errors[0]).toHaveProperty('message', 'Not Authorized!')
})
@@ -220,14 +213,14 @@ describe('SocialMedia', () => {
},
}
- await expect(socialMediaAction(user, mutation, variables)).resolves.toEqual(
+ await expect(socialMediaAction(user, UpdateSocialMedia, variables)).resolves.toEqual(
expect.objectContaining(expected),
)
})
it('does not update if the the given id does not exist', async () => {
variables.id = 'some-id'
- const result = await socialMediaAction(user, mutation, variables)
+ const result = await socialMediaAction(user, UpdateSocialMedia, variables)
expect(result.errors[0]).toHaveProperty('message', 'Not Authorized!')
})
@@ -235,26 +228,17 @@ describe('SocialMedia', () => {
})
describe('delete social media', () => {
- let mutation, variables
+ let variables
beforeEach(async () => {
const socialMedia = await setUpSocialMedia()
-
- mutation = gql`
- mutation ($id: ID!) {
- DeleteSocialMedia(id: $id) {
- id
- url
- }
- }
- `
variables = { url: newUrl, id: socialMedia.id }
})
describe('unauthenticated', () => {
it('throws authorization error', async () => {
const user = null
- const result = await socialMediaAction(user, mutation, variables)
+ const result = await socialMediaAction(user, DeleteSocialMedia, variables)
expect(result.errors[0]).toHaveProperty('message', 'Not Authorized!')
})
@@ -263,7 +247,7 @@ describe('SocialMedia', () => {
describe('authenticated as other user', () => {
it('throws authorization error', async () => {
const user = someUser
- const result = await socialMediaAction(user, mutation, variables)
+ const result = await socialMediaAction(user, DeleteSocialMedia, variables)
expect(result.errors[0]).toHaveProperty('message', 'Not Authorized!')
})
@@ -286,7 +270,7 @@ describe('SocialMedia', () => {
},
}
- await expect(socialMediaAction(user, mutation, variables)).resolves.toEqual(
+ await expect(socialMediaAction(user, DeleteSocialMedia, variables)).resolves.toEqual(
expect.objectContaining(expected),
)
})
diff --git a/backend/src/graphql/resolvers/userData.spec.ts b/backend/src/graphql/resolvers/userData.spec.ts
index 17f1f4446..8427dd964 100644
--- a/backend/src/graphql/resolvers/userData.spec.ts
+++ b/backend/src/graphql/resolvers/userData.spec.ts
@@ -2,10 +2,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 { userData } from '@graphql/queries/userData'
import createServer from '@src/server'
let query, authenticatedUser
@@ -13,29 +13,6 @@ let query, authenticatedUser
const driver = getDriver()
const neode = getNeode()
-const userDataQuery = gql`
- query ($id: ID!) {
- userData(id: $id) {
- user {
- id
- name
- slug
- }
- posts {
- id
- title
- content
- comments {
- content
- author {
- slug
- }
- }
- }
- }
- }
-`
-
beforeAll(async () => {
await cleanDatabase()
@@ -72,7 +49,7 @@ describe('resolvers/userData', () => {
describe('given one authenticated user who did not write anything so far', () => {
it("returns the user's data and no posts", async () => {
- await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: userData, variables })).resolves.toMatchObject({
data: {
userData: {
user: {
@@ -100,7 +77,7 @@ describe('resolvers/userData', () => {
})
it("returns the user's data and the post", async () => {
- await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: userData, variables })).resolves.toMatchObject({
data: {
userData: {
user: {
@@ -125,7 +102,7 @@ describe('resolvers/userData', () => {
describe('try to request data of another user', () => {
variables = { id: 'o-user' }
it('returns the data of the authenticated user', async () => {
- await expect(query({ query: userDataQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: userData, variables })).resolves.toMatchObject({
data: {
userData: {
user: {
diff --git a/backend/src/graphql/resolvers/user_management.spec.ts b/backend/src/graphql/resolvers/user_management.spec.ts
index 8712685a8..f272e9fba 100644
--- a/backend/src/graphql/resolvers/user_management.spec.ts
+++ b/backend/src/graphql/resolvers/user_management.spec.ts
@@ -11,7 +11,9 @@ import { verify } from 'jsonwebtoken'
import { categories } from '@constants/categories'
import Factory, { cleanDatabase } from '@db/factories'
-import { loginMutation } from '@graphql/queries/loginMutation'
+import { changePassword } from '@graphql/queries/changePassword'
+import { login } from '@graphql/queries/login'
+import { saveCategorySettings } from '@graphql/queries/saveCategorySettings'
import { decode } from '@jwt/decode'
import { encode } from '@jwt/encode'
import type { ApolloTestSetup } from '@root/test/helpers'
@@ -201,11 +203,6 @@ describe('currentUser', () => {
})
describe('with categories saved for current user', () => {
- const saveCategorySettings = gql`
- mutation ($activeCategories: [String]) {
- saveCategorySettings(activeCategories: $activeCategories)
- }
- `
beforeEach(async () => {
await mutate({
mutation: saveCategorySettings,
@@ -229,7 +226,7 @@ describe('currentUser', () => {
describe('login', () => {
const respondsWith = async (expected) => {
- await expect(mutate({ mutation: loginMutation, variables })).resolves.toMatchObject(expected)
+ await expect(mutate({ mutation: login, variables })).resolves.toMatchObject(expected)
}
beforeEach(async () => {
@@ -248,7 +245,7 @@ describe('login', () => {
it('responds with a JWT bearer token', async () => {
const {
data: { login: token },
- } = (await mutate({ mutation: loginMutation, variables })) as any // eslint-disable-line @typescript-eslint/no-explicit-any
+ } = (await mutate({ mutation: login, variables })) as any // eslint-disable-line @typescript-eslint/no-explicit-any
jwt.verify(token, config.JWT_SECRET, (err, data) => {
expect(data).toMatchObject({
id: 'acb2d923-f3af-479e-9f00-61b12e864666',
@@ -341,16 +338,8 @@ describe('login', () => {
})
describe('change password', () => {
- const changePasswordMutation = gql`
- mutation ($oldPassword: String!, $newPassword: String!) {
- changePassword(oldPassword: $oldPassword, newPassword: $newPassword)
- }
- `
-
const respondsWith = async (expected) => {
- await expect(mutate({ mutation: changePasswordMutation, variables })).resolves.toMatchObject(
- expected,
- )
+ await expect(mutate({ mutation: changePassword, variables })).resolves.toMatchObject(expected)
}
beforeEach(async () => {
diff --git a/backend/src/graphql/resolvers/users.spec.ts b/backend/src/graphql/resolvers/users.spec.ts
index 87f947620..93e6be4c6 100644
--- a/backend/src/graphql/resolvers/users.spec.ts
+++ b/backend/src/graphql/resolvers/users.spec.ts
@@ -9,7 +9,12 @@ import { categories } from '@constants/categories'
import pubsubContext from '@context/pubsub'
import Factory, { cleanDatabase } from '@db/factories'
import User from '@db/models/User'
+import { DeleteUser } from '@graphql/queries/DeleteUser'
+import { resetTrophyBadgesSelected } from '@graphql/queries/resetTrophyBadgesSelected'
+import { saveCategorySettings } from '@graphql/queries/saveCategorySettings'
import { setTrophyBadgeSelected } from '@graphql/queries/setTrophyBadgeSelected'
+import { switchUserRole } from '@graphql/queries/switchUserRole'
+import { updateOnlineStatus } from '@graphql/queries/updateOnlineStatus'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -31,74 +36,6 @@ let query: ApolloTestSetup['query']
let database: ApolloTestSetup['database']
let server: ApolloTestSetup['server']
-const deleteUserMutation = 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
- }
- }
- }
-`
-const switchUserRoleMutation = gql`
- mutation ($role: UserRole!, $id: ID!) {
- switchUserRole(role: $role, id: $id) {
- name
- role
- id
- updatedAt
- email
- }
- }
-`
-
-const saveCategorySettings = gql`
- mutation ($activeCategories: [String]) {
- saveCategorySettings(activeCategories: $activeCategories)
- }
-`
-
-const updateOnlineStatus = gql`
- mutation ($status: OnlineStatus!) {
- updateOnlineStatus(status: $status)
- }
-`
-
-const resetTrophyBadgesSelected = gql`
- mutation {
- resetTrophyBadgesSelected {
- badgeTrophiesCount
- badgeTrophiesSelected {
- id
- isDefault
- }
- badgeTrophiesUnused {
- id
- }
- badgeTrophiesUnusedCount
- }
- }
-`
-
beforeAll(async () => {
await cleanDatabase()
const apolloSetup = createApolloTestSetup({ context })
@@ -480,7 +417,7 @@ describe('Delete a User as admin', () => {
},
errors: undefined,
}
- await expect(mutate({ mutation: deleteUserMutation, variables })).resolves.toMatchObject(
+ await expect(mutate({ mutation: DeleteUser, variables })).resolves.toMatchObject(
expectedResponse,
)
})
@@ -526,9 +463,9 @@ describe('Delete a User as admin', () => {
},
errors: undefined,
}
- await expect(
- mutate({ mutation: deleteUserMutation, variables }),
- ).resolves.toMatchObject(expectedResponse)
+ await expect(mutate({ mutation: DeleteUser, variables })).resolves.toMatchObject(
+ expectedResponse,
+ )
})
})
})
@@ -536,7 +473,7 @@ describe('Delete a User as admin', () => {
describe('connected `EmailAddress` nodes', () => {
it('will be removed completely', async () => {
await expect(database.neode.all('EmailAddress')).resolves.toHaveLength(2)
- await mutate({ mutation: deleteUserMutation, variables })
+ await mutate({ mutation: DeleteUser, variables })
await expect(database.neode.all('EmailAddress')).resolves.toHaveLength(1)
})
@@ -550,7 +487,7 @@ describe('Delete a User as admin', () => {
it('will be removed completely', async () => {
await expect(database.neode.all('SocialMedia')).resolves.toHaveLength(1)
- await mutate({ mutation: deleteUserMutation, variables })
+ await mutate({ mutation: DeleteUser, variables })
await expect(database.neode.all('SocialMedia')).resolves.toHaveLength(0)
})
})
@@ -579,7 +516,7 @@ describe('Delete a User as admin', () => {
)
const relations = relation.records.map((record) => record.get('relationship'))
expect(relations).toHaveLength(2)
- await mutate({ mutation: deleteUserMutation, variables })
+ await mutate({ mutation: DeleteUser, variables })
const relation2 = await database.neode.cypher(
'MATCH (user:User {id: $id})-[relationship:FOLLOWS]-(:User) RETURN relationship',
{ id: (await user.toJson()).id },
@@ -611,7 +548,7 @@ describe('switch user role', () => {
id: 'user',
role: 'admin',
}
- await expect(mutate({ mutation: switchUserRoleMutation, variables })).resolves.toEqual(
+ await expect(mutate({ mutation: switchUserRole, variables })).resolves.toEqual(
expect.objectContaining({
errors: [
expect.objectContaining({
@@ -630,7 +567,7 @@ describe('switch user role', () => {
id: 'user',
role: 'moderator',
}
- await expect(mutate({ mutation: switchUserRoleMutation, variables })).resolves.toEqual(
+ await expect(mutate({ mutation: switchUserRole, variables })).resolves.toEqual(
expect.objectContaining({
data: {
switchUserRole: expect.objectContaining({
@@ -647,7 +584,7 @@ describe('switch user role', () => {
id: 'admin',
role: 'moderator',
}
- await expect(mutate({ mutation: switchUserRoleMutation, variables })).resolves.toEqual(
+ await expect(mutate({ mutation: switchUserRole, variables })).resolves.toEqual(
expect.objectContaining({
errors: [
expect.objectContaining({
diff --git a/backend/src/graphql/resolvers/users/location.spec.ts b/backend/src/graphql/resolvers/users/location.spec.ts
index a8349c2e8..11ed0de10 100644
--- a/backend/src/graphql/resolvers/users/location.spec.ts
+++ b/backend/src/graphql/resolvers/users/location.spec.ts
@@ -4,6 +4,7 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
+import { queryLocations } from '@graphql/queries/queryLocations'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -25,14 +26,6 @@ const updateUserMutation = gql`
}
}
`
-const queryLocations = gql`
- query ($place: String!, $lang: String!) {
- queryLocations(place: $place, lang: $lang) {
- place_name
- id
- }
- }
-`
const newlyCreatedNodesWithLocales = [
{
city: {
diff --git a/backend/src/graphql/resolvers/users/mutedUsers.spec.ts b/backend/src/graphql/resolvers/users/mutedUsers.spec.ts
index ccb6d2a87..b7b5494fa 100644
--- a/backend/src/graphql/resolvers/users/mutedUsers.spec.ts
+++ b/backend/src/graphql/resolvers/users/mutedUsers.spec.ts
@@ -7,6 +7,9 @@ import gql from 'graphql-tag'
import { cleanDatabase } from '@db/factories'
import { getNeode, getDriver } from '@db/neo4j'
+import { mutedUsers } from '@graphql/queries/mutedUsers'
+import { muteUser } from '@graphql/queries/muteUser'
+import { unmuteUser } from '@graphql/queries/unmuteUser'
import createServer from '@src/server'
const driver = getDriver()
@@ -48,22 +51,9 @@ afterEach(async () => {
})
describe('mutedUsers', () => {
- let mutedUserQuery
- beforeEach(() => {
- mutedUserQuery = gql`
- query {
- mutedUsers {
- id
- name
- isMuted
- }
- }
- `
- })
-
it('throws permission error', async () => {
const { query } = createTestClient(server)
- const result = await query({ query: mutedUserQuery })
+ const result = await query({ query: mutedUsers })
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(result.errors![0]).toHaveProperty('message', 'Not Authorized!')
})
@@ -84,7 +74,7 @@ describe('mutedUsers', () => {
it('returns a list of muted users', async () => {
const { query } = createTestClient(server)
- await expect(query({ query: mutedUserQuery })).resolves.toEqual(
+ await expect(query({ query: mutedUsers })).resolves.toEqual(
expect.objectContaining({
data: {
mutedUsers: [
@@ -108,16 +98,7 @@ describe('muteUser', () => {
currentUser = undefined
muteAction = (variables) => {
const { mutate } = createTestClient(server)
- const muteUserMutation = gql`
- mutation ($id: ID!) {
- muteUser(id: $id) {
- id
- name
- isMuted
- }
- }
- `
- return mutate({ mutation: muteUserMutation, variables })
+ return mutate({ mutation: muteUser, variables })
}
})
@@ -325,16 +306,7 @@ describe('unmuteUser', () => {
currentUser = undefined
unmuteAction = (variables) => {
const { mutate } = createTestClient(server)
- const unmuteUserMutation = gql`
- mutation ($id: ID!) {
- unmuteUser(id: $id) {
- id
- name
- isMuted
- }
- }
- `
- return mutate({ mutation: unmuteUserMutation, variables })
+ return mutate({ mutation: unmuteUser, variables })
}
})
diff --git a/backend/src/graphql/resolvers/viewedTeaserCount.spec.ts b/backend/src/graphql/resolvers/viewedTeaserCount.spec.ts
index f4fba31f8..39cbfb1ad 100644
--- a/backend/src/graphql/resolvers/viewedTeaserCount.spec.ts
+++ b/backend/src/graphql/resolvers/viewedTeaserCount.spec.ts
@@ -2,10 +2,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* 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 { markTeaserAsViewed } from '@graphql/queries/markTeaserAsViewed'
import createServer from '@src/server'
const driver = getDriver()
@@ -37,14 +37,6 @@ afterAll(async () => {
describe('count post teaser views', () => {
let aUser, bUser
- const markTeaserAsViewed = gql`
- mutation ($id: ID!) {
- markTeaserAsViewed(id: $id) {
- id
- viewedTeaserCount
- }
- }
- `
beforeAll(async () => {
Factory.build('post', { id: 'post-to-be-viewed' })
diff --git a/backend/src/middleware/categories.spec.ts b/backend/src/middleware/categories.spec.ts
index ed82bdef6..51e831da5 100644
--- a/backend/src/middleware/categories.spec.ts
+++ b/backend/src/middleware/categories.spec.ts
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
-import gql from 'graphql-tag'
-
import Factory, { cleanDatabase } from '@db/factories'
+import { Category } from '@graphql/queries/Category'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import { categories } from '@src/constants/categories'
@@ -40,17 +39,6 @@ afterAll(() => {
database.neode.close()
})
-const categoriesQuery = gql`
- query {
- Category {
- id
- slug
- name
- icon
- }
- }
-`
-
describe('categories middleware', () => {
describe('categories are active', () => {
beforeEach(() => {
@@ -60,7 +48,7 @@ describe('categories middleware', () => {
it('returns the categories', async () => {
await expect(
query({
- query: categoriesQuery,
+ query: Category,
}),
).resolves.toMatchObject({
data: {
@@ -80,7 +68,7 @@ describe('categories middleware', () => {
it('returns an empty array though there are categories in the db', async () => {
await expect(
query({
- query: categoriesQuery,
+ query: Category,
}),
).resolves.toMatchObject({
data: {
diff --git a/backend/src/middleware/hashtags/hashtagsMiddleware.spec.ts b/backend/src/middleware/hashtags/hashtagsMiddleware.spec.ts
index 42b9ccc05..dfcf9b722 100644
--- a/backend/src/middleware/hashtags/hashtagsMiddleware.spec.ts
+++ b/backend/src/middleware/hashtags/hashtagsMiddleware.spec.ts
@@ -4,6 +4,7 @@
import gql from 'graphql-tag'
import { cleanDatabase } from '@db/factories'
+import { UpdatePost } from '@graphql/queries/UpdatePost'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -25,14 +26,6 @@ const createPostMutation = gql`
}
}
`
-const updatePostMutation = gql`
- mutation ($id: ID!, $title: String!, $postContent: String!, $categoryIds: [ID]!) {
- UpdatePost(id: $id, content: $postContent, title: $title, categoryIds: $categoryIds) {
- title
- content
- }
- }
-`
beforeAll(async () => {
await cleanDatabase()
@@ -176,7 +169,7 @@ describe('hashtags', () => {
it('only one previous Hashtag and the new Hashtag exists', async () => {
await mutate({
- mutation: updatePostMutation,
+ mutation: UpdatePost,
variables: {
id,
title,
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.emails.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.emails.spec.ts
index d7cf11d34..681b0e13b 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.emails.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.emails.spec.ts
@@ -5,8 +5,9 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
-import { createGroupMutation } from '@graphql/queries/createGroupMutation'
-import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
+import { CreateGroup } from '@graphql/queries/CreateGroup'
+import { CreatePost } from '@graphql/queries/CreatePost'
+import { JoinGroup } from '@graphql/queries/JoinGroup'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -31,16 +32,6 @@ const mentionString = `
@group-member
@email-less-member`
-const createPostMutation = gql`
- mutation ($id: ID, $title: String!, $content: String!, $groupId: ID) {
- CreatePost(id: $id, title: $title, content: $content, groupId: $groupId) {
- id
- title
- content
- }
- }
-`
-
const createCommentMutation = gql`
mutation ($id: ID, $postId: ID!, $content: String!) {
CreateComment(id: $id, postId: $postId, content: $content) {
@@ -145,7 +136,7 @@ describe('emails sent for notifications', () => {
})
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'A public group',
@@ -156,7 +147,7 @@ describe('emails sent for notifications', () => {
})
authenticatedUser = await groupMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'group-member',
@@ -168,7 +159,7 @@ describe('emails sent for notifications', () => {
})
authenticatedUser = await emaillessMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'group-member',
@@ -191,7 +182,7 @@ describe('emails sent for notifications', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -269,7 +260,7 @@ describe('emails sent for notifications', () => {
await groupMember.update({ emailNotificationsMention: false })
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -348,7 +339,7 @@ describe('emails sent for notifications', () => {
await groupMember.update({ emailNotificationsFollowingUsers: false })
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -428,7 +419,7 @@ describe('emails sent for notifications', () => {
await groupMember.update({ emailNotificationsPostInGroup: false })
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -502,7 +493,7 @@ describe('emails sent for notifications', () => {
beforeEach(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -590,7 +581,7 @@ describe('emails sent for notifications', () => {
await groupMember.update({ emailNotificationsCommentOnObservedPost: false })
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -679,7 +670,7 @@ describe('emails sent for notifications', () => {
await groupMember.update({ emailNotificationsMention: false })
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.followed-users.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.followed-users.spec.ts
index 6bef70a39..7bd8c8c46 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.followed-users.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.followed-users.spec.ts
@@ -5,7 +5,8 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
-import { createGroupMutation } from '@graphql/queries/createGroupMutation'
+import { CreateGroup } from '@graphql/queries/CreateGroup'
+import { CreatePost } from '@graphql/queries/CreatePost'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -25,16 +26,6 @@ let server: ApolloTestSetup['server']
let postAuthor, firstFollower, secondFollower, thirdFollower, emaillessFollower
-const createPostMutation = gql`
- mutation ($id: ID, $title: String!, $content: String!, $groupId: ID) {
- CreatePost(id: $id, title: $title, content: $content, groupId: $groupId) {
- id
- title
- content
- }
- }
-`
-
const notificationQuery = gql`
query ($read: Boolean) {
notifications(read: $read, orderBy: updatedAt_desc) {
@@ -169,7 +160,7 @@ describe('following users notifications', () => {
beforeAll(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -281,7 +272,7 @@ describe('following users notifications', () => {
beforeAll(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'g-1',
name: 'A group',
@@ -291,7 +282,7 @@ describe('following users notifications', () => {
},
})
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'group-post',
title: 'This is the post in the group',
@@ -350,7 +341,7 @@ describe('following users notifications', () => {
beforeAll(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'g-2',
name: 'A closed group',
@@ -360,7 +351,7 @@ describe('following users notifications', () => {
},
})
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'closed-group-post',
title: 'This is the post in the closed group',
@@ -419,7 +410,7 @@ describe('following users notifications', () => {
beforeAll(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'g-3',
name: 'A hidden group',
@@ -429,7 +420,7 @@ describe('following users notifications', () => {
},
})
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'hidden-group-post',
title: 'This is the post in the hidden group',
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.mentions-in-groups.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.mentions-in-groups.spec.ts
index 95833ad82..82cbd01f3 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.mentions-in-groups.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.mentions-in-groups.spec.ts
@@ -5,9 +5,10 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
-import { changeGroupMemberRoleMutation } from '@graphql/queries/changeGroupMemberRoleMutation'
-import { createGroupMutation } from '@graphql/queries/createGroupMutation'
-import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
+import { ChangeGroupMemberRole } from '@graphql/queries/ChangeGroupMemberRole'
+import { CreateGroup } from '@graphql/queries/CreateGroup'
+import { CreatePost } from '@graphql/queries/CreatePost'
+import { JoinGroup } from '@graphql/queries/JoinGroup'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -34,16 +35,6 @@ const mentionString = `
@email-less-member.
`
-const createPostMutation = gql`
- mutation ($id: ID, $title: String!, $content: String!, $groupId: ID) {
- CreatePost(id: $id, title: $title, content: $content, groupId: $groupId) {
- id
- title
- content
- }
- }
-`
-
const createCommentMutation = gql`
mutation ($id: ID, $postId: ID!, $commentContent: String!) {
CreateComment(id: $id, postId: $postId, content: $commentContent) {
@@ -165,7 +156,7 @@ describe('mentions in groups', () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'public-group',
name: 'A public group',
@@ -175,7 +166,7 @@ describe('mentions in groups', () => {
},
})
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'A closed group',
@@ -185,7 +176,7 @@ describe('mentions in groups', () => {
},
})
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'hidden-group',
name: 'A hidden group',
@@ -196,21 +187,21 @@ describe('mentions in groups', () => {
})
authenticatedUser = await groupMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'group-member',
},
})
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'group-member',
},
})
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'hidden-group',
userId: 'group-member',
@@ -218,21 +209,21 @@ describe('mentions in groups', () => {
})
authenticatedUser = await pendingMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'pending-member',
},
})
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'pending-member',
},
})
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'hidden-group',
userId: 'pending-member',
@@ -240,21 +231,21 @@ describe('mentions in groups', () => {
})
authenticatedUser = await emaillessMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'public-group',
userId: 'group-member',
},
})
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: 'group-member',
},
})
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'hidden-group',
userId: 'group-member',
@@ -262,7 +253,7 @@ describe('mentions in groups', () => {
})
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'group-member',
@@ -270,7 +261,7 @@ describe('mentions in groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'group-member',
@@ -278,7 +269,7 @@ describe('mentions in groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'email-less-member',
@@ -286,7 +277,7 @@ describe('mentions in groups', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'hidden-group',
userId: 'email-less-member',
@@ -308,7 +299,7 @@ describe('mentions in groups', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'public-post',
title: 'This is the post in the public group',
@@ -414,7 +405,7 @@ describe('mentions in groups', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'closed-post',
title: 'This is the post in the closed group',
@@ -516,7 +507,7 @@ describe('mentions in groups', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'hidden-post',
title: 'This is the post in the hidden group',
@@ -618,7 +609,7 @@ describe('mentions in groups', () => {
beforeEach(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'public-post',
title: 'This is the post in the public group',
@@ -713,7 +704,7 @@ describe('mentions in groups', () => {
beforeEach(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'closed-post',
title: 'This is the post in the closed group',
@@ -810,7 +801,7 @@ describe('mentions in groups', () => {
beforeEach(async () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'hidden-post',
title: 'This is the post in the hidden group',
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.observing-posts.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.observing-posts.spec.ts
index 9b8e0e1e6..4ba22dac1 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.observing-posts.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.observing-posts.spec.ts
@@ -4,6 +4,8 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
+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'
@@ -23,16 +25,6 @@ let server: ApolloTestSetup['server']
let postAuthor, firstCommenter, secondCommenter, emaillessObserver
-const createPostMutation = gql`
- mutation ($id: ID, $title: String!, $content: String!) {
- CreatePost(id: $id, title: $title, content: $content) {
- id
- title
- content
- }
- }
-`
-
const createCommentMutation = gql`
mutation ($id: ID, $postId: ID!, $content: String!) {
CreateComment(id: $id, postId: $postId, content: $content) {
@@ -68,15 +60,6 @@ const notificationQuery = gql`
}
}
`
-
-const toggleObservePostMutation = gql`
- mutation ($id: ID!, $value: Boolean!) {
- toggleObservePost(id: $id, value: $value) {
- isObservedByMe
- observingUsersCount
- }
- }
-`
beforeAll(async () => {
await cleanDatabase()
const apolloSetup = createApolloTestSetup({ context })
@@ -138,7 +121,7 @@ describe('notifications for users that observe a post', () => {
})
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the post',
@@ -147,7 +130,7 @@ describe('notifications for users that observe a post', () => {
})
authenticatedUser = await emaillessObserver.toJson()
await mutate({
- mutation: toggleObservePostMutation,
+ mutation: toggleObservePost,
variables: {
id: 'post',
value: true,
@@ -317,7 +300,7 @@ describe('notifications for users that observe a post', () => {
jest.clearAllMocks()
authenticatedUser = await firstCommenter.toJson()
await mutate({
- mutation: toggleObservePostMutation,
+ mutation: toggleObservePost,
variables: {
id: 'post',
value: false,
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.online-status.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.online-status.spec.ts
index 8f22c9adc..6516ae600 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.online-status.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.online-status.spec.ts
@@ -2,9 +2,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
-import gql from 'graphql-tag'
-
import Factory, { cleanDatabase } from '@db/factories'
+import { CreatePost } from '@graphql/queries/CreatePost'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -28,16 +27,6 @@ let server: ApolloTestSetup['server']
let postAuthor
-const createPostMutation = gql`
- mutation ($id: ID, $title: String!, $content: String!, $groupId: ID) {
- CreatePost(id: $id, title: $title, content: $content, groupId: $groupId) {
- id
- title
- content
- }
- }
-`
-
beforeAll(async () => {
await cleanDatabase()
const apolloSetup = createApolloTestSetup({ context })
@@ -94,7 +83,7 @@ describe('online status and sending emails', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post-online-1',
title: 'This post mentions the other user',
@@ -120,7 +109,7 @@ describe('online status and sending emails', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post-offline-1',
title: 'This post mentions the other user',
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.posts-in-groups.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.posts-in-groups.spec.ts
index fdece8b58..afcde7569 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.posts-in-groups.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.posts-in-groups.spec.ts
@@ -5,9 +5,12 @@
import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
-import { changeGroupMemberRoleMutation } from '@graphql/queries/changeGroupMemberRoleMutation'
-import { createGroupMutation } from '@graphql/queries/createGroupMutation'
-import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
+import { ChangeGroupMemberRole } from '@graphql/queries/ChangeGroupMemberRole'
+import { CreateGroup } from '@graphql/queries/CreateGroup'
+import { CreatePost } from '@graphql/queries/CreatePost'
+import { JoinGroup } from '@graphql/queries/JoinGroup'
+import { muteGroup } from '@graphql/queries/muteGroup'
+import { unmuteGroup } from '@graphql/queries/unmuteGroup'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -27,16 +30,6 @@ let server: ApolloTestSetup['server']
let postAuthor, groupMember, pendingMember, emaillessMember
-const createPostMutation = gql`
- mutation ($id: ID, $title: String!, $content: String!, $groupId: ID) {
- CreatePost(id: $id, title: $title, content: $content, groupId: $groupId) {
- id
- title
- content
- }
- }
-`
-
const notificationQuery = gql`
query ($read: Boolean) {
notifications(read: $read, orderBy: updatedAt_desc) {
@@ -64,24 +57,6 @@ const notificationQuery = gql`
}
`
-const muteGroupMutation = gql`
- mutation ($groupId: ID!) {
- muteGroup(groupId: $groupId) {
- id
- isMutedByMe
- }
- }
-`
-
-const unmuteGroupMutation = gql`
- mutation ($groupId: ID!) {
- unmuteGroup(groupId: $groupId) {
- id
- isMutedByMe
- }
- }
-`
-
const markAllAsRead = async () =>
mutate({
mutation: gql`
@@ -155,7 +130,7 @@ describe('notify group members of new posts in group', () => {
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'g-1',
name: 'A closed group',
@@ -166,7 +141,7 @@ describe('notify group members of new posts in group', () => {
})
authenticatedUser = await groupMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'g-1',
userId: 'group-member',
@@ -174,7 +149,7 @@ describe('notify group members of new posts in group', () => {
})
authenticatedUser = await pendingMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'g-1',
userId: 'pending-member',
@@ -182,7 +157,7 @@ describe('notify group members of new posts in group', () => {
})
authenticatedUser = await emaillessMember.toJson()
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'g-1',
userId: 'group-member',
@@ -190,7 +165,7 @@ describe('notify group members of new posts in group', () => {
})
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g-1',
userId: 'group-member',
@@ -198,7 +173,7 @@ describe('notify group members of new posts in group', () => {
},
})
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'g-1',
userId: 'email-less-member',
@@ -219,7 +194,7 @@ describe('notify group members of new posts in group', () => {
authenticatedUser = await postAuthor.toJson()
await markAllAsRead()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post',
title: 'This is the new post in the group',
@@ -302,7 +277,7 @@ describe('notify group members of new posts in group', () => {
beforeEach(async () => {
authenticatedUser = await groupMember.toJson()
await mutate({
- mutation: muteGroupMutation,
+ mutation: muteGroup,
variables: {
groupId: 'g-1',
},
@@ -310,7 +285,7 @@ describe('notify group members of new posts in group', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post-1',
title: 'This is another post in the group',
@@ -344,7 +319,7 @@ describe('notify group members of new posts in group', () => {
beforeEach(async () => {
authenticatedUser = await groupMember.toJson()
await mutate({
- mutation: unmuteGroupMutation,
+ mutation: unmuteGroup,
variables: {
groupId: 'g-1',
},
@@ -358,7 +333,7 @@ describe('notify group members of new posts in group', () => {
await markAllAsRead()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post-2',
title: 'This is yet another post in the group',
@@ -405,7 +380,7 @@ describe('notify group members of new posts in group', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post-1',
title: 'This is another post in the group',
@@ -445,7 +420,7 @@ describe('notify group members of new posts in group', () => {
jest.clearAllMocks()
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: createPostMutation,
+ mutation: CreatePost,
variables: {
id: 'post-1',
title: 'This is another post in the group',
diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.ts b/backend/src/middleware/notifications/notificationsMiddleware.spec.ts
index a34233775..f97c46fe3 100644
--- a/backend/src/middleware/notifications/notificationsMiddleware.spec.ts
+++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.ts
@@ -8,13 +8,14 @@ import gql from 'graphql-tag'
import pubsubContext from '@context/pubsub'
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 { CreateMessage } from '@graphql/queries/CreateMessage'
-import { createRoomMutation } from '@graphql/queries/createRoomMutation'
-import { joinGroupMutation } from '@graphql/queries/joinGroupMutation'
-import { leaveGroupMutation } from '@graphql/queries/leaveGroupMutation'
-import { removeUserFromGroupMutation } from '@graphql/queries/removeUserFromGroupMutation'
+import { CreateRoom } from '@graphql/queries/CreateRoom'
+import { JoinGroup } from '@graphql/queries/JoinGroup'
+import { LeaveGroup } from '@graphql/queries/LeaveGroup'
+import { RemoveUserFromGroup } from '@graphql/queries/RemoveUserFromGroup'
+import { UpdatePost } from '@graphql/queries/UpdatePost'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -54,14 +55,6 @@ const createPostMutation = gql`
}
}
`
-const updatePostMutation = gql`
- mutation ($id: ID!, $title: String!, $postContent: String!, $categoryIds: [ID]!) {
- UpdatePost(id: $id, content: $postContent, title: $title, categoryIds: $categoryIds) {
- title
- content
- }
- }
-`
const createCommentMutation = gql`
mutation ($id: ID, $postId: ID!, $commentContent: String!) {
CreateComment(id: $id, postId: $postId, content: $commentContent) {
@@ -476,7 +469,7 @@ describe('notifications', () => {
`
authenticatedUser = await postAuthor.toJson()
await mutate({
- mutation: updatePostMutation,
+ mutation: UpdatePost,
variables: {
id: 'p47',
title,
@@ -905,7 +898,7 @@ describe('notifications', () => {
authenticatedUser = await chatSender.toJson()
const room = await mutate({
- mutation: createRoomMutation(),
+ mutation: CreateRoom,
variables: {
userId: 'chatReceiver',
},
@@ -1091,7 +1084,7 @@ describe('notifications', () => {
)
authenticatedUser = await groupOwner.toJson()
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
id: 'closed-group',
name: 'The Closed Group',
@@ -1108,7 +1101,7 @@ describe('notifications', () => {
const joinGroupAction = async () => {
authenticatedUser = (await notifiedUser.toJson()) as DecodedUser
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: authenticatedUser.id,
@@ -1195,7 +1188,7 @@ describe('notifications', () => {
const leaveGroupAction = async () => {
authenticatedUser = (await notifiedUser.toJson()) as DecodedUser
await mutate({
- mutation: leaveGroupMutation(),
+ mutation: LeaveGroup,
variables: {
groupId: 'closed-group',
userId: authenticatedUser.id,
@@ -1208,7 +1201,7 @@ describe('notifications', () => {
jest.clearAllMocks()
authenticatedUser = (await notifiedUser.toJson()) as DecodedUser
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: authenticatedUser.id,
@@ -1320,7 +1313,7 @@ describe('notifications', () => {
const changeGroupMemberRoleAction = async () => {
authenticatedUser = (await groupOwner.toJson()) as DecodedUser
await mutate({
- mutation: changeGroupMemberRoleMutation(),
+ mutation: ChangeGroupMemberRole,
variables: {
groupId: 'closed-group',
userId: 'you',
@@ -1333,7 +1326,7 @@ describe('notifications', () => {
beforeEach(async () => {
authenticatedUser = (await notifiedUser.toJson()) as DecodedUser
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: authenticatedUser.id,
@@ -1417,7 +1410,7 @@ describe('notifications', () => {
const removeUserFromGroupAction = async () => {
authenticatedUser = await groupOwner.toJson()
await mutate({
- mutation: removeUserFromGroupMutation(),
+ mutation: RemoveUserFromGroup,
variables: {
groupId: 'closed-group',
userId: 'you',
@@ -1429,7 +1422,7 @@ describe('notifications', () => {
beforeEach(async () => {
authenticatedUser = (await notifiedUser.toJson()) as DecodedUser
await mutate({
- mutation: joinGroupMutation(),
+ mutation: JoinGroup,
variables: {
groupId: 'closed-group',
userId: authenticatedUser.id,
diff --git a/backend/src/middleware/permissionsMiddleware.spec.ts b/backend/src/middleware/permissionsMiddleware.spec.ts
index cac4d45b5..c99a0d8b3 100644
--- a/backend/src/middleware/permissionsMiddleware.spec.ts
+++ b/backend/src/middleware/permissionsMiddleware.spec.ts
@@ -1,9 +1,9 @@
/* 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 { Signup } from '@graphql/queries/Signup'
+import { User } from '@graphql/queries/User'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
@@ -93,26 +93,18 @@ describe('authorization', () => {
})
describe('access email address', () => {
- const userQuery = gql`
- query ($name: String) {
- User(name: $name) {
- email
- }
- }
- `
-
describe('unauthenticated', () => {
beforeEach(() => {
authenticatedUser = null
})
it("throws an error and does not expose the owner's email address", async () => {
- await expect(
- query({ query: userQuery, variables: { name: 'Owner' } }),
- ).resolves.toMatchObject({
- errors: [{ message: 'Not Authorized!' }],
- data: { User: null },
- })
+ await expect(query({ query: User, variables: { name: 'Owner' } })).resolves.toMatchObject(
+ {
+ errors: [{ message: 'Not Authorized!' }],
+ data: { User: null },
+ },
+ )
})
})
@@ -124,7 +116,7 @@ describe('authorization', () => {
it("exposes the owner's email address", async () => {
variables = { name: 'Owner' }
- await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: User, variables })).resolves.toMatchObject({
data: { User: [{ email: 'owner@example.org' }] },
errors: undefined,
})
@@ -138,7 +130,7 @@ describe('authorization', () => {
it("throws an error and does not expose the owner's email address", async () => {
await expect(
- query({ query: userQuery, variables: { name: 'Owner' } }),
+ query({ query: User, variables: { name: 'Owner' } }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { User: [null] },
@@ -153,7 +145,7 @@ describe('authorization', () => {
it("throws an error and does not expose the owner's email address", async () => {
await expect(
- query({ query: userQuery, variables: { name: 'Owner' } }),
+ query({ query: User, variables: { name: 'Owner' } }),
).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { User: [null] },
@@ -168,7 +160,7 @@ describe('authorization', () => {
it("exposes the owner's email address", async () => {
variables = { name: 'Owner' }
- await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
+ await expect(query({ query: User, variables })).resolves.toMatchObject({
data: { User: [{ email: 'owner@example.org' }] },
errors: undefined,
})
@@ -178,14 +170,6 @@ describe('authorization', () => {
})
describe('access Signup', () => {
- const signupMutation = gql`
- mutation ($email: String!, $locale: String!, $inviteCode: String) {
- Signup(email: $email, locale: $locale, inviteCode: $inviteCode) {
- email
- }
- }
- `
-
describe('admin invite only', () => {
beforeEach(async () => {
variables = {
@@ -211,7 +195,7 @@ describe('authorization', () => {
})
it('denies permission', async () => {
- await expect(mutate({ mutation: signupMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { Signup: null },
})
@@ -224,7 +208,7 @@ describe('authorization', () => {
})
it('returns an email', async () => {
- await expect(mutate({ mutation: signupMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
errors: undefined,
data: {
Signup: { email: 'some@email.org' },
@@ -258,7 +242,7 @@ describe('authorization', () => {
})
it('returns an email', async () => {
- await expect(mutate({ mutation: signupMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
errors: undefined,
data: {
Signup: { email: 'some@email.org' },
@@ -292,7 +276,7 @@ describe('authorization', () => {
})
it('returns an email', async () => {
- await expect(mutate({ mutation: signupMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
errors: undefined,
data: {
Signup: { email: 'some@email.org' },
@@ -312,7 +296,7 @@ describe('authorization', () => {
})
it('denies permission', async () => {
- await expect(mutate({ mutation: signupMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: Signup, variables })).resolves.toMatchObject({
errors: [{ message: 'Not Authorized!' }],
data: { Signup: null },
})
diff --git a/backend/src/middleware/slugifyMiddleware.spec.ts b/backend/src/middleware/slugifyMiddleware.spec.ts
index 085badb15..f2c35d696 100644
--- a/backend/src/middleware/slugifyMiddleware.spec.ts
+++ b/backend/src/middleware/slugifyMiddleware.spec.ts
@@ -3,10 +3,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Factory, { cleanDatabase } from '@db/factories'
-import { createGroupMutation } from '@graphql/queries/createGroupMutation'
-import { createPostMutation } from '@graphql/queries/createPostMutation'
-import { signupVerificationMutation } from '@graphql/queries/signupVerificationMutation'
-import { updateGroupMutation } from '@graphql/queries/updateGroupMutation'
+import { CreateGroup } from '@graphql/queries/CreateGroup'
+import { CreatePost } from '@graphql/queries/CreatePost'
+import { SignupVerification } from '@graphql/queries/SignupVerification'
+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'
@@ -82,7 +82,7 @@ describe('slugifyMiddleware', () => {
it('generates a slug based on name', async () => {
await expect(
mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables,
}),
).resolves.toMatchObject({
@@ -103,7 +103,7 @@ describe('slugifyMiddleware', () => {
it('generates a slug based on given slug', async () => {
await expect(
mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
...variables,
slug: 'the-group',
@@ -123,7 +123,7 @@ describe('slugifyMiddleware', () => {
describe('if slug exists', () => {
beforeEach(async () => {
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
...variables,
name: 'Pre-Existing Group',
@@ -136,7 +136,7 @@ describe('slugifyMiddleware', () => {
it('chooses another slug', async () => {
await expect(
mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
...variables,
name: 'Pre-Existing Group',
@@ -158,7 +158,7 @@ describe('slugifyMiddleware', () => {
try {
await expect(
mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
...variables,
name: 'Pre-Existing Group',
@@ -199,7 +199,7 @@ describe('slugifyMiddleware', () => {
beforeEach(async () => {
createGroupResult = await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
name: 'The Best Group',
slug: 'the-best-group',
@@ -218,7 +218,7 @@ describe('slugifyMiddleware', () => {
it('has the new slug', async () => {
await expect(
mutate({
- mutation: updateGroupMutation(),
+ mutation: UpdateGroup,
variables: {
id: createGroupResult.data.CreateGroup.id,
slug: 'my-best-group',
@@ -245,7 +245,7 @@ describe('slugifyMiddleware', () => {
describe('if new slug exists in another group', () => {
beforeEach(async () => {
await mutate({
- mutation: createGroupMutation(),
+ mutation: CreateGroup,
variables: {
name: 'Pre-Existing Group',
slug: 'pre-existing-group',
@@ -263,7 +263,7 @@ describe('slugifyMiddleware', () => {
try {
await expect(
mutate({
- mutation: updateGroupMutation(),
+ mutation: UpdateGroup,
variables: {
id: createGroupResult.data.CreateGroup.id,
slug: 'pre-existing-group',
@@ -312,7 +312,7 @@ describe('slugifyMiddleware', () => {
it('generates a slug based on title', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables,
}),
).resolves.toMatchObject({
@@ -328,7 +328,7 @@ describe('slugifyMiddleware', () => {
it('generates a slug based on given slug', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
...variables,
slug: 'the-post',
@@ -363,7 +363,7 @@ describe('slugifyMiddleware', () => {
it('chooses another slug', async () => {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
...variables,
title: 'Pre-existing post',
@@ -386,7 +386,7 @@ describe('slugifyMiddleware', () => {
try {
await expect(
mutate({
- mutation: createPostMutation(),
+ mutation: CreatePost,
variables: {
...variables,
title: 'Pre-existing post',
@@ -450,7 +450,7 @@ describe('slugifyMiddleware', () => {
it('generates a slug based on name', async () => {
await expect(
mutate({
- mutation: signupVerificationMutation,
+ mutation: SignupVerification,
variables,
}),
).resolves.toMatchObject({
@@ -466,7 +466,7 @@ describe('slugifyMiddleware', () => {
it('generates a slug based on given slug', async () => {
await expect(
mutate({
- mutation: signupVerificationMutation,
+ mutation: SignupVerification,
variables: {
...variables,
slug: 'the-user',
@@ -494,7 +494,7 @@ describe('slugifyMiddleware', () => {
it('chooses another slug', async () => {
await expect(
mutate({
- mutation: signupVerificationMutation,
+ mutation: SignupVerification,
variables,
}),
).resolves.toMatchObject({
@@ -518,7 +518,7 @@ describe('slugifyMiddleware', () => {
it('rejects SignupVerification (on FAIL Neo4j constraints may not defined in database)', async () => {
await expect(
mutate({
- mutation: signupVerificationMutation,
+ mutation: SignupVerification,
variables,
}),
).resolves.toMatchObject({
diff --git a/backend/src/middleware/validation/validationMiddleware.spec.ts b/backend/src/middleware/validation/validationMiddleware.spec.ts
index ea4f6ec54..bc8d3c883 100644
--- a/backend/src/middleware/validation/validationMiddleware.spec.ts
+++ b/backend/src/middleware/validation/validationMiddleware.spec.ts
@@ -6,6 +6,8 @@ import gql from 'graphql-tag'
import Factory, { cleanDatabase } from '@db/factories'
import { getNeode, getDriver } from '@db/neo4j'
+import { review } from '@graphql/queries/review'
+import { UpdateUser } from '@graphql/queries/UpdateUser'
import createServer from '@src/server'
const neode = getNeode()
@@ -46,22 +48,6 @@ const reportMutation = gql`
}
}
`
-const reviewMutation = gql`
- mutation ($resourceId: ID!, $disable: Boolean, $closed: Boolean) {
- review(resourceId: $resourceId, disable: $disable, closed: $closed) {
- createdAt
- updatedAt
- }
- }
-`
-const updateUserMutation = gql`
- mutation ($id: ID!, $name: String) {
- UpdateUser(id: $id, name: $name) {
- name
- }
- }
-`
-
beforeAll(async () => {
await cleanDatabase()
@@ -249,9 +235,7 @@ describe('validateReview', () => {
it('throws an error if a user tries to review a report against them', async () => {
disableVariables = { ...disableVariables, resourceId: 'moderating-user' }
- await expect(
- mutate({ mutation: reviewMutation, variables: disableVariables }),
- ).resolves.toMatchObject({
+ await expect(mutate({ mutation: review, variables: disableVariables })).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'You cannot review yourself!' }],
})
@@ -259,9 +243,7 @@ describe('validateReview', () => {
it('throws an error for invaild resource', async () => {
disableVariables = { ...disableVariables, resourceId: 'non-existent-resource' }
- await expect(
- mutate({ mutation: reviewMutation, variables: disableVariables }),
- ).resolves.toMatchObject({
+ await expect(mutate({ mutation: review, variables: disableVariables })).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'Resource not found or is not a Post|Comment|User!' }],
})
@@ -269,9 +251,7 @@ describe('validateReview', () => {
it('throws an error if no report exists', async () => {
disableVariables = { ...disableVariables, resourceId: 'offensive-post' }
- await expect(
- mutate({ mutation: reviewMutation, variables: disableVariables }),
- ).resolves.toMatchObject({
+ await expect(mutate({ mutation: review, variables: disableVariables })).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'Before starting the review process, please report the Post!' }],
})
@@ -287,9 +267,7 @@ describe('validateReview', () => {
reportAgainstOffensivePost.relateTo(offensivePost, 'belongsTo'),
])
disableVariables = { ...disableVariables, resourceId: 'offensive-post' }
- await expect(
- mutate({ mutation: reviewMutation, variables: disableVariables }),
- ).resolves.toMatchObject({
+ await expect(mutate({ mutation: review, variables: disableVariables })).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'You cannot review your own Post!' }],
})
@@ -306,7 +284,7 @@ describe('validateReview', () => {
resourceId: 'tag-id',
}
await expect(
- mutate({ mutation: reviewMutation, variables: disableVariables }),
+ mutate({ mutation: review, variables: disableVariables }),
).resolves.toMatchObject({
data: { review: null },
errors: [{ message: 'Resource not found or is not a Post|Comment|User!' }],
@@ -336,7 +314,7 @@ describe('validateReview', () => {
...variables,
name: ' ',
}
- await expect(mutate({ mutation: updateUserMutation, variables })).resolves.toMatchObject({
+ await expect(mutate({ mutation: UpdateUser, variables })).resolves.toMatchObject({
data: { UpdateUser: null },
errors: [{ message: 'Username must be at least 3 character long!' }],
})
diff --git a/backend/src/plugins/apolloLogger.spec.ts b/backend/src/plugins/apolloLogger.spec.ts
index 10f56e6e5..7b1f2a91a 100644
--- a/backend/src/plugins/apolloLogger.spec.ts
+++ b/backend/src/plugins/apolloLogger.spec.ts
@@ -7,7 +7,7 @@ import Factory, { cleanDatabase } from '@db/factories'
import type { ApolloTestSetup } from '@root/test/helpers'
import { createApolloTestSetup } from '@root/test/helpers'
import type { Context } from '@src/context'
-import { loginMutation } from '@src/graphql/queries/loginMutation'
+import { login } from '@src/graphql/queries/login'
import ocelotLogger from '@src/logger'
import { loggerPlugin } from '@src/plugins/apolloLogger'
@@ -59,7 +59,7 @@ describe('apollo logger', () => {
describe('login mutation', () => {
it('logs the request and response, masking password and token', async () => {
await mutate({
- mutation: loginMutation,
+ mutation: login,
variables: {
email: 'test@example.org',
password: '1234',