Hi all i am very new to typescript i have written test cases for the routes in my project
My route.test.ts
file
import request from "supertest";
import { app} from "../..";
describe('Virtual Class test',()=>{
//getting the student with valid id's
describe('get student',()=>{
it('it should return student link based on id',async()=>{
const res=await request(app).get('/api/v1/virtual_class/student?meetingId=12316sa&contactId=0037200000AxrvUAAR');
expect(res.statusCode).toBe(200)
})
})
//getting the student with invalid id's
describe('get student',()=>{
it('it should return student link based on id',async()=>{
const res=await request(app).get('/api/v1/virtual_class/student?meetingId=12316sa&contactId=003720R');
expect(res.statusCode).toBe(400)
})
})
//if the params are missing
describe('get student',()=>{
it('it should return student link based on id',async()=>{
const res=await request(app).get('/api/v1/virtual_class/student?meetingId=12316sa');
expect(res.statusCode).toBe(422)
})
})
//If we don't have params to fetch faculty link
describe('get faculty',()=>{
it('return the faculty based on data we are passing',async()=>{
const res=await request(app).post('/api/v1/virtual_class/faculty').send({
redirectUrl: "redirectUrl",
meetingId: "meetingId",
meetingName: "meetingName",
fullName: "fullName",
contactId: "contactId",
})
expect(res.statusCode).toBe(422)
})
})
//get faculty link by passing params
describe('get faculty',()=>{
it('return the faculty based on data we are passing',async()=>{
const res=await request(app).post('/api/v1/virtual_class/faculty').send({
redirectUrl: "redirectUrl",
meetingId: "meetingId",
meetingName: "meetingName",
fullName: "fullName",
contactId: "contactId",
email: "email",
courseOfferingId: "courseOfferingId",
startTime: "startTime",
endTime: "endTime",
sessionName: "sessionName",
date: "date",
sessionId: "sessionId",
})
expect(res.statusCode).toBe(200)
})
})
})
This is working as expected but is there any way to test the specific function ,all the exported function from a file
My function
static startAttendance = async (
meetingId: string,
req: express.Request,
res: express.Response
) => {
try {
const config: string = await configHelper.getConfigData();
const data = JSON.parse(config);
const configdata: any = JSON.parse(data);
const channel = configdata.virtualClass;
switch (channel) {
case “zoom”:
zoomHelper.processZoomMeeting(req, res);
break;
case “bbb”:
bbbHelper.startBBBAttendance(meetingId);
break;
case “meet”:
meetHelper.generateMeetingLink(req, res);
break;
default:
break;
}
} catch (err) {
console.log(“Error in Start Attendence”, err);
}
};
May be similiar to the function on the top