-
Notifications
You must be signed in to change notification settings - Fork 27
added unittest for octokit module #64
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9525d86
added unitest1.ts
Sekhar-Kumar-Dash 7c3b2fe
updated package.json
Sekhar-Kumar-Dash 16a4c94
updated ci.yml
Sekhar-Kumar-Dash feb0011
modified package.json
Sekhar-Kumar-Dash b436325
updated ci.yml
Sekhar-Kumar-Dash 55cf7e6
updated unittest.ts
Sekhar-Kumar-Dash 406332c
updated package.json
Sekhar-Kumar-Dash da0666c
modified yarn.lock
Sekhar-Kumar-Dash f448362
added package-lock.json
Sekhar-Kumar-Dash e07f898
added package-lock.json
Sekhar-Kumar-Dash ccf27fd
added package.json
Sekhar-Kumar-Dash 3cdda69
modified yarn.lock
Sekhar-Kumar-Dash d8f329a
modified unittest1.ts
Sekhar-Kumar-Dash 9033bca
Update yarn.lock
Sekhar-Kumar-Dash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import fetchMock, { MockResponse } from "fetch-mock"; | ||
|
Sekhar-Kumar-Dash marked this conversation as resolved.
Outdated
|
||
| import { wrappedNodeFetch } from "../integrations/octokit/require"; | ||
| import { Response } from 'node-fetch'; | ||
| import { createExecutionContext, getExecutionContext} from '../src/context'; | ||
| import { HTTP } from '../src/keploy'; | ||
|
|
||
| describe("wrappedNodeFetch", () => { | ||
| afterEach(() => { | ||
| fetchMock.restore(); | ||
| }); | ||
|
|
||
| it("should make a network request in record mode", async () => { | ||
| const ctx = { | ||
| mode: "record", | ||
| testId: "test-id", | ||
| mocks: [], | ||
| deps: [], | ||
| }; | ||
| const url = "https://api.github.com/repos/octocat/hello-world/issues/123"; | ||
| const options: RequestInit = { | ||
| method: "GET", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Authorization: "token secret123", | ||
| }, | ||
| }; | ||
| const fetchSpy = jest.spyOn(fetchMock, "default").mockReturnValue( | ||
| Promise.resolve({ | ||
| status: 200, | ||
| body: "Hello world!", | ||
| headers: { | ||
| "Content-Type": "text/plain", | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| const wrappedFetch = wrappedNodeFetch(fetchMock.default); | ||
|
|
||
| await wrappedFetch.call({ fetch: fetchMock.default }, url, options); | ||
|
|
||
| expect(fetchSpy).toHaveBeenCalledWith(url, { | ||
| method: options.method, | ||
| headers: options.headers, | ||
| }); | ||
|
|
||
| expect(ctx.mocks).toHaveLength(1); | ||
|
|
||
| const httpMock = ctx.mocks[0] as HTTP; | ||
| expect(httpMock.Kind).toEqual("HTTP"); | ||
| expect(httpMock.Spec.Metadata.name).toEqual("node-fetch"); | ||
| expect(httpMock.Spec.Metadata.url).toEqual(url); | ||
| expect(httpMock.Spec.Metadata.type).toEqual("HTTP_CLIENT"); | ||
| expect(httpMock.Spec.Metadata.options).toEqual(options); | ||
|
|
||
| expect(httpMock.Spec.Req.Method).toEqual(options.method); | ||
| expect(httpMock.Spec.Req.URL).toEqual(url); | ||
| expect(httpMock.Spec.Req.Header).toEqual({ | ||
| "Content-Type": "application/json", | ||
| Authorization: "token secret123", | ||
| }); | ||
| expect(httpMock.Spec.Req.Body).toBeUndefined(); | ||
|
|
||
| expect(httpMock.Spec.Res.StatusCode).toEqual(200); | ||
| expect(httpMock.Spec.Res.Header).toEqual({ | ||
| "Content-Type": "text/plain", | ||
| }); | ||
| expect(httpMock.Spec.Res.Body).toEqual("Hello world!"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.