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';
import { createUser } from '../../../../../../test/factories/user';
@@ -31,4 +32,15 @@ describe('GET /api/v1/admin/users/:userId', () => {
const expectedPayload = getUserMock(anotherUser, anotherUserRole);
expect(response.body).toEqual(expectedPayload);
});
it('should return not found response for not existing user ID', async () => {
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
const invalidUserId = Crypto.randomUUID();
await request(app)
.get(`/api/v1/admin/users/${invalidUserId}`)
.set('Authorization', token)
.expect(404);
});
});