Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor salesforce adaptor to use client Instead of state.connection #687

Open
mtuchi opened this issue Jul 22, 2024 · 1 comment
Open

Comments

@mtuchi
Copy link
Collaborator

mtuchi commented Jul 22, 2024

Description:

Currently, our Salesforce adapter uses state.connection to establish the session and removes state.connection at the end of execution. To improve the structure and maintainability of the code, we want to refactor the adaptor to use a client setup similar to what we have done with our Hive and GoogleSheets adaptor. This involves the following changes:

  1. Remove state.connection.
  2. Introduce a client or session variable (e.g., let client = null; or let session = null;).
  3. Set up the client using a new function createConnection().
  4. Destroy the client using a new function removeConnection().

Tasks:

  1. Remove state.connection:

    • Identify all instances where state.connection is used.
    • Refactor the code to remove state.connection.
  2. Introduce client variable:

    • Define a new client or session variable (e.g., let client = null;).
  3. Update createConnection() function:

    • Implement a function createConnection() that initializes the client.
    • Ensure the function handles all necessary configurations and authentication.
  4. Create removeConnection() function:

    • Implement a function removeConnection() that properly closes and cleans up the client session.
    • Ensure the function handles any necessary cleanup and error handling.
  5. Refactor code to use client:

    • Update all relevant parts of the adapter to use the new client variable.
    • Replace instances of state.connection with the appropriate client methods and properties.
  6. Testing:

    • Thoroughly test the refactored adaptor to ensure it functions correctly.
    • Ensure all existing functionality is preserved and no regressions are introduced.

References:

  • Example from PostgreSQL adapter:
    let client = null;
    
    function createConnection() {
      // Setup client
    }
    
    function removeConnection() {
      // Destroy client
    }

Related Issues/PRs:

@mtuchi mtuchi mentioned this issue Jul 22, 2024
3 tasks
@josephjclark
Copy link
Collaborator

The unit tests currently rely on state.connection to provide a mock connection handler.

What you'll need to do is provide something like a setMockClient(client) private function in the adaptor. A bit like how we handle mock connections in common http.

Then the tests will call setMockClient each time and provide mock implementations to satisfy the tests

This is sort of what I want to do in the mockable tests epic, but I agree that we need to fix salesforce before we pick that epic up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants