-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 - Initial test added for GetStatsService
- Loading branch information
1 parent
a3d4e52
commit ff60892
Showing
2 changed files
with
56 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,92 +1,33 @@ | ||
import {query} from "../GetStatsService"; | ||
const API_KEY = 'validKey'; | ||
const variables = { | ||
"username": "jangerhard", | ||
"numRepositories": 1, | ||
"numCommits": 1 | ||
}; | ||
const fakeData = { | ||
"avatarUrl": "testUrl.com", | ||
"name": "Test Testington", | ||
"repositories": {} | ||
}; | ||
|
||
const apiKeyError = 'Invalid API-Key'; | ||
const variablesError = 'Invalid variables'; | ||
|
||
const API = 'https://api.github.com/graphql'; | ||
export const getStatsFor = (apiKey, variables, callback) => { | ||
return new Promise((resolve, reject) => { | ||
|
||
const fakeData = [ | ||
{ | ||
"avatarUrl": "https://avatars2.githubusercontent.com/u/6482205?v=4", | ||
"name": "Jan Gerhard Schoepp", | ||
"repositories": { | ||
"edges": [ | ||
{ | ||
"node": { | ||
"name": "react-github-showcase", | ||
"url": "https://github.com/jangerhard/react-github-showcase", | ||
"ref": { | ||
"target": { | ||
"history": { | ||
"nodes": [ | ||
{ | ||
"message": "Update README.md", | ||
"abbreviatedOid": "a6e242e", | ||
"committedDate": "2018-05-01T10:28:23Z" | ||
}, | ||
{ | ||
"message": "Extract Github Service and use component shorthand and destructering (#1)\n\n* 0.0.11\r\n\r\n* Use component shorthand and destructering\r\n\r\n* Extract service\r\n\r\n* Finish up extracting service", | ||
"abbreviatedOid": "c12cffd", | ||
"committedDate": "2018-05-01T09:30:22Z" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"node": { | ||
"name": "SchoeppBrewery", | ||
"url": "https://github.com/jangerhard/SchoeppBrewery", | ||
"ref": { | ||
"target": { | ||
"history": { | ||
"nodes": [ | ||
{ | ||
"message": "Fix layouts", | ||
"abbreviatedOid": "d5c27ea", | ||
"committedDate": "2018-04-14T14:31:37Z" | ||
}, | ||
{ | ||
"message": "Set middle row of grid to auto", | ||
"abbreviatedOid": "075443f", | ||
"committedDate": "2018-04-14T11:50:51Z" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"node": { | ||
"name": "ReactPluralsight", | ||
"url": "https://github.com/jangerhard/ReactPluralsight", | ||
"ref": { | ||
"target": { | ||
"history": { | ||
"nodes": [ | ||
{ | ||
"message": "Finish course", | ||
"abbreviatedOid": "d96e05b", | ||
"committedDate": "2018-04-11T19:03:53Z" | ||
}, | ||
{ | ||
"message": "Add tests using Enzyme and Testing Utils", | ||
"abbreviatedOid": "8feb574", | ||
"committedDate": "2018-03-03T19:35:04Z" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
]; | ||
// API_KEY === apiKey ? resolve(fakeData) | ||
// : reject({ | ||
// error: 'Invalid API key' | ||
// }) | ||
|
||
if (API_KEY !== apiKey) | ||
reject(apiKeyError); | ||
if (variables.name === username || variables.numRepositories === undefined || variables.numCommits === undefined) | ||
reject(variablesError); | ||
|
||
resolve(fakeData) | ||
}).catch(() => { | ||
|
||
export const getStatsFor = () => { | ||
return new Promise(resolve => { | ||
resolve(fakeData); | ||
}); | ||
}; | ||
} |
This file contains 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,27 @@ | ||
import { getStatsFor } from "../GetStatsService" | ||
|
||
jest.mock('../GetStatsService'); | ||
|
||
const variables = { | ||
"username": "jangerhard", | ||
"numRepositories": 1, | ||
"numCommits": 1 | ||
}; | ||
|
||
describe('#getStatsFor() using Promises', () => { | ||
it('should load user data', () => { | ||
return getStatsFor("invalidKey", variables) | ||
.then(user => { | ||
expect(user).toBeDefined() | ||
expect(user.avatarUrl).toEqual('testUrl.com') | ||
expect(user.name).toEqual('Sir Test Testington') | ||
}) | ||
.catch(errors => { | ||
|
||
}) | ||
}) | ||
it('should handle errors', () => { | ||
}) | ||
it('should display a nicer error message', () => { | ||
}) | ||
}); |