diff --git a/backend/src/schema/resolvers/users.spec.js b/backend/src/schema/resolvers/users.spec.js
index 21a59f670..1b266171a 100644
--- a/backend/src/schema/resolvers/users.spec.js
+++ b/backend/src/schema/resolvers/users.spec.js
@@ -6,14 +6,12 @@ import { createTestClient } from 'apollo-server-testing'
const categoryIds = ['cat9']
let user
-//let anotherUser
-//let moderator
-//let admin
+let admin
let query
let mutate
let authenticatedUser
-//let variables
+let variables
const driver = getDriver()
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 () => {
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', () => {
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', () => {
beforeEach(() => {
variables = { ...variables, resource: ['Comment', 'Post'] }
@@ -624,5 +458,3 @@ describe('Delete a User as admin', () => {
})
})
})
-
-*/
diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js
index 59442a9ca..3044e4b6f 100644
--- a/backend/src/schema/resolvers/users/location.spec.js
+++ b/backend/src/schema/resolvers/users/location.spec.js
@@ -51,8 +51,8 @@ const newlyCreatedNodesWithLocales = [
country: {
id: expect.stringContaining('country'),
type: 'country',
- name: 'United States of America',
- nameEN: 'United States of America',
+ name: 'United States',
+ nameEN: 'United States',
nameDE: 'Vereinigte Staaten',
namePT: 'Estados Unidos',
nameES: 'Estados Unidos',
diff --git a/webapp/components/ContentMenu/ContentMenu.spec.js b/webapp/components/ContentMenu/ContentMenu.spec.js
index b49a1158a..37bef14f6 100644
--- a/webapp/components/ContentMenu/ContentMenu.spec.js
+++ b/webapp/components/ContentMenu/ContentMenu.spec.js
@@ -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', () => {
diff --git a/webapp/components/ContentMenu/ContentMenu.vue b/webapp/components/ContentMenu/ContentMenu.vue
index 0bcfeb3cd..6ffd2b7ab 100644
--- a/webapp/components/ContentMenu/ContentMenu.vue
+++ b/webapp/components/ContentMenu/ContentMenu.vue
@@ -156,7 +156,7 @@ export default {
path: '/settings',
icon: 'edit',
})
- if (this.isAdmin === true) {
+ if (this.isAdmin === true && !this.isOwner) {
routes.push({
label: this.$t(`settings.deleteUserAccount.name`),
callback: () => {
diff --git a/webapp/components/Modal/DeleteUserModal.spec.js b/webapp/components/Modal/DeleteUserModal.spec.js
new file mode 100644
index 000000000..76af36fca
--- /dev/null
+++ b/webapp/components/Modal/DeleteUserModal.spec.js
@@ -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'] = ''
+
+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()
+ })
+ })
+ })
+ })
+ })
+})
diff --git a/webapp/components/Modal/DeleteUserModal.vue b/webapp/components/Modal/DeleteUserModal.vue
index 1b09e6dbc..1d534ea64 100644
--- a/webapp/components/Modal/DeleteUserModal.vue
+++ b/webapp/components/Modal/DeleteUserModal.vue
@@ -1,5 +1,5 @@
-
+
@@ -67,7 +67,8 @@ export default {
isOpen: true,
success: false,
loading: false,
- isAdmin: this.$store.getters['auth/isAdmin'],
+ // isAdmin: this.$store.getters['auth/isAdmin'],
+ isAdmin: true,
}
},
computed: {