Hi,
I have this Issues schema:
// Require Mongoose
import mongoose from "mongoose";
import { rolesSchema } from "./roles.js";
import { storyPointSchema } from "./storyPoint.js";
// Define a schema
const Schema = mongoose.Schema;
/**
* Issues Report Schema
*/
export const issuesSchema = new Schema({
team: {
required: true,
type: String,
},
teamRoles: {
type: [rolesSchema],
required: true
},
ticketId: {
type: String,
required: true
},
issueName: {
type: String,
required: true,
},
description: {
type: String,
required: true
},
issueType: {
type: String,
enum: ['story', 'bug', 'task', 'sub-task', 'epic'],
default: 'story',
required: true
},
storyPoints: {
accepted: storyPointSchema,
committed: storyPointSchema,
completed: storyPointSchema,
estimated: storyPointSchema,
actual: storyPointSchema
}
}, {_id: false})
/**
* Calculate Full Name
* Virtual for ticket assignee's full name
*/
issuesSchema.virtual('fullname').get(function () {
let fullName = ""
if (this.firstName && this.lastName) {
fullName = `${this.firstName}, ${this.lastName}`
}
return fullName
})
export const Issues = mongoose.model('Issues', issuesSchema)
and the two embedded document schemas:
export const rolesSchema = new Schema({
firstName: {
type: String,
required: true
},
lastName:{
type: String,
required: true
},
role: {
type:String,
required: true
}
})
export const Roles = mongoose.model('Roles', rolesSchema)
// Require Mongoose
import mongoose from "mongoose";
// Define a schema
const Schema = mongoose.Schema;
/**
* Story Point Report Schema
*/
export const storyPointSchema = new Schema([{
storyPoint: {
type: Number,
required: true,
enum: [0,1, 2, 3, 5, 8, 13]
}
}])
In unit testing I can get all errors that the validators throw when required is missing or wrong format data
Here is the validations errors:
{
"errors": {
"description": {
"name": "ValidatorError",
"message": "Path `description` is required.",
"properties": {
"message": "Path `description` is required.",
"type": "required",
"path": "description"
},
"kind": "required",
"path": "description"
},
"issueName": {
"name": "ValidatorError",
"message": "Path `issueName` is required.",
"properties": {
"message": "Path `issueName` is required.",
"type": "required",
"path": "issueName"
},
"kind": "required",
"path": "issueName"
},
"ticketId": {
"name": "ValidatorError",
"message": "Path `ticketId` is required.",
"properties": {
"message": "Path `ticketId` is required.",
"type": "required",
"path": "ticketId"
},
"kind": "required",
"path": "ticketId"
},
"team": {
"name": "ValidatorError",
"message": "Path `team` is required.",
"properties": {
"message": "Path `team` is required.",
"type": "required",
"path": "team"
},
"kind": "required",
"path": "team"
},
"issueType": {
"name": "ValidatorError",
"message": "`foo` is not a valid enum value for path `issueType`.",
"properties": {
"message": "`foo` is not a valid enum value for path `issueType`.",
"type": "enum",
"enumValues": [
"story",
"bug",
"task",
"sub-task",
"epic"
],
"path": "issueType",
"value": "foo"
},
"kind": "enum",
"path": "issueType",
"value": "foo"
}
},
"_message": "Issues validation failed",
"name": "ValidationError",
"message": "Issues validation failed: description: Path `description` is required., issueName: Path `issueName` is required., ticketId: Path `ticketId` is required., team: Path `team` is required., issueType: `foo` is not a valid enum value for path `issueType`."
Can you see any issues with these schemas to see why both embedded documents fail to register any errors relevant to roles or story points?