Skip to content

Commit

Permalink
add integration test and remove test for now from actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rauner committed Jan 26, 2024
1 parent 40fc556 commit c993f7e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ jobs:
git push
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod assistant;
use assistant::create_assistant;
use assistant::{assistant_chat_handler, DB};
use axum::{extract::Extension, routing::post, Router};
use dotenv::dotenv;
use sqlx::SqlitePool;
mod assistant;
// Define a function to create the Axum app with the database pool and assistant.
// Define a function to create the Axum app with the database pool and assistant.
async fn app(db_pool: SqlitePool, assistant_id: String) -> Router {
Expand All @@ -21,7 +21,7 @@ async fn main() {
"My Assistant",
"gpt-4",
"Your instructions here",
"context",
"/context",
)
.await
{
Expand Down
17 changes: 0 additions & 17 deletions test/chat_integration.rs

This file was deleted.

34 changes: 34 additions & 0 deletions tests/assistant_integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use reqwest;
use serde_json::json;
const BASE_URL: &str = "http://localhost:3000";
#[tokio::test]
async fn test_chat_endpoint() {
let client = reqwest::Client::new();
let user_id = "test_user"; // Example user ID for testing
// Send a chat message to the chat endpoint
let response = client
.post(format!("{}/chat", BASE_URL))
.json(&json!({
"user_id": user_id,
"message": "Hello, chatbot!"
}))
.send()
.await
.expect("Failed to send request");
// Check that the response status code is OK
assert_eq!(response.status(), reqwest::StatusCode::OK);
// Parse the response body as JSON
let response_json: serde_json::Value = response.json().await.expect("Failed to parse response as JSON");
// Perform additional checks on the response JSON
// For example, check that the response contains the expected message structure
if let Some(messages) = response_json.get("messages") {
assert!(messages.is_array(), "Expected 'messages' to be an array");
// Check that the array contains at least one message
assert!(!messages.as_array().unwrap().is_empty(), "Expected at least one message in the response");
// Check that the message content matches what was sent
assert_eq!(messages[0].get("text").unwrap(), "Hello, chatbot!");
} else {
panic!("Response JSON does not contain 'messages' key");
}
}

0 comments on commit c993f7e

Please sign in to comment.