Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
const ticketExaminerSchema = new mongoose.Schema({
// write the code for model here
});
const TicketExaminer = mongoose.model("TicketExaminer", ticketExaminerSchema);
module.exports = TicketExaminer;
const express = require("express");
const TicketExaminer = require("../models/ticketExaminer");
const ticketExaminerRouter = new express.Router();
// write your code for endpoints here
module.exports = ticketExaminerRouter;
const TicketExaminer = require("../src/models/ticketExaminer");
const app = require("../src/app");
const { setupDatabase, ticketExaminerData } = require("./utils/testDB");
const request = require("supertest");
beforeEach(setupDatabase);
getTicketExaminerlength = async () => {
let len = await TicketExaminer.find().count();
return len;
};
test("getting all data", async () => {
const response = await request(app).get("/ticketExaminer");
expect(response.status).toBe(201);
expect(response.body.length).toBe(5);
for (let i = 0; i < 5; i++) {
expect(response.body[i].passenger_name).toEqual(
ticketExaminerData[i].passenger_name
);
expect(response.body[i].coach).toEqual(ticketExaminerData[i].coach);
expect(response.body[i].seat_number).toEqual(
ticketExaminerData[i].seat_number
);
expect(response.body[i].status).toEqual(ticketExaminerData[i].status);
}
});
test("getting data by id", async () => {
for (let i = 0; i < 5; i++) {
const response = await request(app).get(
`/ticketExaminer?id=${ticketExaminerData[i]._id}`
);
expect(response.status).toBe(201);
expect(response.body.length).toBe(1);
expect(response.body[0].passenger_name).toEqual(
ticketExaminerData[i].passenger_name
);
expect(response.body[0].coach).toEqual(ticketExaminerData[i].coach);
expect(response.body[0].seat_number).toEqual(
ticketExaminerData[i].seat_number
);
expect(response.body[0].status).toEqual(ticketExaminerData[i].status);
}
});
test("purchasing the product", async () => {
const id = ticketExaminerData[1]._id;
const response = await request(app).patch(`/ticketExaminer/${id}`).send({status: "occupied"});
expect(response.body.message).toBe(
"Ticket status updated"
);
const ticket = await TicketExaminer.findById(id);
expect(ticket.status).toBe("occupied");
});
test("purchasing the product(2)", async () => {
const id = ticketExaminerData[4]._id;
await request(app).patch(`/ticketExaminer/${id}`).send({status: "occupied"});
const ticket = await TicketExaminer.findById(id);
expect(ticket.status).toBe("occupied");
const response = await request(app).get('/ticketExaminer?status=occupied');
expect(response.body.message).not.toEqual("No data found");
});
test("getting data by status (no data)", async () => {
const response = await request(app).get("/ticketExaminer?status=occupied");
expect(response.status).toBe(404);
expect(response.body.message).toEqual("No data found");
});
test("getting data by status and id (no data)", async () => {
const id = ticketExaminerData[3]._id;
const response = await request(app).get(`/ticketExaminer?id=${id}&status=occupied`);
expect(response.status).toBe(404);
expect(response.body.message).toEqual("No data found");
});
test("getting data by status unoccupied", async () => {
const id = ticketExaminerData[4]._id;
await request(app)
.patch(`/ticketExaminer/${id}`)
.send({ status: "unoccupied" });
const ticket = await TicketExaminer.findById(id);
expect(ticket.status).toBe("unoccupied");
const id2 = ticketExaminerData[2]._id;
await request(app)
.patch(`/ticketExaminer/${id2}`)
.send({ status: "unoccupied" });
const ticket2 = await TicketExaminer.findById(id2);
expect(ticket2.status).toBe("unoccupied");
const response = await request(app).get("/ticketExaminer?status=unoccupied");
expect(response.status).toBe(201);
expect(response.body.length).toBe(2);
expect(response.body[0].passenger_name).toEqual(
ticketExaminerData[2].passenger_name
);
expect(response.body[0].coach).toEqual(ticketExaminerData[2].coach);
expect(response.body[0].seat_number).toEqual(
ticketExaminerData[2].seat_number
);
expect(response.body[0].status).toEqual("unoccupied");
expect(response.body[1].passenger_name).toEqual(
ticketExaminerData[4].passenger_name
);
expect(response.body[1].coach).toEqual(ticketExaminerData[4].coach);
expect(response.body[1].seat_number).toEqual(
ticketExaminerData[4].seat_number
);
expect(response.body[1].status).toEqual("unoccupied");
});
test("getting data using id and status", async () => {
const id = ticketExaminerData[1]._id;
await request(app)
.patch(`/ticketExaminer/${id}`)
.send({ status: "occupied" });
const ticket = await TicketExaminer.findById(id);
expect(ticket.status).toBe("occupied");
const response = await request(app).get(`/ticketExaminer?id=${id}&status=occupied`);
expect(response.status).toBe(201);
expect(response.body.length).toBe(1);
expect(response.body[0].passenger_name).toEqual(
ticketExaminerData[1].passenger_name
);
expect(response.body[0].coach).toEqual(ticketExaminerData[1].coach);
expect(response.body[0].seat_number).toEqual(
ticketExaminerData[1].seat_number
);
expect(response.body[0].status).toEqual("occupied");
});
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team