mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
fix: tests ok, lint ok
This commit is contained in:
parent
0b62d76bc1
commit
3d69ebbb1c
@ -6,14 +6,12 @@ import { createTestClient } from 'apollo-server-testing'
|
|||||||
|
|
||||||
const categoryIds = ['cat9']
|
const categoryIds = ['cat9']
|
||||||
let user
|
let user
|
||||||
//let anotherUser
|
let admin
|
||||||
//let moderator
|
|
||||||
//let admin
|
|
||||||
|
|
||||||
let query
|
let query
|
||||||
let mutate
|
let mutate
|
||||||
let authenticatedUser
|
let authenticatedUser
|
||||||
//let variables
|
let variables
|
||||||
|
|
||||||
const driver = getDriver()
|
const driver = getDriver()
|
||||||
const neode = getNeode()
|
const neode = getNeode()
|
||||||
@ -78,7 +76,7 @@ describe('User', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const variables = { email: 'any-email-address@example.org' }
|
variables = { email: 'any-email-address@example.org' }
|
||||||
|
|
||||||
it('is forbidden', async () => {
|
it('is forbidden', async () => {
|
||||||
await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
|
await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
|
||||||
@ -275,70 +273,6 @@ describe('UpdateUser', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
/*
|
|
||||||
describe('Delete a User as another user', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
variables = { id: ' u343', resource: [] }
|
|
||||||
|
|
||||||
user = await Factory.build('user', {
|
|
||||||
name: 'My name should be deleted',
|
|
||||||
about: 'along with my about',
|
|
||||||
id: 'u343',
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
anotherUser = await Factory.build(
|
|
||||||
'user',
|
|
||||||
{
|
|
||||||
role: 'user',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
email: 'user@example.org',
|
|
||||||
password: '1234',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
authenticatedUser = await anotherUser.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("an ordinary user has no authorization to delete another user's account", async () => {
|
|
||||||
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
|
|
||||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Delete a User as moderator', () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
variables = { id: ' u343', resource: [] }
|
|
||||||
|
|
||||||
user = await Factory.build('user', {
|
|
||||||
name: 'My name should be deleted',
|
|
||||||
about: 'along with my about',
|
|
||||||
id: 'u343',
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
moderator = await Factory.build(
|
|
||||||
'user',
|
|
||||||
{
|
|
||||||
role: 'moderator',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
email: 'moderator@example.org',
|
|
||||||
password: '1234',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
authenticatedUser = await moderator.toJson()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('moderator is not allowed to delete other user accounts', async () => {
|
|
||||||
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
|
|
||||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Delete a User as admin', () => {
|
describe('Delete a User as admin', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -452,106 +386,6 @@ describe('Delete a User as admin', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('deletion of all post requested', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
variables = { ...variables, resource: ['Post'] }
|
|
||||||
})
|
|
||||||
|
|
||||||
it('on request', async () => {
|
|
||||||
const expectedResponse = {
|
|
||||||
data: {
|
|
||||||
DeleteUser: {
|
|
||||||
id: 'u343',
|
|
||||||
name: 'UNAVAILABLE',
|
|
||||||
about: 'UNAVAILABLE',
|
|
||||||
deleted: true,
|
|
||||||
contributions: [
|
|
||||||
{
|
|
||||||
id: 'p139',
|
|
||||||
content: 'UNAVAILABLE',
|
|
||||||
contentExcerpt: 'UNAVAILABLE',
|
|
||||||
deleted: true,
|
|
||||||
comments: [
|
|
||||||
{
|
|
||||||
id: 'c156',
|
|
||||||
content: 'UNAVAILABLE',
|
|
||||||
contentExcerpt: 'UNAVAILABLE',
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
comments: [
|
|
||||||
{
|
|
||||||
id: 'c155',
|
|
||||||
content: 'Comment by user u343',
|
|
||||||
contentExcerpt: 'Comment by user u343',
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
errors: undefined,
|
|
||||||
}
|
|
||||||
await expect(
|
|
||||||
mutate({ mutation: deleteUserMutation, variables }),
|
|
||||||
).resolves.toMatchObject(expectedResponse)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('deletes user avatar and post hero images', async () => {
|
|
||||||
await expect(neode.all('Image')).resolves.toHaveLength(22)
|
|
||||||
await mutate({ mutation: deleteUserMutation, variables })
|
|
||||||
await expect(neode.all('Image')).resolves.toHaveLength(20)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('deletion of all comments requested', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
variables = { ...variables, resource: ['Comment'] }
|
|
||||||
})
|
|
||||||
|
|
||||||
it('marks comments as deleted', async () => {
|
|
||||||
const expectedResponse = {
|
|
||||||
data: {
|
|
||||||
DeleteUser: {
|
|
||||||
id: 'u343',
|
|
||||||
name: 'UNAVAILABLE',
|
|
||||||
about: 'UNAVAILABLE',
|
|
||||||
deleted: true,
|
|
||||||
contributions: [
|
|
||||||
{
|
|
||||||
id: 'p139',
|
|
||||||
content: 'Post by user u343',
|
|
||||||
contentExcerpt: 'Post by user u343',
|
|
||||||
deleted: false,
|
|
||||||
comments: [
|
|
||||||
{
|
|
||||||
id: 'c156',
|
|
||||||
content: "A comment by someone else on user u343's post",
|
|
||||||
contentExcerpt: "A comment by someone else on user u343's post",
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
comments: [
|
|
||||||
{
|
|
||||||
id: 'c155',
|
|
||||||
content: 'UNAVAILABLE',
|
|
||||||
contentExcerpt: 'UNAVAILABLE',
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
errors: undefined,
|
|
||||||
}
|
|
||||||
await expect(
|
|
||||||
mutate({ mutation: deleteUserMutation, variables }),
|
|
||||||
).resolves.toMatchObject(expectedResponse)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('deletion of all posts and comments requested', () => {
|
describe('deletion of all posts and comments requested', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
variables = { ...variables, resource: ['Comment', 'Post'] }
|
variables = { ...variables, resource: ['Comment', 'Post'] }
|
||||||
@ -624,5 +458,3 @@ describe('Delete a User as admin', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
*/
|
|
||||||
|
|||||||
@ -51,8 +51,8 @@ const newlyCreatedNodesWithLocales = [
|
|||||||
country: {
|
country: {
|
||||||
id: expect.stringContaining('country'),
|
id: expect.stringContaining('country'),
|
||||||
type: 'country',
|
type: 'country',
|
||||||
name: 'United States of America',
|
name: 'United States',
|
||||||
nameEN: 'United States of America',
|
nameEN: 'United States',
|
||||||
nameDE: 'Vereinigte Staaten',
|
nameDE: 'Vereinigte Staaten',
|
||||||
namePT: 'Estados Unidos',
|
namePT: 'Estados Unidos',
|
||||||
nameES: 'Estados Unidos',
|
nameES: 'Estados Unidos',
|
||||||
|
|||||||
@ -134,6 +134,47 @@ describe('ContentMenu.vue', () => {
|
|||||||
],
|
],
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can delete another user', () => {
|
||||||
|
getters['auth/user'] = () => {
|
||||||
|
return { id: 'some-user', slug: 'some-user' }
|
||||||
|
}
|
||||||
|
const wrapper = openContentMenu({
|
||||||
|
resourceType: 'user',
|
||||||
|
resource: {
|
||||||
|
id: 'another-user',
|
||||||
|
slug: 'another-user',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
wrapper
|
||||||
|
.findAll('.ds-menu-item')
|
||||||
|
.filter((item) => item.text() === 'settings.deleteUserAccount.name')
|
||||||
|
.at(0)
|
||||||
|
.trigger('click')
|
||||||
|
expect(wrapper.emitted('delete')).toEqual([
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'another-user',
|
||||||
|
slug: 'another-user',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can not delete the own account', () => {
|
||||||
|
const wrapper = openContentMenu({
|
||||||
|
resourceType: 'user',
|
||||||
|
resource: {
|
||||||
|
id: 'some-user',
|
||||||
|
slug: 'some-user',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(
|
||||||
|
wrapper
|
||||||
|
.findAll('.ds-menu-item')
|
||||||
|
.filter((item) => item.text() === 'settings.deleteUserAccount.name'),
|
||||||
|
).toEqual({})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('owner of comment can', () => {
|
describe('owner of comment can', () => {
|
||||||
|
|||||||
@ -156,7 +156,7 @@ export default {
|
|||||||
path: '/settings',
|
path: '/settings',
|
||||||
icon: 'edit',
|
icon: 'edit',
|
||||||
})
|
})
|
||||||
if (this.isAdmin === true) {
|
if (this.isAdmin === true && !this.isOwner) {
|
||||||
routes.push({
|
routes.push({
|
||||||
label: this.$t(`settings.deleteUserAccount.name`),
|
label: this.$t(`settings.deleteUserAccount.name`),
|
||||||
callback: () => {
|
callback: () => {
|
||||||
|
|||||||
113
webapp/components/Modal/DeleteUserModal.spec.js
Normal file
113
webapp/components/Modal/DeleteUserModal.spec.js
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import { config, mount, shallowMount } from '@vue/test-utils'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import DeleteUserModal from './DeleteUserModal.vue'
|
||||||
|
const localVue = global.localVue
|
||||||
|
config.stubs['sweetalert-icon'] = '<span><slot /></span>'
|
||||||
|
|
||||||
|
localVue.use(DeleteUserModal)
|
||||||
|
|
||||||
|
const getters = {
|
||||||
|
'auth/isAdmin': () => true,
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('DeleteUserModal.vue', () => {
|
||||||
|
const store = new Vuex.Store({ getters })
|
||||||
|
let wrapper
|
||||||
|
let propsData = {
|
||||||
|
userdata: {
|
||||||
|
name: 'another-user',
|
||||||
|
slug: 'another-user',
|
||||||
|
createdAt: '2020-08-12T08:34:05.803Z',
|
||||||
|
contributionsCount: '4',
|
||||||
|
commentedCount: '2',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const mocks = {
|
||||||
|
$t: jest.fn(),
|
||||||
|
$filters: {
|
||||||
|
truncate: (a) => a,
|
||||||
|
},
|
||||||
|
$toast: {
|
||||||
|
success: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
},
|
||||||
|
$i18n: {
|
||||||
|
locale: () => 'en',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('shallowMount', () => {
|
||||||
|
const Wrapper = () => {
|
||||||
|
return shallowMount(DeleteUserModal, {
|
||||||
|
propsData,
|
||||||
|
mocks,
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('defaults', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('success false', () => {
|
||||||
|
expect(wrapper.vm.success).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('loading false', () => {
|
||||||
|
expect(wrapper.vm.loading).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
const Wrapper = () => {
|
||||||
|
return mount(DeleteUserModal, {
|
||||||
|
propsData,
|
||||||
|
mocks,
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
beforeEach(jest.useFakeTimers)
|
||||||
|
|
||||||
|
describe('given another user', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
propsData = {
|
||||||
|
...propsData,
|
||||||
|
type: 'user',
|
||||||
|
id: 'u4711',
|
||||||
|
}
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('click cancel button', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = Wrapper()
|
||||||
|
wrapper.find('button.cancel').trigger('click')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not emit "close" yet', () => {
|
||||||
|
expect(wrapper.emitted().close).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('fades away', () => {
|
||||||
|
expect(wrapper.vm.isOpen).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('after timeout', () => {
|
||||||
|
beforeEach(jest.runAllTimers)
|
||||||
|
|
||||||
|
it('emits "close"', () => {
|
||||||
|
expect(wrapper.emitted().close).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<ds-modal :title="title" :is-open="isOpen" @cancel="cancel">
|
<ds-modal class="delete-user-modal" :title="title" :is-open="isOpen" @cancel="cancel">
|
||||||
<transition name="ds-transition-fade">
|
<transition name="ds-transition-fade">
|
||||||
<ds-flex v-if="success" class="hc-modal-success" centered>
|
<ds-flex v-if="success" class="hc-modal-success" centered>
|
||||||
<sweetalert-icon icon="success" />
|
<sweetalert-icon icon="success" />
|
||||||
@ -67,7 +67,8 @@ export default {
|
|||||||
isOpen: true,
|
isOpen: true,
|
||||||
success: false,
|
success: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
isAdmin: this.$store.getters['auth/isAdmin'],
|
// isAdmin: this.$store.getters['auth/isAdmin'],
|
||||||
|
isAdmin: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user