Skip to content

Commit 81c24ea

Browse files
Sherin-2711i-am-that-guy
authored andcommitted
Updated test for delete interview experience
1 parent 15cd055 commit 81c24ea

1 file changed

Lines changed: 46 additions & 13 deletions

File tree

tests/Interview.test.ts

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,14 @@ describe('updateInterviewById', () => {
309309

310310

311311
describe('deleteInterviewById', () => {
312+
afterEach(() => {
313+
jest.restoreAllMocks();
314+
});
315+
312316
it('should return 200 and success message', async () => {
313317
const req: any = {
314-
params: {
315-
id: '1',
316-
},
318+
params: { id: '1' },
319+
body: { memberId: 'user_123' },
317320
};
318321

319322
const res: any = {
@@ -331,13 +334,8 @@ describe('deleteInterviewById', () => {
331334
memberId: 'user_123',
332335
};
333336

334-
jest
335-
.spyOn(interviewService, 'getInterviewById')
336-
.mockResolvedValue(mockInterview);
337-
338-
jest
339-
.spyOn(interviewService, 'deleteInterviewById')
340-
.mockResolvedValue();
337+
jest.spyOn(interviewService, 'getInterviewById').mockResolvedValue(mockInterview);
338+
jest.spyOn(interviewService, 'deleteInterviewById').mockResolvedValue();
341339

342340
await deleteInterviewById(req, res);
343341

@@ -351,22 +349,57 @@ describe('deleteInterviewById', () => {
351349
it('should throw 400 for invalid interview ID', async () => {
352350
const req: any = {
353351
params: { id: 'invalid' },
352+
body: { memberId: 'user_123' },
354353
};
355354

356355
const res: any = {};
356+
357+
await expect(deleteInterviewById(req, res)).rejects.toThrow(ApiError);
358+
});
359+
360+
it('should throw 400 if memberId is missing', async () => {
361+
const req: any = {
362+
params: { id: '1' },
363+
body: {},
364+
};
365+
366+
const res: any = {};
367+
357368
await expect(deleteInterviewById(req, res)).rejects.toThrow(ApiError);
358369
});
359370

360371
it('should throw 404 if interview not found', async () => {
361372
const req: any = {
362373
params: { id: '999' },
374+
body: { memberId: 'user_123' },
363375
};
364376

365377
const res: any = {};
366378

367-
jest
368-
.spyOn(interviewService, 'getInterviewById')
369-
.mockResolvedValue(null);
379+
jest.spyOn(interviewService, 'getInterviewById').mockResolvedValue(null);
380+
381+
await expect(deleteInterviewById(req, res)).rejects.toThrow(ApiError);
382+
});
383+
384+
it('should throw 401 if memberId does not match', async () => {
385+
const req: any = {
386+
params: { id: '1' },
387+
body: { memberId: 'wrong_user' },
388+
};
389+
390+
const res: any = {};
391+
392+
const mockInterview = {
393+
id: 1,
394+
company: 'Google',
395+
role: 'SDE',
396+
verdict: Verdict.Selected,
397+
content: 'Nice',
398+
isAnonymous: false,
399+
memberId: 'user_123',
400+
};
401+
402+
jest.spyOn(interviewService, 'getInterviewById').mockResolvedValue(mockInterview);
370403

371404
await expect(deleteInterviewById(req, res)).rejects.toThrow(ApiError);
372405
});

0 commit comments

Comments
 (0)