Correct tests.

This commit is contained in:
elweyn 2023-08-02 11:52:16 +02:00
parent 51838d398a
commit 2e79dbc310
3 changed files with 33 additions and 12 deletions

View File

@ -17,7 +17,7 @@ export const queryAllUserIds = async (context, offset = -1, pageSize = -1) => {
const ids = await writeTxResultPromise
return ids
} catch (error) {
throw new Error(error)
throw new Error(error.message)
} finally {
session.close()
}

View File

@ -120,25 +120,37 @@ const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo
const handleContentDataOfComment = async (resolve, root, args, context, resolveInfo) => {
const { content } = args
let idsOfUsers = extractMentionedUsers(content)
const comment = await resolve(root, args, context, resolveInfo)
const [postAuthor] = await postAuthorOfComment(comment.id, { context })
idsOfUsers = idsOfUsers.filter((id) => id !== postAuthor.id)
if (idsOfUsers.find((id) => id === 'all')) {
const mentionedUserIds = extractMentionedUsers(content).filter((id) => id !== postAuthor.id)
let notifications
if (mentionedUserIds.includes('all')) {
if (context.user.role !== 'admin') {
throw new AuthenticationError('You are not allowed to use the "@all" mention!')
}
let userToNotify = await queryAllUserIds(context)
userToNotify = userToNotify.filter((id) => id !== postAuthor.id)
await publishNotifications(context, [
notifyUsersOfMention('Comment', comment.id, userToNotify, 'mentioned_in_comment', context),
])
const userToNotify = (await queryAllUserIds(context)).filter((id) => id !== postAuthor.id)
const notification = notifyUsersOfMention(
'Comment',
comment.id,
userToNotify,
'mentioned_in_comment',
context,
)
notifications = [notification]
} else {
await publishNotifications(context, [
notifyUsersOfMention('Comment', comment.id, idsOfUsers, 'mentioned_in_comment', context),
notifications = [
notifyUsersOfMention(
'Comment',
comment.id,
mentionedUserIds,
'mentioned_in_comment',
context,
),
notifyUsersOfComment('Comment', comment.id, postAuthor.id, 'commented_on_post', context),
])
]
}
await publishNotifications(context, notifications)
return comment
}

View File

@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils'
import Editor from './Editor'
import Vuex from 'vuex'
import MutationObserver from 'mutation-observer'
import Vue from 'vue'
@ -7,6 +8,7 @@ import Vue from 'vue'
global.MutationObserver = MutationObserver
const localVue = global.localVue
localVue.use(Vuex)
describe('Editor.vue', () => {
let wrapper
@ -14,6 +16,12 @@ describe('Editor.vue', () => {
let mocks
const Wrapper = () => {
const store = new Vuex.Store({ getters: {
'auth/user': () => {
return { id: 'u343', name: deleteAccountName }
},
'auth/isAdmin': () => false,
}})
return (wrapper = mount(Editor, {
mocks,
propsData,
@ -22,6 +30,7 @@ describe('Editor.vue', () => {
stubs: {
transition: false,
},
store
}))
}