Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

chore(test): add tests for stepsService & Kaoto UI API #1635

Merged
merged 3 commits into from
Apr 11, 2023

Conversation

kahboom
Copy link
Collaborator

@kahboom kahboom commented Apr 6, 2023

This PR adds unit tests for all the remaining methods in stepsService, with some caveats.

Changes

  • Adds unit tests for the following:
    • deleteBranch
    • deleteStep
    • getStepNested
    • handleAppendStep
    • handleDropOnExistingStep
    • handleInsertStep
    • handlePrependStep
    • replacePlaceholderStep
    • updateStepParameters
    • updateViews
  • Adds test suite for createKaotoApi and tests for its methods:
    • deleteStep
    • getDeployment
    • getIntegrationSource
    • notifyKaoto
    • startDeployment
    • step
    • stepParams
    • stopDeployment
    • updateStep
    • updateStepParams
  • Updates the findStepIdxWithUUID test to cover cases where we don't pass an array of steps
  • Updates descriptions of tests and alphabetizes a few of the tests 🤪
  • Updates a few function params to be clearer what it's asking for (e.g. handleDropOnExistingStep)
  • Clears the integrationJson store before each test as a workaround to an issue with mocking Zundo (see below)

Caveat

Execution paths for nested steps are still not covered as there were some issues with nested calls to other Zustand stores, seemingly related to Zundo--paths that call nestedStepsStore from a secondary function were very difficult to mock. I'll update these once we get a workaround. cc @lordrip

Test Coverage

Current coverage of services and stepsService:

Screen Shot 2023-04-06 at 6 39 35 pm

 services                        |   57.55 |    63.61 |   60.86 |   57.85 |
  index.ts                       |     100 |      100 |     100 |     100 |
  stepsService.ts                |   30.97 |    35.77 |   40.62 |   31.07 | ...8,91-186,244-246,290-412,486-506,534-562,571
  validationService.ts           |   78.18 |    94.73 |   58.33 |   82.69 | 129-149
  visualizationService.ts        |   82.73 |    71.48 |   94.44 |    83.2 | 120-187,328,516

Expected coverage of services and stepsService:

 services                        |   77.34 |    72.89 |   88.23 |   78.23 |
  index.ts                       |     100 |      100 |     100 |     100 |
  stepsService.ts                |   72.28 |    68.22 |    89.7 |   72.88 | ...189,307-312,339-341,363-376,400-410,498-505,551-555,567
  validationService.ts           |   78.18 |    94.73 |   58.33 |   82.69 | 129-149
  visualizationService.ts        |   82.73 |    71.48 |   94.44 |    83.2 | 120-187,328,522

Coverage is not 100% due to the issue with nestedStepsStore and Zundo, described above.

kahboom and others added 2 commits April 6, 2023 18:18
chore(test): add test for deleteBranch

chore(test): add test for deleteStep

chore(test): add test for getStepNested

chore(test): add test for handleAppendStep

chore(test): add test for handleDropOnExistingStep, update params

chore(test): add test for handleInsertStep

chore(test): add test for handlePrependStep

chore(test): add test for replacePlaceholderStep

chore(test): add test for updateStepParameters

chore(test): add test for updateViews

chore(test): update test for findStepIdxWithUUID to consider no steps array

chore(test): add test suite for createKaotoApi

chore(test): add test for startDeployment

chore(test): add test for stopDeployment

chore(test): add test for updateStepParams

chore(test): add test for updateStep

chore: fix formatting

chore(test): fix test for deleteStep, rename tests

chore(test): update descriptions of tests
If createState is empty, store won't have a getState function
and it will be the real createImpl function.

In this situation, we need to make sure to return the function
itself to be able to intercept the original createState function
and be able to reset the store after each test.
@kahboom kahboom requested a review from a team April 6, 2023 18:09
@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #1635 (34f5e72) into main (602f943) will increase coverage by 4.67%.
The diff coverage is 91.42%.

@@            Coverage Diff             @@
##             main    #1635      +/-   ##
==========================================
+ Coverage   61.05%   65.72%   +4.67%     
==========================================
  Files          70       71       +1     
  Lines        2054     2048       -6     
  Branches      470      467       -3     
==========================================
+ Hits         1254     1346      +92     
+ Misses        756      660      -96     
+ Partials       44       42       -2     
Impacted Files Coverage Δ
src/types/index.ts 100.00% <ø> (ø)
src/services/stepsService.ts 76.25% <89.65%> (+42.77%) ⬆️
src/api/apiService.ts 29.54% <100.00%> (ø)
src/services/visualizationService.ts 82.63% <100.00%> (-0.19%) ⬇️
src/store/data/deployment.ts 100.00% <100.00%> (ø)
src/store/nestedStepsStore.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@sonarcloud
Copy link

sonarcloud bot commented Apr 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
6.3% 6.3% Duplication

@kahboom kahboom merged commit 6ead4c1 into KaotoIO:main Apr 11, 2023
@kahboom kahboom deleted the service-tests branch April 11, 2023 11:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants