Skip to content

Commit

Permalink
Sosynpl[premieroctet#155]: added creator to question
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Jul 29, 2024
1 parent 577f88d commit 0605f9c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/web/server/plugins/sosynpl/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ const preProcessGet = async ({ model, fields, id, user, params }) => {
id = s._id
// }
}
if (model == 'question') params.creator=user
//If no Id when looking for questions, it means we're looking for FAQ and not all announces' questions
if (model == 'question' && !id) params['filter.announce'] = null
return { model, fields, id, user, params }
Expand Down
5 changes: 5 additions & 0 deletions backend/web/server/plugins/sosynpl/schemas/QuestionSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const { schemaOptions } = require('../../../utils/schemas')
const Schema = mongoose.Schema

const QuestionSchema = new Schema({
creator: {
type: Schema.Types.ObjectId,
ref: 'customerFreelance',
required: [true, `L'auteur est obligatoire`]
},
title: {
type: String,
required: [true, `Le titre est obligatoire`],
Expand Down
31 changes: 31 additions & 0 deletions backend/web/tests/sosynpl/question.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const mongoose = require('mongoose')
const moment = require('moment')
const { MONGOOSE_OPTIONS, loadFromDb } = require('../../server/utils/database')
const CustomerFreelance = require('../../server/models/CustomerFreelance')
const Question = require('../../server/models/Question')
const { CUSTOMER_DATA } = require('./data/base_data')
require('../../server/plugins/sosynpl/functions')
require('../../server/models/Sector')
require('../../server/models/JobFile')
require('../../server/models/Job')

describe('Questions', () => {

beforeAll(async () => {
const DBNAME = `test${moment().unix()}`
await mongoose.connect(`mongodb://localhost/${DBNAME}`, MONGOOSE_OPTIONS)
})

afterAll(async () => {
await mongoose.connection.dropDatabase()
await mongoose.connection.close()
})

it('must get question creator', async() => {
await CustomerFreelance.create({...CUSTOMER_DATA})
const user = await CustomerFreelance.findOne({})
await Question.create({creator: user._id, title:'Test'})
const [question] = await loadFromDb({model:'question', user, fields:['creator.fullname','title']})
expect(question.creator.fullname).toEqual(user.fullname)
})
})

0 comments on commit 0605f9c

Please sign in to comment.