Skip to content
Open
Show file tree
Hide file tree
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
47 changes: 47 additions & 0 deletions __tests__/routes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const request = require('supertest');
const app = require('../app');

describe('Basic API Routes', () => {
describe('GET /test', () => {
it('should return 200 and a welcome message', async () => {
const response = await request(app)
.get('/test')
.expect(200);

expect(response.body).toHaveProperty('message');
expect(response.body.message).toContain('Hello there');
});
});

describe('GET /logout', () => {
it('should return 200', async () => {
await request(app)
.get('/logout')
.expect(200);
});
});

describe('POST /login', () => {
it('should return 401 when no credentials provided', async () => {
const response = await request(app)
.post('/login')
.send({})
.expect(401);

expect(response.body).toHaveProperty('message');
expect(response.body.message).toBe('Bad credentials');
});

it('should return 401 when invalid credentials provided', async () => {
const response = await request(app)
.post('/login')
.send({
username: 'invalid',
password: 'invalid'
})
.expect(401);

expect(response.body).toHaveProperty('message');
});
});
});
33 changes: 33 additions & 0 deletions __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const toSafeName = require('../lib/utils/toSafeName');

describe('Utility Functions', () => {
describe('toSafeName', () => {
it('should convert string to lowercase', () => {
expect(toSafeName('UPPERCASE')).toBe('uppercase');
});

it('should replace ampersands with "and"', () => {
expect(toSafeName('Tom & Jerry')).toBe('tom_and_jerry');
});

it('should replace special characters with underscores', () => {
expect(toSafeName('hello@world!')).toBe('hello_world_');
});

it('should replace spaces with underscores', () => {
expect(toSafeName('hello world')).toBe('hello_world');
});

it('should handle mixed cases correctly', () => {
expect(toSafeName('Project-Name & Test 123!')).toBe('project_name_and_test_123_');
});

it('should keep alphanumeric characters', () => {
expect(toSafeName('abc123')).toBe('abc123');
});

it('should handle empty string', () => {
expect(toSafeName('')).toBe('');
});
});
});
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.test.js', '**/*.spec.js'],
testPathIgnorePatterns: ['/node_modules/', '/datastore/', '/files/', '/docs/'],
collectCoverageFrom: [
'**/*.js',
'!**/node_modules/**',
'!**/coverage/**',
'!**/datastore/**',
'!**/files/**',
'!**/docs/**',
'!**/__tests__/**',
'!jest.config.js',
],
coverageDirectory: 'coverage',
testTimeout: 10000,
// Don't transform files - use native Node.js CommonJS support
transform: {},
};
Loading