NEAR-DevHub / neardevhub-bos

DevHub Portal Product UI (Hosted BOS) – Includes other instances (e.g. Infrastructure, Events)
https://neardevhub.org
MIT License
24 stars 23 forks source link

Write Tests for the New API #986

Open Tguntenaar opened 1 week ago

Tguntenaar commented 1 week ago

Any changes made to the indexer should come with tests written as soon as #982 merges.

Is your feature request related to a problem? Please describe.

The current codebase lacks comprehensive test coverage, particularly for the new API endpoints and core functionality. While there is a basic test structure in place (as seen in src/tests.rs), it only tests the index route. This makes it difficult to ensure reliability and catch potential regressions when making changes.

Reference:

#[test]
fn test_index() {
    use rocket::local::blocking::Client;

    // Construct a client to use for dispatching requests.
    let client = Client::tracked(super::rocket()).expect("valid `Rocket`");

    // Dispatch a request to 'GET /' and validate the response.
    let response = client.get("/").dispatch();
    assert_eq!(response.into_string().unwrap(), "Welcome from fly.io!!!!!");
}

Describe the solution you'd like

We need to implement a comprehensive test suite that covers:

API Endpoints Testing:

Examples on endpoints we need to test:

Database Operations:

External Service Integration:

Background Services:

The tests should use the existing test infrastructure shown in the CI workflow.

Describe alternatives you've considered

  1. Integration Tests Only: We could focus solely on integration tests that verify the entire system works together, but this would make it harder to isolate and fix issues.
  2. Manual Testing: Continue with manual testing, but this isn't scalable and doesn't provide the confidence needed for continuous deployment.
  3. Property-Based Testing: Implement property-based testing for complex data transformations, though this would require additional setup and complexity.

Additional context

Key files to consider when implementing tests:

ori-near commented 4 days ago

@petersalomonsen @Tguntenaar as discussed on our call, can you please split this task up in the way that makes sense? Thanks.