Skip to content

Commit

Permalink
Aftral[premieroctet#120]: fixed helpdeskconversation
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Aug 29, 2024
1 parent 6480388 commit 42aafbf
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 10 deletions.
17 changes: 17 additions & 0 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ declareComputedField({model: 'post', field: 'liked', getterFn: isLiked, requires
// Ticket start
declareEnumField({model:'ticket', field: 'status', instance: 'String', enumValues: TICKET_STATUS})
declareEnumField({model:'ticket', field: 'tag', instance: 'String', enumValues: TICKET_TAG})
// declareVirtualField({model:`ticket`, field: `conversation`, instance: `Array`, multiple: false,
// caster: {
// instance: `ObjectID`,
// options: {ref: `ticket`}
// }
// })
// Ticket End

// Permission start
Expand All @@ -201,6 +207,17 @@ declareVirtualField({model: `group`, field: `available_trainees_count`, instance
declareVirtualField({model: `group`, field: `excluded_trainees_count`, instance: `Number`, requires: `trainees,available_trainees`})
// Group end

// HelpDeskConversation start
const CONVERSATION_MODELS = [`helpDeskConversation`, `sessionConversation`, `conversation`]
CONVERSATION_MODELS.forEach(model => {
declareVirtualField({model, field: 'messages', instance: 'Array', multiple: true,
caster: {
instance: 'ObjectID',
options: {ref: 'message'}},
})
})
// HelpDeskConversation end

const preCreate = async ({model, params, user}) => {
params.creator=params.creator || user._id
params.last_updater=user._id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ const ConversationSchema = new Schema({
type: mongoose.Schema.Types.ObjectId,
ref: 'user',
},
messages: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'message',
}],
newest_message: {
type: mongoose.Schema.Types.ObjectId,
ref: 'message',
},
},
schemaOptions)
},schemaOptions)

ConversationSchema.virtual('messages', {
ref: 'message',
localField: '_id',
foreignField: 'conversation',
})

module.exports=ConversationSchema
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ const HelpDeskConversationSchema = new Schema({
user: { //trainee, trainer, conceptor
type: Schema.Types.ObjectId,
ref: `user`,
required: [true, `L'utilisateur est obligatoire`]
},
ticket: {
type: Schema.Types.ObjectId,
ref: `ticket`,
required: [true, `Le ticket est obligatoire`]
},
block: {
type: Schema.Types.ObjectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const SessionConversationSchema = new Schema({
type: Schema.Types.ObjectId,
ref: `user`,
},
session: {
group: {
type: Schema.Types.ObjectId,
ref: `ticket`,
}
ref: `group`,
},
},
schemaOptions)

Expand Down
1 change: 0 additions & 1 deletion backend/web/tests/aftral-lms/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ describe('User', () => {
})

it('must return homeworks submitted count', async() => {

const [data] = await loadFromDb({model:`block`, user:conceptor, id, fields:[`session`,`homeworks_missing_count`,`homeworks`,`homeworks_submitted_count`,`trainees_count`]})
expect(data.homeworks_missing_count).toEqual(0)
expect(data.homeworks_submitted_count).toEqual(2)
Expand Down
79 changes: 79 additions & 0 deletions backend/web/tests/aftral-lms/ticket.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const mongoose = require('mongoose')
const { MONGOOSE_OPTIONS, loadFromDb, idEqual } = require('../../server/utils/database')
require('../../server/plugins/aftral-lms/functions')
const User = require('../../server/models/User')
const Resource = require('../../server/models/Resource')
const Sequence = require('../../server/models/Sequence')
const Module = require('../../server/models/Module')
const Program = require('../../server/models/Program')
const Session = require('../../server/models/Session')
require('../../server/models/Certification')
require('../../server/models/Permission')
require('../../server/models/PermissionGroup')
const { ROLE_APPRENANT, ROLE_FORMATEUR, RESOURCE_TYPE_PDF, ACHIEVEMENT_RULE_CHECK, ACHIEVEMENT_RULE_SUCCESS, ACHIEVEMENT_RULE_CONSULT, RESOURCE_TYPE_VIDEO, ACHIEVEMENT_RULE_DOWNLOAD, ROLE_CONCEPTEUR, BLOCK_STATUS_CURRENT, BLOCK_STATUS_FINISHED, BLOCK_STATUS_UNAVAILABLE, ACHIEVEMENT_RULE, ROLE_HELPDESK } = require('../../server/plugins/aftral-lms/consts')
const Block = require('../../server/models/Block')
const Homework = require('../../server/models/Homework')
const Progress = require('../../server/models/Progress')
const ProductCode = require('../../server/models/ProductCode')
const { addChildAction } = require('../../server/plugins/aftral-lms/actions')
const HelpDeskConversation = require('../../server/models/HelpDeskConversation')
const Ticket = require('../../server/models/Ticket')
const Message = require('../../server/models/Message')
require('../../server/models/Feed')
require('../../server/models/Certification')

describe(`Ticket`, () => {
let user, ticket, conversation, message, helpDesk
beforeAll(async() => {
await mongoose.connect(`mongodb://localhost/aftral-test`, MONGOOSE_OPTIONS)

user = await User.create({
firstname: `John`,
lastname: `Doe`,
role: ROLE_CONCEPTEUR,
password: `Test`,
email: `t@t.com`,
})

helpDesk = await User.create({
firstname: `Jeanette`,
lastname: `Doe`,
role: ROLE_HELPDESK,
password: `Test`,
email: `t@t.com`,
})

ticket = await Ticket.create({
user: user._id,
content: `content`,
title: `Test ticket`
})

conversation = await HelpDeskConversation.create({
user: user._id,
ticket: ticket._id
})

ticket.conversation = conversation._id
await ticket.save()

message = await Message.create({
conversation: conversation._id,
sender: user._id,
content: `Test message`
})
})

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

it(`must return ticket conversation messages`, async() => {
const [data] = await loadFromDb({
model: `ticket`,
fields: [`conversation.messages`]
})
expect(data.conversation.messages[0].content).toEqual(`Test message`)
})
})

0 comments on commit 42aafbf

Please sign in to comment.