Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1d6dc2d
feat: add model imports and error handling structure to paid labor co…
Aditya-gam Nov 22, 2025
48a89e9
feat: add parameter extraction and validation for paid labor cost con…
Aditya-gam Nov 22, 2025
c7b0b41
feat: build MongoDB query filters for paid labor cost controller
Aditya-gam Nov 22, 2025
fd2c421
feat: query database and retrieve labor cost records
Aditya-gam Nov 22, 2025
0452920
feat: format response data for paid labor cost controller
Aditya-gam Nov 22, 2025
1a4a112
feat: construct final response object for paid labor cost controller
Aditya-gam Nov 22, 2025
120acb8
feat: enhance error handling for paid labor cost controller
Aditya-gam Nov 22, 2025
5403332
feat: enhance edge case handling for paid labor cost controller
Aditya-gam Nov 22, 2025
0d6aed8
fix: change route method from POST to GET for paid labor cost endpoint
Aditya-gam Nov 22, 2025
fad11a2
fix: improve date validation and parameter parsing for paid labor cos…
Aditya-gam Nov 22, 2025
f8fd516
feat: enhance array parameter validation for paid labor cost controller
Aditya-gam Nov 23, 2025
268c291
fix: use UTC methods for date boundary setting in paid labor cost con…
Aditya-gam Nov 23, 2025
93fa479
test: add unit tests for paid labor cost controller helper functions
Aditya-gam Nov 29, 2025
91494cc
test: add unit tests for paid labor cost controller logic
Aditya-gam Nov 29, 2025
5c7c9ba
test: add integration tests for paid labor cost routes
Aditya-gam Nov 29, 2025
447828c
test: add edge case tests for paid labor cost controller
Aditya-gam Nov 29, 2025
9e2ec84
test: add documentation and optimize paid labor cost tests
Aditya-gam Nov 29, 2025
dc5ec23
refactor: extract validation and parsing logic into helper functions …
Aditya-gam Nov 30, 2025
acf7794
fix: Move @aws-sdk/client-s3 from devDependencies to dependencies
Aditya-gam Dec 5, 2025
0b3bce4
Merge branch 'development' into Aditya-fix/implement-paid-labor-cost-…
Aditya-gam Feb 17, 2026
32d42a2
Merge branch 'development' into Aditya-fix/implement-paid-labor-cost-…
Aditya-gam Feb 28, 2026
db8c003
chore: align package-lock.json with development
Aditya-gam Feb 28, 2026
57945b9
fix(security): build labor-cost query from validated params only
Aditya-gam Feb 28, 2026
d58a64d
test: reduce duplication in paid labor cost controller tests
Aditya-gam Feb 28, 2026
c6a79ca
fix(security): sanitize project/task arrays to prevent NoSQL injection
Aditya-gam Feb 28, 2026
71683e1
test: add sanitizeStringArrayForQuery tests and reduce helper duplica…
Aditya-gam Feb 28, 2026
57c85e1
fix: resolve merge conflicts with development branch
rithika-paii May 2, 2026
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
113 changes: 113 additions & 0 deletions src/__tests__/integration/bmPaidLaborCostRoutes.integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Integration Tests for Paid Labor Cost Routes
*
* This test suite covers:
* 1. Authorization tests (401 responses without auth token)
* 2. Route functionality tests (method validation, route existence)
*
* Note: These tests require the full app to be loaded, which may require
* additional dependencies (e.g., @aws-sdk/client-s3) to be installed.
*/

const request = require('supertest');
const { app } = require('../../app');

const agent = request.agent(app);

describe('bmPaidLaborCostRoutes tests', () => {
// Global timeout for the entire test suite
jest.setTimeout(60000); // 1 minute

beforeAll(async () => {
console.log('=== Starting Paid Labor Cost Integration Test Setup ===');
console.log('✓ Test setup completed');
console.log('=== Paid Labor Cost Integration Test Setup Complete ===');
}, 60000); // 1 minute timeout for beforeAll

/**
* Authorization Tests
* Verifies that routes require authentication (return 401 without auth header)
*/
describe('Authorization Tests', () => {
it('should return 401 if authorization header is not present for GET /api/labor-cost', async () => {
console.log('Testing 401 unauthorized access for GET /api/labor-cost...');

try {
await agent.get('/api/labor-cost').expect(401);
console.log('✓ GET /api/labor-cost 401 test passed');
} catch (error) {
console.error('❌ GET /api/labor-cost 401 test failed:', error.message);
throw error;
}
}, 30000);

it('should return 401 if authorization header is not present for GET with query params', async () => {
console.log('Testing 401 unauthorized access for GET /api/labor-cost with query params...');

try {
await agent.get('/api/labor-cost?projects=["A"]').expect(401);
console.log('✓ GET /api/labor-cost with query params 401 test passed');
} catch (error) {
console.error('❌ GET /api/labor-cost with query params 401 test failed:', error.message);
throw error;
}
}, 30000);
});

/**
* Route Functionality Tests
* Verifies route configuration and method handling
* Note: Full functionality tests require database connection.
* If database is not available, these become smoke tests.
*/
describe('Route Functionality Tests', () => {
it('should return 404 or method not allowed for POST method', async () => {
console.log('Testing POST method (should not be allowed)...');

try {
const response = await agent.post('/api/labor-cost').send({});
// POST should return 404 (route doesn't exist), 405 (method not allowed), or 401 (auth required)
const { status } = response;
expect([404, 405, 401]).toContain(status);
console.log(`✓ POST /api/labor-cost returned ${status} as expected`);
} catch (error) {
// If it throws, check the status code
const status = error.status || error.response?.status;
if ([404, 405, 401].includes(status)) {
console.log(`✓ POST /api/labor-cost returned ${status} as expected`);
} else {
console.error(
`❌ POST /api/labor-cost test failed with status ${status}:`,
error.message,
);
throw error;
}
}
}, 30000);

// Note: The following test requires authentication token
// It will fail with 401 if no token is provided, which is expected
// To fully test route existence, a valid token would be needed
it('should have route configured (returns 401 without auth, not 404)', async () => {
console.log('Testing route existence...');

try {
const response = await agent.get('/api/labor-cost');
// Route exists if we get 401 (unauthorized) rather than 404 (not found)
expect(response.status).toBe(401);
console.log('✓ Route exists (returned 401, not 404)');
} catch (error) {
// If error status is 401, that's good - route exists
if (error.status === 401 || error.response?.status === 401) {
console.log('✓ Route exists (returned 401, not 404)');
} else if (error.status === 404 || error.response?.status === 404) {
console.error('❌ Route does not exist (returned 404)');
throw new Error('Route /api/labor-cost not found');
} else {
console.error('❌ Route test failed:', error.message);
throw error;
}
}
}, 30000);
});
});
Loading
Loading