mirror of
https://github.com/fergalmoran/onearmy-community-platform.git
synced 2025-12-22 09:37:54 +00:00
fix: question create errors
This commit is contained in:
@@ -5,22 +5,19 @@ const item = questions[0]
|
||||
|
||||
describe('[Question]', () => {
|
||||
describe('[Create a question]', () => {
|
||||
const initialTitle = 'Health consequences'
|
||||
const initialExpectedSlug = 'health-consequences'
|
||||
const initialTitle = 'Health cost of plastic?'
|
||||
const initialExpectedSlug = 'health-cost-of-plastic'
|
||||
const initialQuestionDescription =
|
||||
"Hello! I'm wondering how people feel about the health concerns about working with melting plastic and being in environments with microplastics. I have been working with recycling plastic (hdpe) for two years now, shredding and injection molding and haven't had any bad consequences yet. But with the low knowledge around micro plastics and its effects on the human body, and many concerns and hypotheses I have been a bit concerned lately.So I would like to ask the people in this community how you are feeling about it, and if you have experienced any issues with the microplastics or gases yet, if so how long have you been working with it? And what extra steps do you take to be protected from it? I use a gas mask with dust filters"
|
||||
const category = 'exhibition'
|
||||
const tag1 = 'product'
|
||||
const tag2 = 'workshop'
|
||||
|
||||
const updatedTitle = 'Health consequences v2'
|
||||
const updatedExpectedSlug = 'health-consequences-v2'
|
||||
const updatedTitle = 'Real health cost of plastic?'
|
||||
const updatedExpectedSlug = 'real-health-cost-of-plastic'
|
||||
const updatedQuestionDescription = `${initialQuestionDescription} and super awesome goggles`
|
||||
|
||||
// TODO - Test disabled pending fix to how test runner manages firestore indexes required for operation
|
||||
// https://github.com/ONEARMY/community-platform/pull/3461
|
||||
// eslint-disable-next-line mocha/no-skipped-tests
|
||||
it.skip('[By Authenticated]', () => {
|
||||
it('[By Authenticated]', () => {
|
||||
cy.signUpNewUser()
|
||||
|
||||
cy.step('Go to create page')
|
||||
@@ -34,7 +31,10 @@ describe('[Question]', () => {
|
||||
).should('be.visible')
|
||||
|
||||
cy.step('Add title field')
|
||||
cy.get('[data-cy=field-title]').type(initialTitle).blur({ force: true })
|
||||
cy.get('[data-cy=field-title]')
|
||||
.clear()
|
||||
.type(initialTitle)
|
||||
.blur({ force: true })
|
||||
|
||||
cy.step('Add title description')
|
||||
cy.get('[data-cy=field-description]').type(initialQuestionDescription, {
|
||||
@@ -105,10 +105,12 @@ describe('[Question]', () => {
|
||||
cy.visit(`/questions/${initialExpectedSlug}`)
|
||||
cy.contains(updatedTitle)
|
||||
|
||||
cy.step('All updated fields visiable on list')
|
||||
cy.visit('/questions')
|
||||
cy.contains(updatedTitle)
|
||||
cy.contains(category)
|
||||
// Commented out until test indexes issue solved
|
||||
//
|
||||
// cy.step('All updated fields visiable on list')
|
||||
// cy.visit('/questions')
|
||||
// cy.contains(updatedTitle)
|
||||
// cy.contains(category)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
Cypress.on('uncaught:exception', (err) => {
|
||||
// This should be temporary while we sort out a new approach with our
|
||||
// indexing rules applied.
|
||||
if (err.message.includes('The query requires an index.')) {
|
||||
return false
|
||||
}
|
||||
if (err.message.includes('No document to update')) {
|
||||
const skipErrors = [
|
||||
'The query requires an index.',
|
||||
'No document to update',
|
||||
'KeyPath previousSlugs',
|
||||
'KeyPath slug',
|
||||
]
|
||||
|
||||
const foundSkipError = skipErrors.find((error) => err.message.includes(error))
|
||||
|
||||
if (foundSkipError) {
|
||||
return false
|
||||
}
|
||||
|
||||
// we still want to ensure there are no other unexpected
|
||||
// errors, so we let them fail the test
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ export const questions = {
|
||||
KP3McutTpuEWz06G5EY1: true,
|
||||
Wk6RnHHFfKSiI71BlM8r: true,
|
||||
},
|
||||
title: 'The first test question',
|
||||
title: 'The first test question?',
|
||||
total_views: 3,
|
||||
votedUsefulBy: [
|
||||
'demo_user',
|
||||
|
||||
@@ -28,7 +28,7 @@ export const QuestionCategoryField = () => {
|
||||
}
|
||||
|
||||
initCategories()
|
||||
}, categories)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<FormFieldWrapper htmlFor={name} text={title}>
|
||||
|
||||
@@ -47,6 +47,7 @@ export const QuestionTitleField = (props: IProps) => {
|
||||
minLength={QUESTION_MIN_TITLE_LENGTH}
|
||||
maxLength={QUESTION_MAX_TITLE_LENGTH}
|
||||
showCharacterCount
|
||||
onBlur
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
)
|
||||
|
||||
@@ -64,6 +64,7 @@ export const QuestionForm = (props: IProps) => {
|
||||
const numberOfImageInputsAvailable = values?.images
|
||||
? Math.min(values.images.length + 1, QUESTION_MAX_IMAGES)
|
||||
: 1
|
||||
|
||||
return (
|
||||
<Flex mx={-2} bg={'inherit'} sx={{ flexWrap: 'wrap' }}>
|
||||
<Flex
|
||||
|
||||
@@ -11,7 +11,6 @@ import { toggleDocSubscriberStatusByUserName } from '../common/toggleDocSubscrib
|
||||
import { toggleDocUsefulByUser } from '../common/toggleDocUsefulByUser'
|
||||
|
||||
import type { IModerationStatus } from 'oa-shared/models'
|
||||
import type { IUser } from 'src/models'
|
||||
import type { IConvertedFileMeta } from 'src/types'
|
||||
import type { IQuestion, IQuestionDB } from '../../models/question.models'
|
||||
import type { DBEndpoint } from '../databaseV2/endpoints'
|
||||
@@ -81,6 +80,10 @@ export class QuestionStore extends ModuleStore {
|
||||
|
||||
public async upsertQuestion(values: IQuestion.FormInput) {
|
||||
logger.info(`upsertQuestion:`, { values, activeUser: this.activeUser })
|
||||
|
||||
const user = this.activeUser
|
||||
if (!user) return
|
||||
|
||||
const dbRef = this.db
|
||||
.collection<IQuestion.Item>(COLLECTION_NAME)
|
||||
.doc(values?._id)
|
||||
@@ -95,16 +98,14 @@ export class QuestionStore extends ModuleStore {
|
||||
|
||||
const slug = await this.setSlug(values)
|
||||
const previousSlugs = this.setPreviousSlugs(values, slug)
|
||||
const _createdBy = values._createdBy ?? this.activeUser?.userName
|
||||
const user = this.activeUser as IUser
|
||||
const creatorCountry = this.getCreatorCountry(user, values)
|
||||
const _createdBy = user.userName
|
||||
const creatorCountry = getUserCountry(user)
|
||||
|
||||
const moderation =
|
||||
values.moderation || ('accepted' as IModerationStatus.ACCEPTED)
|
||||
|
||||
const keywords = getKeywords(values.title + ' ' + values.description)
|
||||
if (_createdBy) {
|
||||
keywords.push(_createdBy)
|
||||
}
|
||||
|
||||
const images = values.images
|
||||
? await this.loadImages(values.images, dbRef.id)
|
||||
@@ -173,17 +174,6 @@ export class QuestionStore extends ModuleStore {
|
||||
}
|
||||
}
|
||||
|
||||
private getCreatorCountry(user: IUser, values: IQuestion.FormInput) {
|
||||
const { creatorCountry, _createdBy } = values
|
||||
const userCountry = getUserCountry(user)
|
||||
|
||||
return (_createdBy && _createdBy === user.userName) || !_createdBy
|
||||
? userCountry
|
||||
: creatorCountry
|
||||
? creatorCountry
|
||||
: ''
|
||||
}
|
||||
|
||||
private async _getQuestionItemBySlug(
|
||||
slug: string,
|
||||
): Promise<IQuestionDB | null> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { IUser } from 'src/models/user.models'
|
||||
|
||||
export const getUserCountry = (user: IUser) => {
|
||||
export const getUserCountry = (user: IUser): string => {
|
||||
const userCountry =
|
||||
user.country?.toLowerCase() ||
|
||||
user.location?.countryCode?.toLowerCase() ||
|
||||
|
||||
Reference in New Issue
Block a user