mirror of
https://github.com/directus/directus.git
synced 2026-02-04 23:55:13 -05:00
* add unit tests to several API util functions * fix timezone tests to account for daylight saving * add a note for future reference * Update api/src/utils/get-date-formatted.test.ts Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> * remove unnecessary note as it is not an issue * fix getEnv mock in validate-env test Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
42 lines
892 B
TypeScript
42 lines
892 B
TypeScript
import { afterEach, beforeAll, expect, test, vi } from 'vitest';
|
|
|
|
import { validateEnv } from './validate-env';
|
|
import logger from '../logger';
|
|
|
|
vi.mock('../env', () => ({
|
|
getEnv: vi.fn().mockReturnValue({
|
|
PRESENT_TEST_VARIABLE: true,
|
|
}),
|
|
}));
|
|
vi.mock('../logger', () => ({
|
|
default: {
|
|
error: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
vi.mock('process', () => ({
|
|
exit: vi.fn(),
|
|
}));
|
|
|
|
beforeAll(() => {
|
|
vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
test('should not have any error when key is present', () => {
|
|
validateEnv(['PRESENT_TEST_VARIABLE']);
|
|
|
|
expect(logger.error).not.toHaveBeenCalled();
|
|
expect(process.exit).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('should have error when key is missing', () => {
|
|
validateEnv(['ABSENT_TEST_VARIABLE']);
|
|
|
|
expect(logger.error).toHaveBeenCalled();
|
|
expect(process.exit).toHaveBeenCalled();
|
|
});
|