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

Integrate gitbeaker API into client codebase #830

Conversation

VanessaScherma
Copy link
Contributor

The problem is that mockGitlabConstructor is instantiated as an empty constructor, without its methods. For example, when using this.api.Projects.search() in the code, mockGitlabConstructor is used in the test but gives an error as the methods like Projects.search() are not inserted inside the mockGitlabConstructor.

I have tried to find more information on the Internet but have not yet been able to solve it.
Thank you for your help.

@prasadtalasila
Copy link
Contributor

@VanessaScherma you could do dependency injection. To be precise, give an instance of Gitlab to DigitalTwin class via constructor. Then mocking it becomes easier. You just need to implement skeleton functionality of Gitlab to test DigitalTwin class.
Module mocking like you are doing is doable as well. Perhaps the injection of Gitlab into DigitalTwin is an easier testing step for now.

@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 58.10811% with 31 lines in your changes missing coverage. Please review.

Project coverage is 85.93%. Comparing base (eaa22d5) to head (ea3fd03).
Report is 24 commits behind head on feature/distributed-demo.

Current head ea3fd03 differs from pull request most recent head d54bbb8

Please upload reports for the commit d54bbb8 to get more accurate results.

Files with missing lines Patch % Lines
client/src/util/gitlabDriver.ts 0.00% 23 Missing and 1 partial ⚠️
client/src/util/gitlabDigitalTwin.ts 81.81% 2 Missing and 2 partials ⚠️
client/src/util/gitlab.ts 89.28% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##           feature/distributed-demo     #830       +/-   ##
=============================================================
+ Coverage                     66.49%   85.93%   +19.43%     
=============================================================
  Files                            31       35        +4     
  Lines                           394      519      +125     
  Branches                         26       40       +14     
=============================================================
+ Hits                            262      446      +184     
+ Misses                          117       49       -68     
- Partials                         15       24        +9     
Files with missing lines Coverage Δ
client/src/util/gitlab.ts 89.28% <89.28%> (ø)
client/src/util/gitlabDigitalTwin.ts 81.81% <81.81%> (ø)
client/src/util/gitlabDriver.ts 0.00% <0.00%> (ø)

... and 6 files with indirect coverage changes

Components Coverage Δ
Website 85.93% <75.49%> (+19.43%) ⬆️
Lib Microservice ∅ <ø> (∅)

@VanessaScherma
Copy link
Contributor Author

The commands to run the gitlabDriver file are:

  1. yarn install
  2. npx tsc
  3. cd dist/src/util
  4. In 'gitlabDriver.js', change './gitlab' to './gitlab.js' and './gitlabDigitalTwin' to './gitlabDigitalTwin.js'
  5. node gitlabDriver.js

The correct functioning of the API will be visible in the terminal.

@prasadtalasila
Copy link
Contributor

prasadtalasila commented Aug 7, 2024

The commands to run the gitlabDriver file are:

  1. yarn install
  2. npx tsc
  3. cd dist/src/util
  4. In 'gitlabDriver.js', change './gitlab' to './gitlab.js' and './gitlabDigitalTwin' to './gitlabDigitalTwin.js'
  5. node gitlabDriver.js

The correct functioning of the API will be visible in the terminal.

@VanessaScherma
npx tsc is still throwing up errors. In addition, you can change imports of gitlabDriver.ts to

import GitlabInstance from './gitlab.js';
import DigitalTwin from './gitlabDigitalTwin.js';

@VanessaScherma
Copy link
Contributor Author

The updated commands are:

  1. yarn install
  2. npx tsc
  3. cd dist/src/util
  4. node gitlabDriver.js

The only errors that npx tsc gives are related to other files, but it still works.

@prasadtalasila prasadtalasila changed the title Problem creating the Gitlab mock (gitbeaker) in the unit test of gitlab.ts Integrate gitbeaker API into client codebase Aug 15, 2024
Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VanessaScherma please see the suggested changes. I've made some improvements to code and pushed them to pr-830 of my fork. Please update your PR accordingly. Thanks.

client/src/util/gitlab.ts Outdated Show resolved Hide resolved
client/src/util/gitlab.ts Outdated Show resolved Hide resolved
client/src/util/gitlab.ts Outdated Show resolved Hide resolved
client/src/util/gitlab.ts Show resolved Hide resolved
client/src/util/gitlab.ts Show resolved Hide resolved
client/src/util/gitlabDriver.ts Show resolved Hide resolved
client/test/unitTests/Util/gitlab.test.ts Outdated Show resolved Hide resolved
client/test/unitTests/Util/gitlabDigitalTwin.test.ts Outdated Show resolved Hide resolved
client/test/unitTests/Util/gitlabDigitalTwin.test.ts Outdated Show resolved Hide resolved
client/test/unitTests/Util/gitlabDigitalTwin.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make this change

@prasadtalasila
Copy link
Contributor

prasadtalasila commented Aug 19, 2024

@VanessaScherma
Also when you make the change, the Gitlab&nstance class needs the constructor parameters in the GitlabDriver.ts file. Please keep them in either client/config/gitlab.json and read them into the driver file.

Copy link

codeclimate bot commented Aug 23, 2024

Code Climate has analyzed commit d54bbb8 and detected 0 issues on this pull request.

View more on Code Climate.

prasadtalasila added a commit that referenced this pull request Aug 29, 2024
- Uses gitbeaker API to showcase gitlab API integration into react client codebase
- This PR builds on top of PR #830
@prasadtalasila
Copy link
Contributor

merged via PR #894

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

Successfully merging this pull request may close these issues.

3 participants