From cbf50014ed150a4b502c2130d07e975656f1ae06 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 15 Jan 2021 00:36:55 +0100 Subject: [PATCH] removed categories from posts --- .../validation/validationMiddleware.js | 2 -- .../validation/validationMiddleware.spec.js | 8 ++--- backend/src/schema/resolvers/posts.js | 7 +--- backend/src/schema/types/type/Post.gql | 2 +- backend/src/schema/types/type/User.gql | 2 +- .../ContributionForm/ContributionForm.spec.js | 34 ++++++++++--------- .../ContributionForm/ContributionForm.vue | 23 ++----------- webapp/pages/post/_id/_slug/index.vue | 17 ---------- 8 files changed, 27 insertions(+), 68 deletions(-) diff --git a/backend/src/middleware/validation/validationMiddleware.js b/backend/src/middleware/validation/validationMiddleware.js index d36e64846..086b657ff 100644 --- a/backend/src/middleware/validation/validationMiddleware.js +++ b/backend/src/middleware/validation/validationMiddleware.js @@ -138,8 +138,6 @@ export default { Mutation: { CreateComment: validateCreateComment, UpdateComment: validateUpdateComment, - CreatePost: validatePost, - UpdatePost: validateUpdatePost, UpdateUser: validateUpdateUser, fileReport: validateReport, review: validateReview, diff --git a/backend/src/middleware/validation/validationMiddleware.spec.js b/backend/src/middleware/validation/validationMiddleware.spec.js index 74a343eeb..efb85bd10 100644 --- a/backend/src/middleware/validation/validationMiddleware.spec.js +++ b/backend/src/middleware/validation/validationMiddleware.spec.js @@ -240,7 +240,7 @@ describe('validateCreateComment', () => { describe('categories', () => { describe('null', () => { - it('throws UserInputError', async () => { + it.skip('throws UserInputError', async () => { createPostVariables = { ...createPostVariables, categoryIds: null } await expect( mutate({ mutation: createPostMutation, variables: createPostVariables }), @@ -256,7 +256,7 @@ describe('validateCreateComment', () => { }) describe('empty', () => { - it('throws UserInputError', async () => { + it.skip('throws UserInputError', async () => { createPostVariables = { ...createPostVariables, categoryIds: [] } await expect( mutate({ mutation: createPostMutation, variables: createPostVariables }), @@ -272,7 +272,7 @@ describe('validateCreateComment', () => { }) describe('more than 3 categoryIds', () => { - it('throws UserInputError', async () => { + it.skip('throws UserInputError', async () => { createPostVariables = { ...createPostVariables, categoryIds: ['cat9', 'cat27', 'cat15', 'cat4'], @@ -313,7 +313,7 @@ describe('validateCreateComment', () => { } }) - it('requires at least one category for successful update', async () => { + it.skip('requires at least one category for successful update', async () => { await expect( mutate({ mutation: updatePostMutation, variables: updatePostVariables }), ).resolves.toMatchObject({ diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index f209158fe..14e645730 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -76,7 +76,6 @@ export default { }, Mutation: { CreatePost: async (_parent, params, context, _resolveInfo) => { - const { categoryIds } = params const { image: imageInput } = params delete params.categoryIds delete params.image @@ -92,13 +91,9 @@ export default { WITH post MATCH (author:User {id: $userId}) MERGE (post)<-[:WROTE]-(author) - WITH post - UNWIND $categoryIds AS categoryId - MATCH (category:Category {id: categoryId}) - MERGE (post)-[:CATEGORIZED]->(category) RETURN post {.*} `, - { userId: context.user.id, categoryIds, params }, + { userId: context.user.id, params }, ) const [post] = createPostTransactionResponse.records.map((record) => record.get('post')) if (imageInput) { diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index dc6a00a41..37f9dd176 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -136,7 +136,7 @@ type Post { """ ) tags: [Tag]! @relation(name: "TAGGED", direction: "OUT") - categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") + categories: [Category] @relation(name: "CATEGORIZED", direction: "OUT") comments: [Comment]! @relation(name: "COMMENTS", direction: "IN") commentsCount: Int! diff --git a/backend/src/schema/types/type/User.gql b/backend/src/schema/types/type/User.gql index e6e7191c5..08682494f 100644 --- a/backend/src/schema/types/type/User.gql +++ b/backend/src/schema/types/type/User.gql @@ -104,7 +104,7 @@ type User { shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT") shoutedCount: Int! @cypher(statement: "MATCH (this)-[:SHOUTED]->(r:Post) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)") - categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") + categories: [Category] @relation(name: "CATEGORIZED", direction: "OUT") badges: [Badge]! @relation(name: "REWARDED", direction: "IN") badgesCount: Int! @cypher(statement: "MATCH (this)<-[:REWARDED]-(r:Badge) RETURN COUNT(r)") diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index be2228845..cabf77455 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -17,6 +17,7 @@ config.stubs['client-only'] = '' config.stubs['nuxt-link'] = '' config.stubs['v-popover'] = '' +/* const categories = [ { id: 'cat3', @@ -44,6 +45,7 @@ const categories = [ icon: 'tree', }, ] +*/ describe('ContributionForm.vue', () => { let wrapper, @@ -136,7 +138,7 @@ describe('ContributionForm.vue', () => { describe('CreatePost', () => { describe('invalid form submission', () => { beforeEach(async () => { - wrapper.find(CategoriesSelect).setData({ categories }) + // wrapper.find(CategoriesSelect).setData({ categories }) postTitleInput = wrapper.find('.ds-input') postTitleInput.setValue(postTitle) await wrapper.vm.updateEditorContent(postContent) @@ -144,10 +146,10 @@ describe('ContributionForm.vue', () => { .findAll('li') .filter((language) => language.text() === 'English') englishLanguage.trigger('click') - dataPrivacyButton = await wrapper + /* dataPrivacyButton = await wrapper .find(CategoriesSelect) - .find('[data-test="category-buttons-cat12"]') - dataPrivacyButton.trigger('click') + .find('[data-test="category-buttons-cat12"]') + dataPrivacyButton.trigger('click') */ }) it('title cannot be empty', async () => { @@ -174,7 +176,7 @@ describe('ContributionForm.vue', () => { expect(mocks.$apollo.mutate).not.toHaveBeenCalled() }) - it('has at least one category', async () => { + it.skip('has at least one category', async () => { dataPrivacyButton = await wrapper .find(CategoriesSelect) .find('[data-test="category-buttons-cat12"]') @@ -183,7 +185,7 @@ describe('ContributionForm.vue', () => { expect(mocks.$apollo.mutate).not.toHaveBeenCalled() }) - it('has no more than three categories', async () => { + it.skip('has no more than three categories', async () => { wrapper.vm.formData.categoryIds = ['cat4', 'cat9', 'cat15', 'cat27'] await Vue.nextTick() wrapper.find('form').trigger('submit') @@ -200,23 +202,23 @@ describe('ContributionForm.vue', () => { content: postContent, language: 'en', id: null, - categoryIds: ['cat12'], + // categoryIds: ['cat12'], image: null, }, } postTitleInput = wrapper.find('.ds-input') postTitleInput.setValue(postTitle) await wrapper.vm.updateEditorContent(postContent) - wrapper.find(CategoriesSelect).setData({ categories }) + // wrapper.find(CategoriesSelect).setData({ categories }) englishLanguage = wrapper .findAll('li') .filter((language) => language.text() === 'English') englishLanguage.trigger('click') await Vue.nextTick() - dataPrivacyButton = await wrapper + /* dataPrivacyButton = await wrapper .find(CategoriesSelect) .find('[data-test="category-buttons-cat12"]') - dataPrivacyButton.trigger('click') + dataPrivacyButton.trigger('click') */ await Vue.nextTick() }) @@ -293,16 +295,16 @@ describe('ContributionForm.vue', () => { postTitleInput.setValue(postTitle) await wrapper.vm.updateEditorContent(postContent) categoryIds = ['cat12'] - wrapper.find(CategoriesSelect).setData({ categories }) + // wrapper.find(CategoriesSelect).setData({ categories }) englishLanguage = wrapper .findAll('li') .filter((language) => language.text() === 'English') englishLanguage.trigger('click') await Vue.nextTick() - dataPrivacyButton = await wrapper + /* dataPrivacyButton = await wrapper .find(CategoriesSelect) .find('[data-test="category-buttons-cat12"]') - dataPrivacyButton.trigger('click') + dataPrivacyButton.trigger('click') */ await Vue.nextTick() }) @@ -365,7 +367,7 @@ describe('ContributionForm.vue', () => { content: propsData.contribution.content, language: propsData.contribution.language, id: propsData.contribution.id, - categoryIds: ['cat12'], + // categoryIds: ['cat12'], image: { sensitive: false, }, @@ -380,9 +382,9 @@ describe('ContributionForm.vue', () => { expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) }) - it('supports updating categories', async () => { + it.skip('supports updating categories', async () => { expectedParams.variables.categoryIds.push('cat3') - wrapper.find(CategoriesSelect).setData({ categories }) + // wrapper.find(CategoriesSelect).setData({ categories }) await Vue.nextTick() const healthWellbeingButton = await wrapper .find(CategoriesSelect) diff --git a/webapp/components/ContributionForm/ContributionForm.vue b/webapp/components/ContributionForm/ContributionForm.vue index 0cbd90563..8db89173f 100644 --- a/webapp/components/ContributionForm/ContributionForm.vue +++ b/webapp/components/ContributionForm/ContributionForm.vue @@ -50,11 +50,6 @@ {{ contentLength }} - - - {{ formData.categoryIds.length }} / 3 - - { return { label: locale.name, value: locale.code } @@ -119,21 +112,10 @@ export default { imageAspectRatio, imageBlurred, language: languageOptions.find((option) => option.value === language) || null, - categoryIds: categories ? categories.map((category) => category.id) : [], }, formSchema: { title: { required: true, min: 3, max: 100 }, content: { required: true }, - categoryIds: { - type: 'array', - required: true, - validator: (_, value = []) => { - if (value.length === 0 || value.length > 3) { - return [new Error(this.$t('common.validations.categories'))] - } - return [] - }, - }, language: { required: true }, imageBlurred: { required: false }, }, @@ -155,7 +137,7 @@ export default { methods: { submit() { let image = null - const { title, content, categoryIds } = this.formData + const { title, content } = this.formData if (this.formData.image) { image = { sensitive: this.formData.imageBlurred, @@ -172,7 +154,6 @@ export default { variables: { title, content, - categoryIds, id: this.contribution.id || null, language: this.formData.language.value, image, diff --git a/webapp/pages/post/_id/_slug/index.vue b/webapp/pages/post/_id/_slug/index.vue index c0388da87..a2147db41 100644 --- a/webapp/pages/post/_id/_slug/index.vue +++ b/webapp/pages/post/_id/_slug/index.vue @@ -46,21 +46,6 @@ - -
- - - - - - {{ post.language.toUpperCase() }} - -
@@ -110,7 +95,6 @@