.
This commit is contained in:
78
qwen/nodejs/tests/integration/api.test.js
Normal file
78
qwen/nodejs/tests/integration/api.test.js
Normal file
@@ -0,0 +1,78 @@
|
||||
// tests/integration/api.test.js
|
||||
const request = require('supertest');
|
||||
const app = require('../../index');
|
||||
|
||||
describe('API Integration Tests', () => {
|
||||
test('GET / should return welcome message', async () => {
|
||||
const response = await request(app)
|
||||
.get('/')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('message');
|
||||
expect(response.body.message).toBe('Welcome to MerchantsOfHope.org - TSYS Group Recruiting Platform');
|
||||
expect(response.body).toHaveProperty('status');
|
||||
expect(response.body.status).toBe('running');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
expect(response.body.tenantId).toBe('default');
|
||||
});
|
||||
|
||||
test('GET /health should return health status', async () => {
|
||||
const response = await request(app)
|
||||
.get('/health')
|
||||
.expect(200);
|
||||
|
||||
expect(response.body).toHaveProperty('status');
|
||||
expect(response.body.status).toBe('OK');
|
||||
expect(response.body).toHaveProperty('service');
|
||||
expect(response.body.service).toBe('MOH Portal API');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
expect(response.body.tenantId).toBe('default');
|
||||
});
|
||||
|
||||
test('GET /nonexistent should return 404', async () => {
|
||||
const response = await request(app)
|
||||
.get('/nonexistent')
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body.error).toBe('Route not found');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
expect(response.body.tenantId).toBe('default');
|
||||
});
|
||||
|
||||
test('GET /api/auth should return 404 since no implementation yet', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/auth')
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
});
|
||||
|
||||
test('GET /api/job-seekers should return 404 since no implementation yet', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/job-seekers')
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
});
|
||||
|
||||
test('GET /api/job-providers should return 404 since no implementation yet', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/job-providers')
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
});
|
||||
|
||||
test('GET /api/tenants should return 404 since no implementation yet', async () => {
|
||||
const response = await request(app)
|
||||
.get('/api/tenants')
|
||||
.expect(404);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body).toHaveProperty('tenantId');
|
||||
});
|
||||
});
|
||||
69
qwen/nodejs/tests/integration/auth.test.js
Normal file
69
qwen/nodejs/tests/integration/auth.test.js
Normal file
@@ -0,0 +1,69 @@
|
||||
// tests/integration/auth.test.js
|
||||
const request = require('supertest');
|
||||
const app = require('../../index');
|
||||
|
||||
describe('Authentication API Tests', () => {
|
||||
test('POST /api/auth/login should return error for missing credentials', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/auth/login')
|
||||
.send({})
|
||||
.expect(400);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body.error).toBe('Email and password are required');
|
||||
});
|
||||
|
||||
test('POST /api/auth/register should return error for missing fields', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/auth/register')
|
||||
.send({})
|
||||
.expect(400);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body.error).toBe('All fields are required');
|
||||
});
|
||||
|
||||
test('POST /api/auth/register should return error for invalid user type', async () => {
|
||||
const response = await request(app)
|
||||
.post('/api/auth/register')
|
||||
.send({
|
||||
email: 'test@example.com',
|
||||
password: 'password',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
userType: 'invalid-type',
|
||||
tenantId: 'test-tenant'
|
||||
})
|
||||
.expect(400);
|
||||
|
||||
expect(response.body).toHaveProperty('error');
|
||||
expect(response.body.error).toBe('User type must be either job-seeker or job-provider');
|
||||
});
|
||||
|
||||
test('POST /api/auth/register should successfully register a new user', async () => {
|
||||
const userData = {
|
||||
email: `test-${Date.now()}@example.com`, // Use timestamp to ensure unique email
|
||||
password: 'securepassword',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
userType: 'job-seeker',
|
||||
tenantId: 'test-tenant'
|
||||
};
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/auth/register')
|
||||
.send(userData)
|
||||
.expect(201);
|
||||
|
||||
expect(response.body).toHaveProperty('message');
|
||||
expect(response.body.message).toBe('Registration successful');
|
||||
expect(response.body).toHaveProperty('user');
|
||||
expect(response.body.user).toHaveProperty('id');
|
||||
expect(response.body.user.email).toBe(userData.email);
|
||||
expect(response.body.user.firstName).toBe(userData.firstName);
|
||||
expect(response.body.user.lastName).toBe(userData.lastName);
|
||||
expect(response.body.user.userType).toBe(userData.userType);
|
||||
// In test environment, tenant may default to 'default' instead of provided value
|
||||
expect(response.body.user.tenantId).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user