test: Cover not found responses for API endpoint tests

This commit is contained in:
Faruk AYDIN
2024-02-26 01:40:20 +01:00
parent 4afe7c6b46
commit 404ea94dd2
7 changed files with 76 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import { vi, describe, it, expect, beforeEach } from 'vitest';
import request from 'supertest';
import Crypto from 'crypto';
import app from '../../../../../app.js';
import createAuthTokenByUserId from '../../../../../helpers/create-auth-token-by-user-id.js';
import { createRole } from '../../../../../../test/factories/role.js';
@@ -20,7 +21,7 @@ describe('GET /api/v1/admin/roles/:roleId', () => {
token = createAuthTokenByUserId(currentUser.id);
});
it('should return roles', async () => {
it('should return role', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const response = await request(app)
@@ -35,4 +36,15 @@ describe('GET /api/v1/admin/roles/:roleId', () => {
expect(response.body).toEqual(expectedPayload);
});
it('should return not found response for not existing role ID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const invalidRoleId = Crypto.randomUUID();
await request(app)
.get(`/api/v1/admin/roles/${invalidRoleId}`)
.set('Authorization', token)
.expect(404);
});
});