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 external to use interfaces #371

Open
2 tasks
ekefan opened this issue Feb 27, 2025 · 0 comments
Open
2 tasks

Refactor external to use interfaces #371

ekefan opened this issue Feb 27, 2025 · 0 comments
Assignees

Comments

@ekefan
Copy link
Contributor

ekefan commented Feb 27, 2025

Description

The external package contains logic for sending requests to external services needed by hng_boilerplate. Currently, it has no factory for setting up the logic properly, there is no interface binding all external services hence mocking is difficult. And this package has no unit tests.

Acceptance Criteria

  • Ensure all services dependent on external package and its logic retain their logic and functionality
  • Expose the external package as an interface for communicating with any external package
  • Update Mocks for the external package
  • Include unit tests with good coverage for the package
  • NightOwlDev will be handling all of these

Requirements

  • N/A

Purpose

  • To improve code modularity, testability, and adherence to the dependency inversion principle

Changes to be made:

The current external folder looks like this:

└── external/
    ├── external_models/
    │   └── ipstack.go
    ├── mocks/
    │   ├── ipstack_mocks/
    │   │   └── resolve_ip.go
    │   └── send_invites/
    │       └── send_invites.go
    ├── request/
    │   └── request.go
    ├── thirdparty/ipstack/
    │   ├── base.go
    │   └── resolve_ip.go
    └── send.go

I will be updating it to this:

└── external/
    ├── ipstack/
    │   ├── ipstack_test.go
    │   ├── ipstack.go
    │   └── model.go
    ├── mocks
    ├── request/
    │   ├── request_test.go
    │   └── request.go
    ├── external_test.go
    ├── external.go
    └── interface.go
  • interface.go defines the required interface for external service interactions.

  • external.go provides a generic function for sending external requests.

  • request/request.go serves as a configurable external request handler using the factory pattern with options.

  • mocks/ contains generated mocks to inject the external package when testing services that depend on it.

  • ipstack/ contains implementation details for the IpStack API.

  • *_test.go files contain unit test for functions.

  • Update external to use interface Refactor the external package to use an interface #376

  • Properly initialize external.ExternalRequest using factory method in every package using it

Expected Outcome

  • Ability to choose which external service to communicate with at setup
  • Every service dependent on external works as it should
  • No failing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants