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
5 changes: 5 additions & 0 deletions GPTutor-Backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.chatgpt;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;

@SpringBootTest
@TestPropertySource(locations = "classpath:application-test.properties")
class ChatGptApplicationTests {

@Test
void contextLoads() {
// Test that Spring context loads successfully
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.chatgpt.controllers;

import com.chatgpt.services.MessageService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(MessageController.class)
class MessageControllerTest {

@Autowired
private MockMvc mockMvc;

@MockBean
private MessageService messageService;

@Autowired
private ObjectMapper objectMapper;

@Test
void shouldReturnOkWhenGetModels() throws Exception {
mockMvc.perform(get("/models"))
.andExpect(status().isOk());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.chatgpt.services;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@SpringBootTest
@TestPropertySource(locations = "classpath:application-test.properties")
class ApiKeysServiceTest {

@InjectMocks
private ApiKeysService apiKeysService;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
void shouldInitializeService() {
assertNotNull(apiKeysService);
}
}
13 changes: 13 additions & 0 deletions GPTutor-Backend/src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Test configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop

# Disable specific features for testing
api.keys=test-key-1,test-key-2
secret.key=test-secret-key12
spring.flyway.enabled=false

# Logging level for tests
logging.level.com.chatgpt=DEBUG
3 changes: 3 additions & 0 deletions GPTutor-Frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"cross-env": "^7.0.3",
"eslint": "^8.48.0",
"jest": "^27.5.1",
"@testing-library/react": "^13.4.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^14.4.3",
"prettier": "^2.8.7",
"react-hot-loader": "^4.13.0",
"react-scripts": "^5.0.1",
Expand Down
22 changes: 22 additions & 0 deletions GPTutor-Frontend/src/components/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

// Simple component test example
const TestComponent: React.FC = () => {
return <div data-testid="test-component">GPTutor Test</div>;
};

describe('Component Tests', () => {
test('renders test component', () => {
render(<TestComponent />);
const element = screen.getByTestId('test-component');
expect(element).toBeInTheDocument();
expect(element).toHaveTextContent('GPTutor Test');
});

test('component snapshot', () => {
const { container } = render(<TestComponent />);
expect(container.firstChild).toMatchSnapshot();
});
});
5 changes: 5 additions & 0 deletions GPTutor-Frontend/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
9 changes: 9 additions & 0 deletions GPTutor-Models/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool:pytest]
testpaths = tests
python_files = test_*.py
python_functions = test_*
python_classes = Test*
addopts = -v --tb=short
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
integration: marks tests as integration tests
4 changes: 3 additions & 1 deletion GPTutor-Models/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ langchain-community==0.2.7
gigachat==0.1.31
faiss-cpu==1.8.0.post1
langchainhub==0.1.20
langgraph==0.1.8
langgraph==0.1.8
pytest==7.4.3
pytest-flask==1.3.0
1 change: 1 addition & 0 deletions GPTutor-Models/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tests package initialization
36 changes: 36 additions & 0 deletions GPTutor-Models/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from app import app


@pytest.fixture
def client():
"""Create a test client for the Flask application."""
app.config['TESTING'] = True
with app.test_client() as client:
yield client


def test_llm_get_endpoint(client):
"""Test the GET /llm endpoint."""
response = client.get('/llm')
assert response.status_code == 200
assert response.json == []


def test_llm_post_endpoint(client):
"""Test the POST /llm endpoint."""
response = client.post('/llm')
assert response.status_code == 200


def test_image_endpoint_missing_data(client):
"""Test the POST /image endpoint with missing data."""
response = client.post('/image', json={})
# Should return error due to missing required fields
assert response.status_code in [400, 500]


def test_app_initialization():
"""Test that the Flask app initializes correctly."""
assert app is not None
assert app.config.get('TESTING') is not None
17 changes: 17 additions & 0 deletions GPTutor-Rag/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
collectCoverageFrom: [
'**/*.ts',
'!**/*.d.ts',
'!**/node_modules/**',
'!**/tests/**',
'!jest.config.js'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
moduleNameMapping: {
'^@/(.*)$': '<rootDir>/$1'
}
};
12 changes: 10 additions & 2 deletions GPTutor-Rag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"main": "index.js",
"scripts": {
"start": "ts-node index.ts",
"web_scrapping": "ts-node web_scrapping.ts"
"web_scrapping": "ts-node web_scrapping.ts",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"author": "",
"license": "ISC",
Expand All @@ -30,6 +33,11 @@
"zod": "3.23.8"
},
"devDependencies": {
"@types/express": "^4.17.21"
"@types/express": "^4.17.21",
"@types/jest": "^29.5.5",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"@types/supertest": "^2.0.13",
"supertest": "^6.3.3"
}
}
61 changes: 61 additions & 0 deletions GPTutor-Rag/tests/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import request from 'supertest';
import express from 'express';
import * as bodyParser from 'body-parser';

// Mock the complex dependencies
jest.mock('../GigaChatSupport/GigaChatEmbeddings');
jest.mock('@langchain/community/vectorstores/faiss');
jest.mock('../graph/buildWorkflow');

describe('RAG Application Tests', () => {
let app: express.Application;

beforeAll(() => {
// Create a simple test app without complex dependencies
app = express();
app.use(bodyParser.json());

// Simple test route
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
});

test('should respond to health check', async () => {
const response = await request(app)
.get('/health')
.expect(200);

expect(response.body).toEqual({ status: 'ok' });
});

test('should handle JSON body parsing', async () => {
app.post('/test-json', (req, res) => {
res.json(req.body);
});

const testData = { message: 'test' };
const response = await request(app)
.post('/test-json')
.send(testData)
.expect(200);

expect(response.body).toEqual(testData);
});
});

describe('Environment Configuration', () => {
test('should handle environment variables', () => {
const originalEnv = process.env.CLIENT_SECRET_KEY;
process.env.CLIENT_SECRET_KEY = 'test-key';

expect(process.env.CLIENT_SECRET_KEY).toBe('test-key');

// Restore original value
if (originalEnv) {
process.env.CLIENT_SECRET_KEY = originalEnv;
} else {
delete process.env.CLIENT_SECRET_KEY;
}
});
});
Loading