Skip to content

Commit

Permalink
Refactor formController.js and formRoutes.js for improved form creati…
Browse files Browse the repository at this point in the history
…on and retrieval
  • Loading branch information
yunji0387 committed Apr 22, 2024
1 parent 4bfd30c commit a4416f0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion controllers/formController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.createForm = async (req, res) => {
const session = await mongoose.startSession();
session.startTransaction();
try {
const { formData } = req.body;
const formData = req.body;
console.log('Received form data:', formData);
const newForm = new FormData(formData); // Assuming formData should not be nested under 'formData'

Expand Down
72 changes: 48 additions & 24 deletions test/form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@ before(async () => {

describe('Form CRUD Operations', function () {
const testFormId = 1;
// const formData = {
// formData: {
// jobName: "Initial Job",
// customerName: "Initial Customer",
// materialID: ["001", "002"],
// materialName: ["Paper", "Plastic"],
// printType: "Digital",
// printCustomerName: false,
// printCustomText: false,
// customText: "",
// designNotes: "Initial notes",
// formId: testFormId
// }
// };
const formData = {
formData: {
jobName: "Initial Job",
customerName: "Initial Customer",
materialID: ["001", "002"],
materialName: ["Paper", "Plastic"],
printType: "Digital",
printCustomerName: false,
printCustomText: false,
customText: "",
designNotes: "Initial notes",
formId: testFormId
}
jobName: "Initial Job",
customerName: "Initial Customer",
materialID: ["001", "002"],
materialName: ["Paper", "Plastic"],
printType: "Digital",
printCustomerName: false,
printCustomText: false,
customText: "",
designNotes: "Initial notes",
formId: testFormId
};

before(async function () {
Expand Down Expand Up @@ -92,19 +104,31 @@ describe('Form CRUD Operations', function () {
});

it('should return an array of forms if multiple forms are found', async function () {
// const formData2 = {
// formData: {
// jobName: "Second Job",
// customerName: "Second Customer",
// materialID: ["003", "004"],
// materialName: ["Metal", "Wood"],
// printType: "Offset",
// printCustomerName: true,
// printCustomText: true,
// customText: "Custom Text",
// designNotes: "Second notes",
// formId: 2
// }
// };
const formData2 = {
formData: {
jobName: "Second Job",
customerName: "Second Customer",
materialID: ["003", "004"],
materialName: ["Metal", "Wood"],
printType: "Offset",
printCustomerName: true,
printCustomText: true,
customText: "Custom Text",
designNotes: "Second notes",
formId: 2
}
jobName: "Second Job",
customerName: "Second Customer",
materialID: ["003", "004"],
materialName: ["Metal", "Wood"],
printType: "Offset",
printCustomerName: true,
printCustomText: true,
customText: "Custom Text",
designNotes: "Second notes",
formId: 2
};
await request.post('/forms').send(formData);
await request.post('/forms').send(formData2);
Expand Down

0 comments on commit a4416f0

Please sign in to comment.