Skip to content

Adding Unit test cases for wrappedNodeFetch and adding github actions - #59

Open
Hermione2408 wants to merge 10 commits into
keploy:mainfrom
Hermione2408:test#354
Open

Adding Unit test cases for wrappedNodeFetch and adding github actions #59
Hermione2408 wants to merge 10 commits into
keploy:mainfrom
Hermione2408:test#354

Conversation

@Hermione2408

@Hermione2408Hermione2408 commented Mar 8, 2023

Copy link
Copy Markdown

For code coverage added unit test for wrappedNodeFetch function and integrated git hub actions.

test #354
Closes: keploy/keploy#354

@developer-diganta

Copy link
Copy Markdown

Hi @re-Tick! Can you please review the PR?

@re-Tick

Copy link
Copy Markdown
Contributor

@Hermione2408 please resolve DCO and commitzen

@Hermione2408
Hermione2408force-pushed the test#354 branch 3 times, most recently from 5cebecf to 7270469CompareMarch 8, 2023 20:16
@Hermione2408

Copy link
Copy Markdown
Author

Can you have a look now @re-Tick

Comment threadtest/wrappedNodeFetch.test.ts
@re-Tickre-Tick added Don't Merge Not to be merged until gsoc results Accepted PR is reviewed and Accepted and removed Accepted PR is reviewed and Accepted labels Mar 9, 2023
Comment threadtest/wrappedNodeFetch.test.ts Outdated
@Hermione2408

Copy link
Copy Markdown
Author

Hey @re-Tick , Can you please review the changes now

@re-Tick

Copy link
Copy Markdown
Contributor

a test is failing. I will try these changes locally and request changes if any.

@Hermione2408

Copy link
Copy Markdown
Author

Sure I'll try to resolve too where they are failing

Comment threadtest/wrappedNodeFetch.test.ts Outdated

describe('wrappedNodeFetch', () => {
it('should call fetch function with correct arguments in record mode', async () => {
const mockFetch = jest.fn().mockResolvedValueOnce(new Response());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since, outputs are recorded when end event is triggered for response of fetch. We dont need to mock fetch here. We can use the actual fetch of node-fetch

Comment threadtest/wrappedNodeFetch.test.ts Outdated
deps: [],
};
createExecutionContext(ctx)
const wrappedFetch = (wrappedNodeFetch(mockFetch) as any).bind({ fetch: mockFetch });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And pass actual fetch here. To capture the outputs.

Comment threadtest/wrappedNodeFetch.test.ts Outdated
};
createExecutionContext(ctx)
const wrappedFetch = (wrappedNodeFetch(mockFetch) as any).bind({ fetch: mockFetch });
const url = 'http://example.com';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can use keploy's health API "https://api.keploy.io/healthz" here as url

Comment threadtest/wrappedNodeFetch.test.ts Outdated
const deps=updatedctx.deps.length;
const responseBody = await response.text();
const recordedOutput = updatedctx.mocks[0].Spec.Res.Body;
expect(mockFetch).toHaveBeenCalledWith(url, options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We also dont need to do this since we use actual fetch of node-fetch

@Hermione2408

Copy link
Copy Markdown
Author

@re-Tick I have made the changes and it is passing all the test cases now.

Hermione2408and others added 8 commits March 14, 2023 17:30
…b action and wrote unit test
For code coverage added unit test for wrappedNodeFetch function and integrated git hub actions.
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
Revert version and removing console from unit test file
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
Added expect test for mocks and deps after fetching in record and test mode
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
… output with response
Added a check to compare the recorded output with response to ensure wrappedNodeFetch functionality
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
importing HTTP from src/keploy.ts
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
…reateExecutionContext
Resolving the failed test cases by using fetch from node-fetch and createExecutionContext
test#354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
updating test cases
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
Hermione2408and others added 2 commits March 14, 2023 17:51
removing createExecutionContext from octokit
test #354
Signed-off-by: Hermione Dadheech <hermionedadheech@gmail.com>
@re-Tick

Copy link
Copy Markdown
Contributor

LGTM. Please add this PR link in GSOC task list.

@developer-digantadeveloper-diganta added the Accepted PR is reviewed and Accepted label Mar 15, 2023
@keploy

keployBot commented Apr 15, 2025

Copy link
Copy Markdown

Nice Pr 😄. We currently support Unit Test Generation only for Go projects.
Stay tuned – support for more languages is coming soon! 🚀

1 similar comment
@keploy-staging

Copy link
Copy Markdown

Nice Pr 😄. We currently support Unit Test Generation only for Go projects.
Stay tuned – support for more languages is coming soon! 🚀

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AcceptedPR is reviewed and AcceptedDon't MergeNot to be merged until gsoc results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test]: add unit tests for octokit module

3 participants

@Hermione2408@developer-diganta@re-Tick