Skip to content

Commit 4f39a1a

Browse files
All test cases pass
1 parent da246d0 commit 4f39a1a

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

__mocks__/node-fetch.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
async function fetch(handle, transport) {
2+
if (
3+
transport.method === "GET" &&
4+
handle === `https://api.github.com/users/iKnowJavaScript/repos`
5+
) {
6+
return Promise.resolve([
7+
{ name: "Ball-Bouncing-and-Collision" },
8+
{ name: "css-grid" },
9+
{ name: "CSS-Grid-Calculator" },
10+
{ name: "CSS-Grid-Phone" },
11+
{ name: "css-protips" },
12+
{ name: "Databaseless-API" },
13+
{ name: "front-end-interview-handbook" },
14+
{ name: "git-blog-demo" },
15+
{ name: "html5games1" },
16+
{ name: "Introductory-Website" },
17+
{ name: "Javascript-30" },
18+
{ name: "jsninja2" },
19+
{ name: "learn-git" }
20+
]);
21+
}else if (
22+
transport.method === "GET" &&
23+
handle === `https://api.github.com/users/rasaki/repos`
24+
) {
25+
return Promise.resolve([]);
26+
}
27+
}
28+
29+
module.exports = fetch;

operations/git_api/getRepo.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
const fetch = require("node-fetch")
2-
//Takes a username as an argument and makes a call to GitHub API
3-
//and returns all the repositoriesowned by the user as an array.
42

5-
async function showGitHubRepos(handle) {
3+
function showGitHubRepos(handle) {
64
const url = `https://api.github.com/users/${handle}/repos`;
7-
const response = await fetch(url);
8-
const repos = await response.json();
5+
return fetch(url, { method: "GET" }).then(response =>
6+
response.map(elem => elem.name)
7+
);
98

10-
return repos.map(repo => repo.name);
119
}
12-
showGitHubRepos("whiteh").then(data => console.log(data));
10+
//showGitHubRepos("whiteh").then(data => console.log(data));
1311

1412
const myrepo = [
1513
"Ball-Bouncing-and-Collision",

operations/git_api/getRepo.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
1+
const showGitHubRepos = require("./getRepo");
32

43
describe("Mock testing getRepo implementation", () => {
54
it("Make sure fetchRepo function is called", async () => {
@@ -12,4 +11,4 @@ describe("Mock testing getRepo implementation", () => {
1211

1312
expect(repos).toEqual([]);
1413
});
15-
});
14+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy