Initial Version of sitemap.xml spec
This commit is contained in:
103
tests/unit/utils.test.js
Normal file
103
tests/unit/utils.test.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Unit Tests for General Utilities
|
||||
* Tests request ID generation and document ID validation
|
||||
*/
|
||||
|
||||
import { test, describe } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
// Set up globals that server.js would provide
|
||||
globalThis.crypto = crypto;
|
||||
globalThis.config = { google: {}, server: {}, sitemap: {} };
|
||||
|
||||
import { generateRequestId, validateDocumentId } from '../../src/proxy.js';
|
||||
|
||||
describe('Unit: Request ID Generation', () => {
|
||||
|
||||
test('T046: Should generate unique request ID', () => {
|
||||
const id1 = generateRequestId();
|
||||
const id2 = generateRequestId();
|
||||
|
||||
assert.ok(id1, 'Should generate ID');
|
||||
assert.ok(id2, 'Should generate second ID');
|
||||
assert.notStrictEqual(id1, id2, 'IDs should be unique');
|
||||
});
|
||||
|
||||
test('T046: Should generate ID with req_ prefix', () => {
|
||||
const id = generateRequestId();
|
||||
assert.ok(id.startsWith('req_'), 'Should start with req_ prefix');
|
||||
});
|
||||
|
||||
test('T046: Should generate valid UUID format', () => {
|
||||
const id = generateRequestId();
|
||||
const uuidPart = id.substring(4); // Remove 'req_' prefix
|
||||
|
||||
// UUID v4 format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
assert.ok(uuidRegex.test(uuidPart), 'Should be valid UUID v4');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Unit: Document ID Validation', () => {
|
||||
|
||||
test('T046: Should accept valid Google Drive IDs', () => {
|
||||
const validIds = [
|
||||
'1BxAA_example123',
|
||||
'abcdefghijklmnop',
|
||||
'12345678',
|
||||
'test-doc-id_123',
|
||||
'ABCDEFGH-IJKLMNOP_12345678'
|
||||
];
|
||||
|
||||
for (const id of validIds) {
|
||||
assert.ok(
|
||||
validateDocumentId(id),
|
||||
`Should accept valid ID: ${id}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('T046: Should reject IDs that are too short', () => {
|
||||
const shortId = 'abc1234'; // 7 characters (minimum is 8)
|
||||
assert.strictEqual(validateDocumentId(shortId), false);
|
||||
});
|
||||
|
||||
test('T046: Should reject IDs that are too long', () => {
|
||||
const longId = 'a'.repeat(129); // 129 characters (maximum is 128)
|
||||
assert.strictEqual(validateDocumentId(longId), false);
|
||||
});
|
||||
|
||||
test('T046: Should reject IDs with invalid characters', () => {
|
||||
const invalidIds = [
|
||||
'invalid@id',
|
||||
'invalid id', // space
|
||||
'invalid/id', // slash
|
||||
'invalid#id', // hash
|
||||
'invalid.id', // period
|
||||
'invalid$id' // dollar sign
|
||||
];
|
||||
|
||||
for (const id of invalidIds) {
|
||||
assert.strictEqual(
|
||||
validateDocumentId(id),
|
||||
false,
|
||||
`Should reject invalid ID: ${id}`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('T046: Should reject null, undefined, and non-strings', () => {
|
||||
assert.strictEqual(validateDocumentId(null), false);
|
||||
assert.strictEqual(validateDocumentId(undefined), false);
|
||||
assert.strictEqual(validateDocumentId(123), false);
|
||||
assert.strictEqual(validateDocumentId({}), false);
|
||||
assert.strictEqual(validateDocumentId([]), false);
|
||||
});
|
||||
|
||||
test('T046: Should reject empty string', () => {
|
||||
assert.strictEqual(validateDocumentId(''), false);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user