Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/tests/controllerHelpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, it, expect } from '@jest/globals';
import { validateTechnologyArray, FIRESTORE_IN_LIMIT } from '../utils/controllerHelpers.js';

describe('validateTechnologyArray', () => {
it('should return an array for a valid comma-separated string', () => {
const input = 'WordPress,Google Analytics,PHP';
const result = validateTechnologyArray(input);
expect(result).toEqual(['WordPress', 'Google Analytics', 'PHP']);
});

it('should return an array for a single technology string', () => {
const input = 'WordPress';
const result = validateTechnologyArray(input);
expect(result).toEqual(['WordPress']);
});

it('should return an empty array for null input', () => {
const result = validateTechnologyArray(null);
expect(result).toEqual([]);
});

it('should return an empty array for undefined input', () => {
const result = validateTechnologyArray(undefined);
expect(result).toEqual([]);
});

it('should return an empty array for an empty string', () => {
const result = validateTechnologyArray('');
expect(result).toEqual([]);
});

it('should return null when the number of technologies exceeds FIRESTORE_IN_LIMIT', () => {
// Create a string with FIRESTORE_IN_LIMIT + 1 technologies
const technologies = Array(FIRESTORE_IN_LIMIT + 1).fill('tech').join(',');
const result = validateTechnologyArray(technologies);
expect(result).toBeNull();
});

it('should return an array when the number of technologies is exactly FIRESTORE_IN_LIMIT', () => {
const technologiesArray = Array(FIRESTORE_IN_LIMIT).fill('tech');
const technologiesString = technologiesArray.join(',');
const result = validateTechnologyArray(technologiesString);
expect(result).toHaveLength(FIRESTORE_IN_LIMIT);
expect(result).toEqual(technologiesArray);
});

it('should handle URL encoded technologies', () => {
const input = 'Google%20Analytics,WordPress';
const result = validateTechnologyArray(input);
expect(result).toEqual(['Google Analytics', 'WordPress']);
});
});