test: Cover not found responses for API endpoint tests
This commit is contained in:
@@ -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 { createUser } from '../../../../../../test/factories/user.js';
|
||||
@@ -31,5 +32,14 @@ describe('GET /api/v1/admin/app-auth-clients/:appAuthClientId', () => {
|
||||
const expectedPayload = getAdminAppAuthClientMock(currentAppAuthClient);
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing app auth client ID', async () => {
|
||||
const invalidAppAuthClientId = Crypto.randomUUID();
|
||||
|
||||
await request(app)
|
||||
.get(`/api/v1/admin/app-auth-clients/${invalidAppAuthClientId}`)
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
|
@@ -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';
|
||||
@@ -31,4 +32,15 @@ describe('GET /api/v1/admin/saml-auth-provider/:samlAuthProviderId', () => {
|
||||
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing saml auth provider ID', async () => {
|
||||
vi.spyOn(license, 'hasValidLicense').mockResolvedValue(true);
|
||||
|
||||
const invalidSamlAuthProviderId = Crypto.randomUUID();
|
||||
|
||||
await request(app)
|
||||
.get(`/api/v1/admin/saml-auth-providers/${invalidSamlAuthProviderId}`)
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
|
@@ -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 { createUser } from '../../../../../test/factories/user.js';
|
||||
@@ -28,4 +29,13 @@ describe('GET /api/v1/app-auth-clients/:id', () => {
|
||||
const expectedPayload = getAppAuthClientMock(currentAppAuthClient);
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing app auth client ID', async () => {
|
||||
const invalidAppAuthClientId = Crypto.randomUUID();
|
||||
|
||||
await request(app)
|
||||
.get(`/api/v1/app-auth-clients/${invalidAppAuthClientId}`)
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { 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';
|
||||
@@ -68,4 +69,20 @@ describe('GET /api/v1/flows/:flowId', () => {
|
||||
|
||||
expect(response.body).toEqual(expectedPayload);
|
||||
});
|
||||
|
||||
it('should return not found response for not existing flow id', async () => {
|
||||
await createPermission({
|
||||
action: 'read',
|
||||
subject: 'Flow',
|
||||
roleId: currentUserRole.id,
|
||||
conditions: [],
|
||||
});
|
||||
|
||||
const invalidFlowId = Crypto.randomUUID();
|
||||
|
||||
await request(app)
|
||||
.get(`/api/v1/flows/${invalidFlowId}`)
|
||||
.set('Authorization', token)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import logger from './logger.js';
|
||||
import { NotFoundError, DataError } from 'objection';
|
||||
import objection from 'objection';
|
||||
const { NotFoundError, DataError } = objection;
|
||||
|
||||
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
Reference in New Issue
Block a user