mirror of
https://github.com/directus/directus.git
synced 2026-02-15 18:24:59 -05:00
* build: ➕ add vitest and update test scripts * build: 🔧 add vitest config * build: ✅ Migrate tests to vitest Remove jest references from test api test files and replace with vitest equivalents. Tests: 13 tests are failing. * build: 🚚 move vite.config.ts to api/src folder * build: 🔥 remove unused vitest.config from api root * build: ✅ import vitest modules for tests * build: ✅ add type conversion for actual object * Finish switch from Jest to Vitest in API * Replace some leftovers * Load "sharp" before tests * Try with cjs * Temporary enable verbose reporter * Try with globalSetup * Fix path to globalSetup * Provide default export in globalSetup * Final clean-up * Remove @vitest/ui & update vitest to 0.25.0 * Add vitest c8 coverage dependency * Update vitest to v0.25.1 * Replace unnecessary Vitest workaround * Rework new tests * Resolve build errors Co-authored-by: Dorian C Brown <brown.3794@gmail.com> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
27 lines
875 B
TypeScript
27 lines
875 B
TypeScript
import isDirectusJWT from '../../src/utils/is-directus-jwt';
|
|
import jwt from 'jsonwebtoken';
|
|
import { test, expect } from 'vitest';
|
|
|
|
test('Returns false for non JWT string', () => {
|
|
const result = isDirectusJWT('test');
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('Returns false for JWTs with text payload', () => {
|
|
const token = jwt.sign('plaintext', 'secret');
|
|
const result = isDirectusJWT(token);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test(`Returns false if token issuer isn't "directus"`, () => {
|
|
const token = jwt.sign({ payload: 'content' }, 'secret', { issuer: 'rijk' });
|
|
const result = isDirectusJWT(token);
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test(`Returns true if token is valid JWT and issuer is "directus"`, () => {
|
|
const token = jwt.sign({ payload: 'content' }, 'secret', { issuer: 'directus' });
|
|
const result = isDirectusJWT(token);
|
|
expect(result).toBe(true);
|
|
});
|